简体   繁体   English

Magento V1.9 在事件观察器中的 sales_flat_quote_item 更新后超时运行

[英]Magento V1.9 is running in timeout after sales_flat_quote_item update in event observer

I try to save additional information (from third-party-system) to sales_flat_quote_item db in Magento V1.9.我尝试将其他信息(来自第三方系统)保存到 Magento V1.9 中的sales_flat_quote_item db。 The observer works fine.观察者工作正常。

The data which should be updated, were updated, but everytime it ends in an "Internal Server Error 500", even if I add a die() after the $quoteItem->save();应该更新的数据已更新,但每次都以“内部服务器错误 500”结尾,即使我在$quoteItem->save();之后添加了一个die() $quoteItem->save();

There is no timeout when I comment $quoteItem->save();当我评论$quoteItem->save();时没有超时$quoteItem->save(); out <- But then nothing was saved out <- 但随后什么也没有保存

config.xml配置文件

<events>
    <sales_quote_item_save_commit_after>
        <observers>
            <MyCompany_MyProject_salesQuoteItemSaveCommitAfter>
                <type>singleton</type>
                <class>MyCompany_MyProject_Model_Observer</class>
                <method>salesQuoteItemSaveCommitAfter</method>
            </MyCompany_MyProject_salesQuoteItemSaveCommitAfter>
        </observers>
    </sales_quote_item_save_commit_after>
</events>

Observer.php观察者.php

/**
     * @param Varien_Event_Observer $observer
     */
    public function salesQuoteItemSaveCommitAfter($observer)
    {
        //var_dump($post); die();

        $quoteItem = $observer->getEvent()->getItem();
        //var_dump($quoteItem->getId()); echo die();

        if (!$quoteItem->getId()) {
            //quote not saved in the database
            return $this;
        }
        //var_dump($quoteItem->getId()); die();

        $quoteItem->setPriceInclTax($post['my_custom_price']);
        $quoteItem->save();
        
        return $this;
    }

Yes exactly,对,就是这样,

The event sales_quote_item_save_commit_after is launched after each recording of the quote entity, here in the code when the $quoteItem->save();事件 sales_quote_item_save_commit_after 在每次记录报价实体后启动,这里在代码中 $quoteItem->save(); is launched, just after the observer is restarted and so on : which creates an infinite loop.启动,就在观察者重新启动之后,依此类推:这会创建一个无限循环。

In this case you can instead use the sales_quote_item_save_before event or perform a check to verify that the PriceInclTax field has been recorded.在这种情况下,您可以改为使用 sales_quote_item_save_before 事件或执行检查以验证是否已记录 PriceInclTax 字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未完成Magento订单创建sales_flat_quote_item - Magento Order creation sales_flat_quote_item not being made Magento - 向sales_flat_quote_item和sales_flat_order_item添加新列 - Magento - Adding a new column to sales_flat_quote_item and sales_flat_order_item 为什么core_write在Magento CE 1.9.1中的sales_flat_quote_item上不起作用 - Why core_write is not working on sales_flat_quote_item in Magento CE 1.9.1 **更新**如何在表sales_flat_quote_item中创建新列并使用$ cart-&gt; addProduct添加数据 - **update** How i can create new column in table sales_flat_quote_item and add data with $cart->addProduct Magento-更新sales_flat_order_item表中发票的数量 - Magento - update the qty invoiced in sales_flat_order_item table magento sales_order_place_after 观察者 - magento sales_order_place_after observer Magento 1.9:签出页面无法通过事件sales_order_place_after重定向到成功页面 - Magento 1.9:check out page not redirect to sucess page with event sales_order_place_after 从sales_quote_add_item观察者中止产品添加 - abort product add from sales_quote_add_item observer 在sales_flat_quote和sales_flat_order_item表中添加额外信息 - Adding extra information in sales_flat_quote and sales_flat_order_item tables 在magento中完成订单后,更新sales_flat_order表的自定义列 - Update a custom column of sales_flat_order table after order complete in magento
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM