Author Topic: "Undefined index" notice for DBTaxRulesBill  (Read 3033 times)

innato

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
"Undefined index" notice for DBTaxRulesBill
« 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...

Regards
Rob

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

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10291
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #1 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

Code: [Select]
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10144
  • VM3.9 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #2 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
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

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #3 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!
Regards
Rob

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

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10291
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #4 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
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

innato

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #5 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.
Regards
Rob

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

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10291
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #6 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
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

innato

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #7 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:

Code: [Select]
$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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4516
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #8 on: August 25, 2016, 00:30:46 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:

Code: [Select]
$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 :
Code: [Select]
// 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

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #9 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'.

Code: [Select]
// 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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10144
  • VM3.9 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #10 on: August 25, 2016, 21:52:52 pm »
thx, added
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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4516
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: "Undefined index" notice for DBTaxRulesBill
« Reply #11 on: August 26, 2016, 00:02:15 am »
Yep sorry for the typo ;)