VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: sandomatyas on July 30, 2014, 21:45:45 PM

Title: Shipment method with wrong cost
Post by: sandomatyas on July 30, 2014, 21:45:45 PM
I made an own shipment plugin based on weight_countries. Everything is fine except one thing.

For example I have a site with four shipment methods. Three of them are wight countries and one based on my new plugin.
I add some products to the cart and open it. There is no selected method for the first time but I can see the shipment cost of the last method. I open the shipment selector, there is everything fine. I select a weight countries based method with 0 cost, save it and the cart displays the selected method but still the wrong cost.
I can do anything there is only the last price.
What did I missed from my plugin?
Title: Re: Shipment method with wrong cost
Post by: GJC Web Design on July 30, 2014, 21:51:38 PM
what shows when you switch VM debug on?
Title: Re: Shipment method with wrong cost
Post by: sandomatyas on July 30, 2014, 22:04:25 PM
Part of my code is from authorizenet payment plugin.
I have checked my code and I found this part in function plgVmDisplayListFEShipment:

$htmla = '';
$html = array();
foreach ($this->methods as $this->_currentMethod) {
if ($this->checkConditions($cart, $this->_currentMethod, $cart->pricesUnformatted)) {
$methodSalesPrice = $this->setCartPrices($cart, $cart->pricesUnformatted, $this->_currentMethod);
$this->_currentMethod->$method_name = $this->renderPluginName($this->_currentMethod);
$html = $this->getPluginHtml($this->_currentMethod, $selected, $methodSalesPrice);


I think $methodSalesPrice overrides every method's cost? Do I need to filter the code to only the current method? But how?
Title: Re: Shipment method with wrong cost
Post by: Milbo on July 31, 2014, 08:57:13 AM
setCartPrices does the job already.
Title: Re: Shipment method with wrong cost
Post by: sandomatyas on July 31, 2014, 09:22:45 AM
Quote from: Milbo on July 31, 2014, 08:57:13 AM
setCartPrices does the job already.

Yes, the third param is the current method.
But I can't figure out what the problem is.
I have to add custom data to the shipment method and I have copied some code from authorize.net payment plugin and the standard shipment plugin.

My plgVmDisplayListFEShipment function is this:

public function plgVmDisplayListFEShipment (VirtueMartCart $cart, $selected = 0, &$htmlIn) {
if ($this->getPluginMethods($cart->vendorId) === 0) {
if (empty($this->_name)) {
$app = JFactory::getApplication();
$app->enqueueMessage(vmText::_('COM_VIRTUEMART_CART_NO_' . strtoupper($this->_psType)));
return FALSE;
} else {
return FALSE;
}
}

$html = array();
$method_name = $this->_psType . '_name';

$document = JFactory::getDocument();
$document->addScript( 'http://maps.googleapis.com/maps/api/js?sensor=false' );

$htmla = '';
$html = array();
foreach ($this->methods as $this->_currentMethod) {
if ($this->checkConditions($cart, $this->_currentMethod, $cart->pricesUnformatted)) {
$methodSalesPrice = $this->setCartPrices($cart, $cart->pricesUnformatted, $this->_currentMethod);
$this->_currentMethod->$method_name = $this->renderPluginName($this->_currentMethod);
$html = $this->getPluginHtml($this->_currentMethod, $selected, $methodSalesPrice);
if ($selected == $this->_currentMethod->virtuemart_shipmentmethod_id) {
$this->_getDataFromSession();
} else {

}

$html .= 'some html and javascript codes';

$htmla[] = $html;
}
}
$htmlIn[] = $htmla;

return TRUE;
}


Is the problem here or somewhere else?
Title: Re: Shipment method with wrong cost
Post by: sandomatyas on July 31, 2014, 09:47:57 AM
Ok, I started it from the begining. I have deleted the whole function, copied the displayListFE from vmpsplugin.php, renamed to plgVmDisplayListFEShipment and appended my custom codes.
Now it is well.
The new code:
public function plgVmDisplayListFEShipment (VirtueMartCart $cart, $selected = 0, &$htmlIn) {

if ($this->getPluginMethods ($cart->vendorId) === 0) {
if (empty($this->_name)) {
vmAdminInfo ('displayListFE cartVendorId=' . $cart->vendorId);
$app = JFactory::getApplication ();
$app->enqueueMessage (JText::_ ('COM_VIRTUEMART_CART_NO_' . strtoupper ($this->_psType)));
return FALSE;
} else {
return FALSE;
}
}

$document = JFactory::getDocument();
$document->addScript( 'http://maps.googleapis.com/maps/api/js?sensor=false' );

$html = array();
$method_name = $this->_psType . '_name';
foreach ($this->methods as $method) {
if ($this->checkConditions ($cart, $method, $cart->pricesUnformatted)) {

//$methodSalesPrice = $this->calculateSalesPrice ($cart, $method, $cart->pricesUnformatted);
/* Because of OPC: the price must not be overwritten directly in the cart */
$pricesUnformatted= $cart->pricesUnformatted;
$methodSalesPrice = $this->setCartPrices ($cart, $pricesUnformatted,$method);
$method->$method_name = $this->renderPluginName ($method);
$pluginHTML = $this->getPluginHtml ($method, $selected, $methodSalesPrice);

if ($selected == $method->virtuemart_shipmentmethod_id) {
$this->getDataFromSession();
} else {

}


$pluginHTML .= 'some html and javascript codes';

$html [] = $pluginHTML;
}
}
if (!empty($html)) {
$htmlIn[] = $html;
return TRUE;
}

return FALSE;
}
Title: Re: Shipment method with wrong cost
Post by: nzed on October 20, 2014, 13:45:42 PM
Hi all,

I think my question is connected to this topic, maybe you can give a clue for me.

In my shop shipment methods are in different currency than the products in the shop, and the weight-countries shipment method gives me wrong shipment cost. The shipment cost value is kept from shipment method but it is handled as if it was in the currency of products. For checkout and payment I have to convert shipment cost to the currency of the products. For solving this my idea was to read shipment cost from shipment methods but convert shipment price before it is saved in the cart or saved to DB. I've found the way to convert it before putting into the cart model (I use convertCurrencyTo() of the CurrencyDisplay class) but it is saved with wrong values to #__virtuemart_shipment_plg_weight_countries.shipment_cost and #__virtuemart_orders.order_shipment.
Can you tell me which function saves data to these fields and which is the best way to change the values?