Magento:应该有至少10个总数量的购物车批发客户群结账


Magento: There should be minimum 10 total quantity of cart for wholesale customer group to checkout

我创建了一个客户组Wholesale,如果这个分组的客户登录,他会看到不同的价格。无论如何,我想限制这一群体,他们必须购买至少10件任何产品,比如4件产品A和6件产品B,才能进行结账。我试着在库存管理中更改最低数量,但它适用于每种产品。我希望它作为一个整体,即购物车中的总数量。

SET MINIMUM ORDER Quantity FOR WHOLESALE CUSTOMER GROUP This is the tricky bit.
Open your app/design/frontend/default/[your theme]/template/checkout/cart.phtml
1. Add the following code to the beginning of the file, right above <div class="cart">
<?php $logged_in = Mage::getSingleton( 'customer/session' )->isLoggedIn();
if ($logged_in) { $group = Mage::getSingleton('customer/session')->getCustomerGroupId(); $totalItems = Mage::helper('checkout')->getQuote()->getItemsQty();
$minimum_qty = 10; } ?>
This code checks if the user is logged in, and if so, finds out which Customer Group they are in, their cart qty, and creates a variable to store what you want the minimum order qty to be.
2. Find the following code on your page (it will appear twice):
<ul class="checkout-types"> <?php foreach ($this->getMethods('top_methods') as $method): ?> <?php if ($methodHtml = $this->getMethodHtml($method)): ?> <li><?php echo $methodHtml; ?></li> <?php endif; ?> <?php endforeach; ?> </ul>
This is the code that renders the checkout buttons.
Replace the first instance of that code with:
<?php if (($group == 2 && $totalItems > $minimum_qty) || $group != 2): ?> <ul class="checkout-types"> <?php foreach ($this->getMethods('top_methods') as $method): ?> <?php if ($methodHtml = $this->getMethodHtml($method)): ?> <li><?php echo $methodHtml; ?></li> <?php endif; ?> <?php endforeach; ?> </ul> <?php endif; ?>
<?php if ($group == 2 && $totalItems < $minimum_qty): ?> <span style="color: red">Note: The minimum qty  for Wholesale customers is 10. Please add more items to your cart.</span><br /><br /> <?php endif; ?>
and the second instance with:
<?php if (($group == 2 && $totalItems > $minimum_qty) || $group != 2): ?> <ul class="checkout-types"> <?php foreach ($this->getMethods('top_methods') as $method): ?> <?php if ($methodHtml = $this->getMethodHtml($method)): ?> <li><?php echo $methodHtml; ?></li> <?php endif; ?> <?php endforeach; ?> </ul> <?php endif; ?>
What this does is prevent the checkout buttons from rendering if the customer is a wholesale customer ($group == 2) and their cart qty is less than the minimum you want ($totalItems > $minimum_qty). An error message will be displayed in red at the top of the cart page.
The buttons will render for everyone else, with no error message.

您可以隐藏CHECKOUT按钮,并通过在phtml页面中检查以下两个条件来显示消息。

10 <= Mage::helper('checkout/cart')->getSummaryCount()
YOUR_GROUP_ID = Mage::getSingleton('customer/session')->getCustomerGroupId()

防止从url 手动"签出/一页"

  1. 打开"模板路径提示"并找到phtml文件
  2. 打开phtml文件并将其放在顶部以查找控制器所在的位置。
    <p><?php print_r($this->getRequest()->getModuleName()); ?></p>
    <p><?php print_r($this->getRequest()->getControllerName()); ?></p>
    <p><?php print_r($this->getRequest()->getActionName()); ?></p>
  3. 找到它并转到Action方法。打破代码或进行回叫,以确保您在正确的位置
  4. 如果这是一个核心控制器文件,更好的方法是覆盖控制器。例如,单击此处。你可以在网上找到更多。如果您无法覆盖控制器,则只有在同一页面上进行编辑的选项