【问题标题】:Limit order quantity by category or add additional shipping charge by category in Magento在 Magento 中按类别限制订单数量或按类别添加额外运费
【发布时间】:2013-04-18 04:28:24
【问题描述】:

我对 Magento 有疑问。

我有一个类别,客户每次订单只能购买该类别中的一种产品。我已成功设置产品设置中只能添加一项​​。但是,如果客户返回该类别,他仍然可以在该类别中添加另一个产品。假设他从A类中选择了产品A,他可以返回到A类选择产品B。我想要的是任何时候,对于那个订单,他只能从A类中购买一个产品。

如果无法做到这一点,如果从该类别中选择超过 1 个产品,我希望增加额外的运费。

有人对此有解决方案吗?

【问题讨论】:

    标签: magento


    【解决方案1】:

    Magento: limit 3 products from category per order

    为事件checkout_cart_product_add_after创建一个观察者

         <events>
            <checkout_cart_product_add_after>
                <observers>
                    <enableduplicateproductstatus>
                        <type>singleton</type>
                        <class>limitcartproductbycategory/observer</class>
                        <method>cartlimit</method>
                    </enableduplicateproductstatus>
                </observers>
            </checkout_cart_product_add_after>
        </events>
    

    创建:app/code/local/MagePal/LimitCartProductByCategory/Model/Observer.php

    class MagePal_LimitCartProductByCategory_Model_Observer 
    {
    
        public function cartlimit(Varien_Event_Observer  $observer)
        {
            $category_ids = array();
    
            $quote = Mage::getSingleton('checkout/session')->getQuote();
            foreach($quote->getAllVisibleItems() as $item){
                  $product = Mage::getModel('catalog/product')->load($item->getId());
                  $product_category_ids = explode(",", $product->getCategoryIds());
                  //$product_category_ids = $product->getCategoryIds();
    
                  array_push($category_ids, $product_category_ids);
            }
    
            $justAdded = $observer->getQuoteItem();
    
    
            $productJustAdded = Mage::getModel('catalog/product')->load($justAdded->getId());
    
            //total the category id in $category_ids
            //if $productJustAdded->getCategoryIds exist in $category_ids, 
            //then check to see if category id count greater than 3
            // if true then add error msg and try setting the qty to 0
    
            return $this;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-16
      • 1970-01-01
      • 1970-01-01
      • 2016-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多