【问题标题】:Minimum total of items in shopping cart to allow checkout购物车中允许结帐的最少物品总数
【发布时间】:2015-03-26 06:07:08
【问题描述】:

我正在尝试找到一种配置,允许我的一个客户组(批发)将任何给定数量的商品添加到他们的购物车中,但限制结账的商品总数等于或大于 16 件。

例如: 产品 A 中的 8 件商品 产品 B 中的 2 件商品 产品 C 中的 6 件商品

总共有 16 件商品,他们可以结帐。

我尝试配置购物车中允许的最小数量,但是,他们必须获得每个产品的 16 件商品。

你知道是否有办法配置、添加扩展或硬编码来解决这个问题?

感谢您的宝贵时间!

【问题讨论】:

  • 您必须知道何时将某些东西添加到购物车中。只需在某处保留一个计数器,每次添加某些内容时递增 1。然后在添加某些内容时检查计数器是否为

标签: magento shopping-cart


【解决方案1】:

最简单的方法是设置最低订单金额

/admin/system_config/edit/section/sales

要实施最低商品限制,您可以在一个页面结账时设置观察者,该页面会检查其购物车的商品数量,如果低于您的阈值并显示消息将您重定向回购物车。

完整原型,按需调整:

app\etc\modules\Spirit_Cms.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Spirit_Cms>
            <active>true</active>
            <codePool>local</codePool>
        </Spirit_Cms>
    </modules>
</config>

app\code\local\Spirit\Cms\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Spirit_Cms>
            <version>0.0.1</version>
        </Spirit_Cms>
    </modules>
    <frontend>
        <events>
            <controller_action_predispatch_checkout_onepage_index>
                <observers>
                    <spirit_cms_restrict_checkout>
                        <class>Spirit_Cms_Model_Observer</class>
                        <method>restrictCheckout</method>
                    </spirit_cms_restrict_checkout>
                </observers>
            </controller_action_predispatch_checkout_onepage_index>
        </events>
    </frontend>
    <global>
        <models>
            <spirit_cms>
                <class>Spirit_Cms_Model</class>
            </spirit_cms>
        </models>
    </global>
</config>

app\code\local\Spirit\Cms\Model\Observer.php

<?php
    class Spirit_Cms_Model_Observer
    {   
        public function restrictCheckout( $oObserver )
        {
            // Ensure we only observe once.
            if( Mage::registry( 'restrict_checkout_flag' ) ) 
            {
                return $this;
            }
            else
            {
                $oQuote = Mage::getSingleton( 'checkout/cart' )->getQuote();
                $oCartItems = $oQuote->getAllItems();
                $iTotalQty = 0;
                foreach( $oCartItems as $oCartItem )
                {
                    $iTotalQty = $iTotalQty + $oCartItem->getQty();
                }
                if( $iTotalQty < 12 )
                {
                    $oSession = Mage::getSingleton( 'checkout/session' );
                    $oSession->addError( 'Please add at least 12 items to your cart.' );
                    Mage::app()->getResponse()->setRedirect( Mage::getUrl( 'checkout/cart' ) );
                }
                Mage::register( 'restrict_checkout_flag', 1, TRUE );
            }
        }
    }
?>

【讨论】:

    猜你喜欢
    • 2018-07-23
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    相关资源
    最近更新 更多