News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

"Undefined index" notice for DBTaxRulesBill

Started by innato, August 21, 2016, 16:13:09 PM

Previous topic - Next topic

innato

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...

Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

GJC Web Design

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

Milbo

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

innato

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!
Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

GJC Web Design

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

innato

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.
Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

GJC Web Design

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

innato

#7
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']));

Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

Studio 42

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']));


innato

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']));

Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

Milbo

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

Studio 42