doufei4418 2016-04-13 11:28
浏览 67

将产品添加到购物车后获取报价项目ID

I need to get quote item id of the product when it is added to cart because I need to update a field of Db after this event,I have taken reference from How to get Quote Item Id after adding a product to cart?, but this is not working,I have used event: sales_quote_product_add_after and my oberver function is:

$quoteItem = $observer->getEvent()->getQuoteItem();
$id = $quoteItem->getId();

also I have tried with

$id = $quoteItem->getItemId();

It is throwing following Fatal error:

Fatal error</b>:  Call to a member function getId() on a non-object in <b>C:\xampp\htdocs\project\app\code\local\Custom\Module\Model\Observer.php</b> on line <b>1053</b><br />

Please let me know what I am doing wrong,I have taken reference from many other links too but none of them is working.

  • 写回答

3条回答 默认 最新

  • duanpanzhu2910 2016-04-13 19:59
    关注

    As per my understanding, You will not get QuoteItems keys for this event. This event provide items array which contain all the items which are getting added for a product. So you don't have to change your code a lot.

    $item = $observer->getEvent()->getItems()[0];
    $item_id =  $item->getId();
    

    It should give you desired result.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭