duanboshe0001 2014-08-06 11:01
浏览 175
已采纳

Magento:产品从购物车转移到愿望清单

I am trying to catch the event of move cart item to wishlist. I tried wishlist_product_add and wishlist_product_item events. But they not work on cart page. I want to save the custom options of product in wishlist. But when i move product from cart to wishlist all the options data are lost.

  • 写回答

3条回答 默认 最新

  • doulin2947 2014-08-28 10:12
    关注

    You can use following event

           <wishlist_item_add_after>
                <observers>
                   <cop_wishlist_price_options>         
                        <class>AAA_Addon_Model_Observer</class>
                        <method>addProductPriceOptionsToWishlist</method>           
                    </cop_wishlist_price_options>
                </observers>
            </wishlist_item_add_after>
    

    and in observer, you can have access to wishlist and quote. copy data/options form quote to wishlist items.

    public function addProductPriceOptionsToWishlist($observer){
    
    try {
    
        $wishlist = $observer->getEvent()->getWishlist();   
        $itemId = (int) $this->_getRequest()->getParam('item');
    
        $cart = Mage::getSingleton('checkout/cart');
        $session = Mage::getSingleton('checkout/session');
    
    
            $quote_item = $cart->getQuote()->getItemById($itemId);
            if (!$quote_item) {
                Mage::throwException(
                    Mage::helper('wishlist')->__("Requested cart item doesn't exist")
                );
            }
    
            $productId  = $quote_item->getProductId();
    
        $buyRequest = $quote_item->getBuyRequest();
        $buyRequestData = $buyRequest->getData();
    
    
        if($buyRequestData):
    
        $additional_op = $quote_item->getOptionByCode('additional_options');
        $additional_op = $additional_op->getData();
    
        $wishlist_item = Mage::getModel('wishlist/item')->load($productId,'product_id');
    
    
        //save additonal options to wishlist-options        
        $modelRes_w_item_op = Mage::getModel('wishlist/item_option');
        $modelRes_w_item_op->setWishlistItemId($wishlist_item->getId());
        $modelRes_w_item_op->setProductId($productId);
        $modelRes_w_item_op->setCode('additional_options');
        $modelRes_w_item_op->setValue($additional_op['value']);
        $modelRes_w_item_op->save();
    
        endif;
    
    
        } catch (Mage_Core_Exception $e) {
            Mage::log($e->getMessage());
        } catch (Exception $e) {
            Mage::log($e->getMessage());
        }
    
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀