我有一个Magento扩展,它应该为PayPal订单添加捐款,但是它在Model / Observer.php中引发了错误。这是人们完成PayPal并重定向回我的网站。显示此错误时的URL是/ paypal / express / placeOrder /。错误是Fatal error: Call to a member function getBaseDonation() on a non-object in [path]/Model/Observer.php on line 215
。第215行在if(!$捐赠){
public function addPaypalItem($observer)
{
$cart = $observer->getEvent()->getPaypalCart();
$quote = $cart->getSalesEntity();
$donation = $quote->getBaseDonation();
if (!$donation) {
$donation = $quote->getShippingAddress()->getBaseDonation() ? $quote->getShippingAddress()->getBaseDonation() : $quote->getBillingAddress()->getBaseDonation();
}
if ($donation > 0) {
$cart->addItem(
Mage::helper('donations')->__('Donation'),
1,
$donation
);
}
return $this;
}
如何解决这个非对象问题?谢谢!
答案 0 :(得分:0)
首先,我认为你应该重新检查getShippingAddress()函数,以确保它返回工作流程中的对象。
如果是,请检查您的扩展是否已覆盖到ShippingAddress对象以输入BaseDonation值。
$quote->getBaseDonation() is different from $quote->getShippingAddress()->getBaseDonation();