Amir Cohen
Amir Cohen

Reputation: 31

Magento shopping cart minimum quantity

I have an online shop to sell wine and sell by the bottle. However I can only ship in multiple of 6. i.e. 6, 12, 18, 24, and so on in any SKU combination.

I have tried Config->Inventory->"Minimum Qty Allowed in Shopping Cart" it works for individual product but not for total quantity at checkout.

Is there an way (via an extension, code or admin) to configure the rule during check out such that the total quantity regardless of the different SKUs has to be multiple of 6?

Upvotes: 3

Views: 3056

Answers (3)

1000Nettles
1000Nettles

Reputation: 2334

While the other answers work, perhaps the best method is to check upon quote save so if a customer adjusts quantities in their cart it will round and they will see and understand the change. Angry phone calls from customers when they purchased something that they didn't know they were buying are not fun.

With that said, we can hook into the sales_quote_save_before event to do our check and adjust the quantities accordingly.

Observer.php

<?php

class Yrcrz_WineQty_Model_Observer
{
    public function sales_quote_save_before(Varien_Event_Observer $observer)
    {
        $quote = $observer->getQuote();
        $items = $quote->getAllItems();
        $message = false;
        foreach ($items as $item) {
            $qty = $item->getQty();
            if ($qty % 6 != 0) {
                if ($qty <= 3) {
                    $newQty = 6;
                } else {
                    $newQty = round($qty / 6) * 6;
                    $item->setQty($newQty);
                    if (!$message) {
                        $message = Mage::helper('core')->__('Product quantities have been adjusted for case sizes');
                        Mage::getSingleton('core/session')->addNotice($message);
                    }
                }
            }
        }
    }
}

We first get all of our items, see if the quantity is in an increment of 6, and then subsequently adjust the quantity accordingly. We can even output a notice so the customer understands the subtle change.

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Yrcrz_WineQty>
            <version>0.0.1</version>
        </Yrcrz_WineQty>
    </modules>
    <global>
        <events>
            <sales_quote_save_before>
                <observers>
                    <Yrcrz_WineQty_Observer>
                        <type>singleton</type>
                        <class>Yrcrz_WineQty_Model_Observer</class>
                        <method>sales_quote_save_before</method>
                    </Yrcrz_WineQty_Observer>
                </observers>
            </sales_quote_save_before>
        </events>
    </global>
</config>

Upvotes: 0

MagePal Extensions
MagePal Extensions

Reputation: 17656

You could create a custom module or on the login page of your onepage checkout do

if(Mage::helper('checkout/cart')->getCart()->getItemsCount() % 6 != 0){
   Mage::getSingleton('customer/session')->addError('Item in your cart must be multiple of 6');
   $url = Mage::getUrl('checkout/cart')
   Mage::app()->getFrontController()->getResponse()->setRedirect($url, 301);
}

Upvotes: 0

Fabian Blechschmidt
Fabian Blechschmidt

Reputation: 4141

afaik not, but it should be easy to do.

write an observer which listens on controller_action_predispatch_checkout_onepage_index check wether the quantity is a multiple of 6 and if not add an error and redirect to the cart

you can think about checking it in controller_action_predispatch_checkout_cart_index too to show a warning on the cart page and maybe grey the button.

Upvotes: 0

Related Questions