VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: dartagnon on August 15, 2019, 09:23:02 AM

Title: Shipping insurance cost not added to the total in the cart.
Post by: dartagnon on August 15, 2019, 09:23:02 AM
Hello VirtueMart experts,
I've inherited a VirtueMart site, which had a few issues with old version of codes, and slowly I have got it up to date.
However there is this one critical problem that I cannot seem to find the root cause.
The site is www.karlangu.com and when you put an item in the cart, you should be able to choose a shipping method with insurance.
The site uses 'Standard Plus' shipping module, which seems no longer supported, to handle the shipping rates.
It also has insurance calculation done according to the policy (I think it is insurance cost of $25 below $1000 total or 2.5% over $1000). anyhow... the shipping options show the insurance option, but then when when I choose it, it doesn't update the cart total.
Anyone have any suggestions where I should look to troubleshoot? I don't think it generates javascript errors...
Thanks in advance.
Title: Re: Shipping insurance cost not added to the total in the cart.
Post by: GJC Web Design on August 15, 2019, 11:51:48 AM
I would assume its in this plugins implementation of the getCosts (VirtueMartCart $cart, $method, $cart_prices) function
Title: Re: Shipping insurance cost not added to the total in the cart.
Post by: dartagnon on August 19, 2019, 01:44:25 AM
While trying to look for the getCosts(), I've come across this snippet of code in the plugin's helper directory 'vmshipping.php', which also contains the formula for shipping insurance calculation;


                $rate_name = $row['detail']->rate_name;

                if ($cart->virtuemart_shipmentmethod_id == $methods[$rate_id]->virtuemart_shipmentmethod_id) {
                    $isinsurance = ($cart->virtuemart_insurance == 1) ? 'checked' : '';
                    $isnormal = ($cart->virtuemart_insurance != 1) ? 'checked' : '';
                } else {
                    $isinsurance = '';
                    $isnormal = '';
                }

                $html[] = '<input type="radio" name="virtuemart_shipmentmethod_id" id="shipment_id_' . $methods[$rate_id]->virtuemart_shipmentmethod_id . '"   value="' . $methods[$rate_id]->virtuemart_shipmentmethod_id . '" ' . $isnormal . '>' .
                '<label for="shipment_id_' . $methods[$rate_id]->virtuemart_shipmentmethod_id . '"><span class="vmshipment">' . $carrier_name . '</span><span class="vmshipment_cost"> + ' . $show_shipping_handling . "</span></label>\n";

                $html[] = '<input type="radio" name="virtuemart_shipmentmethod_id" id="shipment_id_' . $methods[$rate_id]->virtuemart_shipmentmethod_id . '-1"   value="' . $methods[$rate_id]->virtuemart_shipmentmethod_id . '-1" ' . $isinsurance . '>' .
                '<label for="shipment_id_' . $methods[$rate_id]->virtuemart_shipmentmethod_id . '"><span class="vmshipment">' . $carrier_name . '</span><span class="vmshipment_cost"> + ' . $show_shiping_insurance . "</span><br /><small>Include insurance </small></label>\n";



I think this generates the radio button of the shipping methods with or without insurance.
Interesting is that the $isinsurance is always empty. That means $cart->virtuemart_insurance is never set.
Also looking at the AJAX reply, the reply simply had an error back.

It is a bit like going into a rabbit hole...

Could you help how I can find
1) how one would go about setting a value in the cart - ie. $cart->virtuemart_insurance
2) probably related to Q1 above, any pointers as to which javascript code handles the cart Ajax "https://<server>/index.php?option=com_virtuemart&view=cart"? I am guessing that the Ajax handler must be able to set the insurance flag and update total, which is not happening...

Thanks in advance.
Title: Re: Shipping insurance cost not added to the total in the cart.
Post by: GJC Web Design on August 19, 2019, 12:44:46 PM
this has to be all bespoke/hack code -- there is no such thing as $cart->virtuemart_insurance in a stock VM install