0
我使用magento 1.7。
我正在嘗試使用magento製作廣告模塊。
用戶可以將廣告作爲產品發佈,當他支付訂單時,我希望啓用廣告(產品)。 爲此,我收聽sales_order_invoice_save_after。一切正常,但是當我嘗試保存該產品在事件偵聽器,保存功能拋出異常:在事件觀察者中保存產品屬性
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
我的功能看起來是這樣的:
public function onInvoiceSaveAfter(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$invoice = $event->getInvoice();
switch($invoice->getState())
{
case Mage_Sales_Model_Order_Invoice::STATE_PAID :
{
$order = $invoice->getOrder();
$items = $order->getAllItems();
//Update the product
$product = Mage::getModel('catalog/product')->load($item->getEntityId());
$product->setAdEndDate('2015-10-10 00:00:00');
$product->getResource()->saveAttribute($product, 'ad_end_date'); //Throws exception
}
}
誰能幫助我嗎?
我該如何做到這一點?