【问题标题】:Magento get Wishlistitem from ProductMagento 从 Product 中获取 Wishlistitem
【发布时间】:2018-08-29 07:08:34
【问题描述】:
public function addItem(Mage_Wishlist_Model_Item $item)
{

    $superAttributes = Mage::app()->getRequest()->getParam('super_attribute');
    if ($item instanceof Mage_Wishlist_Model_Item && isset($superAttributes)) {
        $simpleItem = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($superAttributes, $item->getProduct());
    }

    return parent::addItem($simpleItem);
}

现在我的问题是我想调用需要接收Mage_Wishlist_Model_Item 而不是Mage_Catalog_Model_Product 的父函数

MyCustom_Wishlist_Model_Wishlist extends Mage_Wishlist_Model_Wishlist

如何获得产品$simpleItem的愿望清单

【问题讨论】:

    标签: php magento e-commerce magento-1.9


    【解决方案1】:
    public function addItem(Mage_Wishlist_Model_Item $item)
    {
        $superAttributes = Mage::app()->getRequest()->getParam('super_attribute');
        if ($item instanceof Mage_Wishlist_Model_Item && isset($superAttributes)) {
            $product = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($superAttributes, $item->getProduct());
            $item = Mage::getModel('wishlist/item');
            $storeId = $product->hasWishlistStoreId() ? $product->getWishlistStoreId() : $this->getStore()->getId();
            $qty = 1;
    
            $item->setProductId($product->getId())
                ->setWishlistId($this->getId())
                ->setAddedAt(now())
                ->setStoreId($storeId)
                ->setOptions($product->getCustomOptions())
                ->setProduct($product)
                ->setQty($qty)
                ->save();
        }
    
        return parent::addItem($item);
    }
    

    这对我有用,但我还不知道如何设置$qty

    【讨论】:

      【解决方案2】:

      您检查过此网址吗? https://magento.stackexchange.com/questions/19678/how-do-i-add-to-wishlist-programatically

      这是将产品添加到愿望清单的原生方式。

      如果您不想更改参数类型,则可以从代码中删除 $item 类型检查(没有必要):

      $item instanceof Mage_Wishlist_Model_Item
      

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-11-22
        • 1970-01-01
        • 1970-01-01
        • 2018-04-18
        • 2014-08-22
        • 1970-01-01
        • 1970-01-01
        • 2012-03-28
        相关资源
        最近更新 更多