VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: innato on August 21, 2016, 16:13:09 PM

Title: "Undefined index" notice for DBTaxRulesBill
Post by: innato on August 21, 2016, 16:13:09 PM
VM3.0.16 on J3.6.2 and PHP 5.6.24

I am using the Virtuemart Finalize Order system plug-in (v3.4.1) from Daycounts (https://www.daycounts.com/shop/virtuemart-3/finalize-order-plugin.htm) and this plug-in does its job without a problem, EXCEPT that an error notice is thrown by VM.

When visiting a pending VM order at frontend (after customer login), the following notice is thrown:
<quote>
Notice: Undefined index: DBTaxRulesBill in /var/www/root/administrator/components/com_virtuemart/plugins/vmpsplugin.php on line 1086
<unquote>

The Joomla! error reporting level is set to 'Maximum' (back-end global config / server) and the notice disappears when the error reporting level is set to 'system default'.
The 'finalise order' button is shown correctly by the plug-in and the pending VM order can be completed without problems. It's just that the notice should not be there...

Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: GJC Web Design on August 21, 2016, 19:29:45 PM
It is only a notice - max error reporting shouldn't be on on a production site

you could try something like

if(!empty($cart->cartData['taxRulesBill'])){
$taxrules = array_merge($cart->cartData['VatTax'],$cart->cartData['taxRulesBill']);
}else{
$taxrules = array($cart->cartData['VatTax']);
}


not tested
Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: Milbo on August 23, 2016, 11:42:15 AM
Please update to the last version vm3.0.17.6 http://dev.virtuemart.net/projects/virtuemart/files
Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: innato on August 23, 2016, 13:00:04 PM
Guys, I really appreciate the promptness of your replies. It deserves my respect.
@milbo alas, the update to VM3.0.17.6 did not help.
@GJC I appreciate your sense of humour ("it's only a notice"), but being a developer yourself you must agree that errors, warnings and notices are at odds with best coding practice. But... your code suggestion relates to $cart->cartData['taxRulesBill'] whereas the problem relates to $cart->cartData['DBTaxRulesBill'] (note the additional "DB"). I tested your code but it didn't help.
I find it OK to temporarily add a hack as you suggested, would you please have another suggestion? BTW, was your suggestion meant for the file vmpsplugin.php?
Tnx in advance!
Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: GJC Web Design on August 23, 2016, 13:04:49 PM
the notice states -> vmpsplugin.php on line 1086  ->  $taxrules = array_merge($cart->cartData['VatTax'],$cart->cartData['taxRulesBill']);

that is where I suggested the code -

as your the only one reporting this with a 3rd party extension you need to do some digging as to what index value is missing
Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: innato on August 23, 2016, 19:57:21 PM
My notice says "Undefined index: DBTaxRulesBill in ....   ... on line 1086"

My copy of the file /administrator/components/com_virtuemart/plugins/vmpsplugin.php (VM 3.0.16) reads on line 1086:
   $cartdiscountBeforeTax = $calculator->roundInternal($calculator->cartRuleCalculation($cart->cartData['DBTaxRulesBill'], $cart->cartPrices['salesPrice']));

which indeed includes mentioned index DBTaxRulesBill that appears to be missing.
Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: GJC Web Design on August 23, 2016, 21:06:38 PM
my version of 3.0.16 is different .. that line is 2 below.. any way..

you do a similar thing .. check if the var exists , if not make a fall back option
Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: innato on August 24, 2016, 10:40:43 AM
Resolved by assigning empty to the missing element when it does not exist. I asked on this forum because there might be a more 'in depth' solution. Anyway, I consider it a minor flaw in the code that hopefully gets corrected in some future VM release.
Thanks a lot for your help!

This is what I did (for others to benefit from). VM version 3.0.16 on J3.6.2 and PHP 5.6.24, file /administrator/components/com_virtuemart/plugins/vmpsplugin.php

Lines 1085 ("$taxrules = array_merge($cart->cartData['VatTax']... etcetera") and 1086 ("$cartdiscountBeforeTax = $calculator->roundInternal(... etcetera") have some extra code between them and now read:


$taxrules = array_merge($cart->cartData['VatTax'],$cart->cartData['taxRulesBill']);

// added code - when using Virtuemart Finalize Order system plug-in from Daycounts, notice ref undefined index 'DBTaxRulesBill' is thrown - this avoids the notice
if ( !isset($cart->cartData['DBTaxRulesBill']) ) {
$cart->cartData['DBTaxRulesBill'] = "";
}
// end code addition

$cartdiscountBeforeTax = $calculator->roundInternal($calculator->cartRuleCalculation($cart->cartData['DBTaxRulesBill'], $cart->cartPrices['salesPrice']));

Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: Studio 42 on August 25, 2016, 00:30:46 AM
Quote from: innato on August 24, 2016, 10:40:43 AM
Resolved by assigning empty to the missing element when it does not exist. I asked on this forum because there might be a more 'in depth' solution. Anyway, I consider it a minor flaw in the code that hopefully gets corrected in some future VM release.
Thanks a lot for your help!

This is what I did (for others to benefit from). VM version 3.0.16 on J3.6.2 and PHP 5.6.24, file /administrator/components/com_virtuemart/plugins/vmpsplugin.php

Lines 1085 ("$taxrules = array_merge($cart->cartData['VatTax']... etcetera") and 1086 ("$cartdiscountBeforeTax = $calculator->roundInternal(... etcetera") have some extra code between them and now read:


$taxrules = array_merge($cart->cartData['VatTax'],$cart->cartData['taxRulesBill']);

// added code - when using Virtuemart Finalize Order system plug-in from Daycounts, notice ref undefined index 'DBTaxRulesBill' is thrown - this avoids the notice
if ( !isset($cart->cartData['DBTaxRulesBill']) ) {
$cart->cartData['DBTaxRulesBill'] = "";
}
// end code addition

$cartdiscountBeforeTax = $calculator->roundInternal($calculator->cartRuleCalculation($cart->cartData['DBTaxRulesBill'], $cart->cartPrices['salesPrice']));



PHP doc is array_merge ( array $array1 [, array $... ] ) so the fix is to check before array_merge .
SO the code should be :

// added code - when using Virtuemart Finalize Order system plug-in from Daycounts, notice ref undefined index 'DBTaxRulesBill' is thrown - this avoids the notice
if ( !isset($cart->cartData['DBTaxRulesBill']) ) {
$cart->cartData['DBTaxRulesBill'] = array();
}
if ( !isset($cart->cartData['DBTaxRulesBill']) ) {
$cart->cartData['DBTaxRulesBill'] = array();
}
// end code addition
$taxrules = array_merge($cart->cartData['VatTax'],$cart->cartData['taxRulesBill']);


$cartdiscountBeforeTax = $calculator->roundInternal($calculator->cartRuleCalculation($cart->cartData['DBTaxRulesBill'], $cart->cartPrices['salesPrice']));

Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: innato on August 25, 2016, 19:55:52 PM
Tnx, you're code is even better!
However... you are repeating the same code twice. A typo. It should be once for 'taxRulesBill' and once for 'DBTaxRulesBill'.


// added code - when using Virtuemart Finalize Order system plug-in from Daycounts, notice ref undefined index 'DBTaxRulesBill' is thrown - this avoids the notice
if ( !isset($cart->cartData['taxRulesBill']) ) {
$cart->cartData['taxRulesBill'] = array();
}
if ( !isset($cart->cartData['DBTaxRulesBill']) ) {
$cart->cartData['DBTaxRulesBill'] = array();
}
// end code addition
$taxrules = array_merge($cart->cartData['VatTax'],$cart->cartData['taxRulesBill']);
$cartdiscountBeforeTax = $calculator->roundInternal($calculator->cartRuleCalculation($cart->cartData['DBTaxRulesBill'], $cart->cartPrices['salesPrice']));

Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: Milbo on August 25, 2016, 21:52:52 PM
thx, added
Title: Re: "Undefined index" notice for DBTaxRulesBill
Post by: Studio 42 on August 26, 2016, 00:02:15 AM
Yep sorry for the typo ;)