News:

Support the VirtueMart project and become a member

Main Menu

Shipment method with wrong cost

Started by sandomatyas, July 30, 2014, 21:45:45 PM

Previous topic - Next topic

sandomatyas

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?

GJC Web Design

what shows when you switch VM debug on?
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

sandomatyas

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?

Milbo

setCartPrices does the job already.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sandomatyas

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?

sandomatyas

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;
}

nzed

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?