Demac Media Demac Media Brand Demac Media Brand



Mini Tutorial: How to Add Wholesale Quantity to your Cart in Magento

Timer Icon 2 Mins

Magento Commerce, Magento Tutorials

A client recently requested me to change how the “add to cart” feature works. He explained that their customers are required to buy products in a full case, which the quantity can be 6, 12, etc, but their inventory quantity is in a single unit. So I couldn’t just raise the price to match the price of a case. After digging around a bit, I found that there is an observer I can hook into, to change the add to cart quantity.

First, You will need a new product attribute to store the case size. I called it “case_size”

And then you will create an extension to observe “sales_quote_item_qty_set_after” event. I assume you have experience on creating an event observer! If you don’t… Here is a tutorial

The following code is the magic.

$item = $observer->getItem();
    $case_qty =  floor($item->getQtyToAdd());
    $case_size =  $item->getProduct()->getCaseSize();

    if(Mage::app()->getRequest()->getActionName() == 'reorder') {
        $qty = $case_qty * $case_size;
        if($item->getQty() > 0)
            $qty += $item->getQty() - $case_qty;
else if($item->getQty())
    $caseSize = Mage::getResourceModel('catalog/product')
'case_size', Mage::app()->getStore());
    $origin_qty =  $item->getOrigData('qty');
    $current_qty =  floor($item->getData('qty'));
    if($origin_qty != $current_qty)
         if(!$current_qty) {
              $current_qty  = 1;
        $qty = $current_qty * $caseSize;

The above code manipulates the input quantity by multiplying it to the case size. However, there are a few cases that you don’t want to apply the multiplication, e.g the item is being added to cart by the reorder function.

Good luck & have fun!!!

Subscribe to the Blog

Stay updated with 20,000+ eCommerce leaders in our community

Sign Up

Let’s talk about your 10X return

Icon/Social/Phone Contact us for pricing information