doutiaoku4495 2010-12-09 10:58
浏览 5
已采纳

获取购买产品的类别

I have this task to do, but I'm stuck on it. Client wants to get a category name product was purchased at. This info normally is not set. So at first step I'm trying to capture event checkout_cart_product_add_after and set a category for product.

So in my Observer.php I try to get current category, by:

Mage::registry('current_category')->getName()

but it appears that current_category object is not set in Mage registry. How can I add a category to a product in a different way? (Note that, product may belong to many categories, I just need the one at which it was purchased).

Regards, ventus

  • 写回答

2条回答 默认 最新

  • douba2011 2010-12-14 09:12
    关注

    Keeping this data in user session is not so good idea. There is another way. On product page I add a hidden input tag with current category id, which can be received by $product->getCategory()->getEntityId().

    Second step is more difficult. Before I have added new field (attribute) to the sales_flat_quote_item and sales_flat_order_item named from_category (my custom name ;)). Now I use observer for event sales_quote_save_before and I set to Quote Item my custom attribute.

    To convert quote item to order item with my custom attribute I just added to config.xml global section:

    
    <fieldsets>
      <sales_convert_quote_item>
        <from_category>
          <to_order_item>*</to_order_item>
        </from_category>
      </sales_convert_quote_item>
    </fieldsets>
    

    Now I can use it on checkout.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用