I’m having two problems in my system.log that I’m having some problems resolving. The site seems to run fine, but I would very much like to remove these ongoing errors from the log.
Notice: Undefined variable: order in /var/www/… on line 17
// line 17
$merchantnumber = $standard->getConfigData('merchantnumber', $order ? $order->getStoreId() : null);
Warning: Division by zero in /var/www/… on line 267
// line 267
"vat" => (float)round((string)((round($order->getBaseShippingInclTax(),2)-round($order->getBaseShippingAmount(),2))/round((string)$order->getBaseShippingAmount(),2))*100, 2)
UPDATE
// line 258-281
$items = $order->getAllItems();
foreach ($items as $itemId => $item)
{
$invoice["lines"][] = array
(
"id" => $item->getSku(),
"description" => $item->getName(),
"quantity" => round($item->getQtyOrdered(), 0),
"price" => $item->getBasePrice()*100,
"vat" => (float)round((string)((round($item->getBasePriceInclTax(),2)-round($item->getBasePrice(),2))/round((string)$item->getBasePrice(),2))*100, 2)
);
}
$invoice["lines"][] = array
(
"id" => $order->getShippingMethod(),
"description" => $order->getShippingDescription(),
"quantity" => 1,
"price" => $order->getBaseShippingAmount()*100,
"vat" => (float)round((string)((round($order->getBaseShippingInclTax(),2)-round($order->getBaseShippingAmount(),2))/round((string)$order->getBaseShippingAmount(),2))*100, 2)
);
return json_encode($invoice);
}
I’ve posted the wrong code before sorry, I was confused when looking throug the errorlog because the same (Devider) error appeared on both the Item and Order part.
Unfortunately Magento code seems to often rely on PHP’s tolerance for logic errors which are considered notices.
If
$orderis not set we want to use NULL instead of the order’s store Id:In the second file:
UPDATE check out if you’re referring to
$orderor$item. If it’s in a loop, it is probably the latter.the VAT% is back-calculated from ShippingInclTax (which is ShippingAmount + VAT). Only, if getBaseShippingAmount() is zero, the calculation crashes.
To cope with that we ought to have:
…I’m not really happy with all those
rounds, but they probably are there so that printed accounts “check” up to the last decimal and avoid strange results such as 10.33 + 10.33 + 9.33 = 30.00 instead of 29.99.I would write
but even if it is mathematically more sound, I’m afraid that the results might not “match” with what Magento prints elsewhere.
If you’re using
$orderin a loop (meaning you’ve got the same value whatever the item), you’d be better advised in calculating VAT before the loop and then use it inside.