我有一个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(!$donate){内
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;
}
我如何解决这个非对象问题?非常感谢。
首先,我认为您应该重新检查getShippingAddress()函数,以确保它在我们的工作流中返回一个对象。
如果是,请检查您的扩展是否已经覆盖到ShippingAddress对象以输入BaseDonation值。
$quote->getBaseDonation() is different from $quote->getShippingAddress()->getBaseDonation();