0

Currently have a Magento site using the standard minimum order amount functionality in System > Config > Sales > Minimum order amount.

Minimum order amount is set to £30.

I would like to allow certain SKU's through this rule, I have read a post on this and currently have the following setup but unable to get this working:

Original File location: /public_html/app/code/core/Mage/Sales/Model/Quote

Edited file location: /public_html/app/code/local/Mage/Sales/Model/Quote

Filename: Address.php

I have replaced the following:

        $amount = Mage::getStoreConfig('sales/minimum_order/amount', $storeId);
    if ($this->getBaseSubtotalWithDiscount() < $amount) {
        return false;
    }
    return true;
}

With:

 $amount = Mage::getStoreConfig('sales/minimum_order/amount', $storeId);
foreach($this->getAllItems() as $item){
    if(in_array($item->getSku(), array("MELT04", "HRT02")))
    $amount += $item->getPrice(); 
}
   if ($this->getBaseSubtotalWithDiscount() < $amount) {
    return false;
} 

    return true;
}

But this does not allow the following SKU's through MELT04 & HRT02.

Please help, thanks in advance.

  • Anyone able to help with this? – Billy Parker Jan 15 '16 at 12:40
  • This code only adds the price if the sku is MELT04 & HRT02. How should this work. Any order containing those should always go through? Or should just those products be left in the quote when ordering? – Sander Mangel Jan 15 '16 at 22:59
0

I have written for you a module which implement this functionality. All you need to do is to make an input field, somewhere in admin, where you'll declare your sku's(very simple to do via system.xml). Then you'll need to get this sku's as an array in IsSkuPresent() method from Helper/Data.php.

This module checks if one of these sku's is in the cart. If it is, the "minimum order" verification will be skipped and the user will be able to go to checkout.

In this module I have rewritten 2 model class:

Mage_Sales_Model_Quote
Mage_Sales_Model_Quote_Address

to override the methods which are responsible with this verification

Here is the code. If you have questions please ask.

app/etc/modules/Namespace_SkipMinimumOrderAlert.xml

Contains

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_SkipMinimumOrderAlert>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Sales />
            </depends>
        </Namespace_SkipMinimumOrderAlert>
    </modules>
</config>

next

local/Namespace/SkipMinimumOrderAlert/etc/config.xml

Contains

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_SkipMinimumOrderAlert>
            <version>1.0.0</version>
        </Namespace_SkipMinimumOrderAlert>
    </modules>
    <global>
        <helpers>
            <skipminimumorderalert>
                <class>Namespace_SkipMinimumOrderAlert_Helper</class>
            </skipminimumorderalert>
        </helpers>
        <models>
          <sales>
              <rewrite>
                  <quote>Namespace_SkipMinimumOrderAlert_Model_Quote</quote>
                  <quote_address>Namespace_SkipMinimumOrderAlert_Model_Quote_Address</quote_address>
              </rewrite>
          </sales>
       </models>
    </global>
</config>

next

local/Namespace/SkipMinimumOrderAlert/Model/Quote.php

Contains

<?php
class Namespace_SkipMinimumOrderAlert_Model_Quote extends Mage_Sales_Model_Quote
{

      public function validateMinimumAmount($multishipping = false)
    {
        $helper = Mage::helper('skipminimumorderalert');
        $isSkuPresent = $helper->IsSkuPresent();
        $storeId = $this->getStoreId();
        $minOrderActive = Mage::getStoreConfigFlag('sales/minimum_order/active', $storeId);
        $minOrderMulti  = Mage::getStoreConfigFlag('sales/minimum_order/multi_address', $storeId);
        $minAmount      = Mage::getStoreConfig('sales/minimum_order/amount', $storeId);

        if (!$minOrderActive) {
            return true;
        }

        $addresses = $this->getAllAddresses();

        if ($multishipping) {
            if ($minOrderMulti) {
                foreach ($addresses as $address) {
                    foreach ($address->getQuote()->getItemsCollection() as $item) {
                        $amount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount();
                        if ($amount < $minAmount && !($isSkuPresent)) {
                            return false;
                        }
                    }
                }
            } else {
                $baseTotal = 0;
                foreach ($addresses as $address) {
                    /* @var $address Mage_Sales_Model_Quote_Address */
                    $baseTotal += $address->getBaseSubtotalWithDiscount();
                }
                if ($baseTotal < $minAmount && !($isSkuPresent)) {
                    return false;
                }
            }
        } else {
            foreach ($addresses as $address) {
                /* @var $address Mage_Sales_Model_Quote_Address */
                if (!$address->validateMinimumAmount()) {
                    return false;
                }
            }
        }
        return true;
    }

}

next

local/Namespace/SkipMinimumOrderAlert/Model/Quote/Address.php

Contains

<?php
class Namespace_SkipMinimumOrderAlert_Model_Quote_Address extends Mage_Sales_Model_Quote_Address
{
    public function validateMinimumAmount()
    {
        $helper = Mage::helper('skipminimumorderalert');
        $isSkuPresent = $helper->IsSkuPresent();
        $storeId = $this->getQuote()->getStoreId();
        if (!Mage::getStoreConfigFlag('sales/minimum_order/active', $storeId)) {
            return true;
        }

        if ($this->getQuote()->getIsVirtual() && $this->getAddressType() == self::TYPE_SHIPPING) {
            return true;
        } elseif (!$this->getQuote()->getIsVirtual() && $this->getAddressType() != self::TYPE_SHIPPING) {
            return true;
        }

        $amount = Mage::getStoreConfig('sales/minimum_order/amount', $storeId);
        if ($this->getBaseSubtotalWithDiscount() < $amount && !($isSkuPresent)) {
            return false;
        }
        return true;
    }
}

and

local/Namespace/SkipMinimumOrderAlert/Helper/Data.php

Contains

<?php
class Namespace_SkipMinimumOrderAlert_Helper_Data extends Mage_Core_Helper_Abstract
{
    public function IsSkuPresent(){
        $cart = Mage::getModel('checkout/cart')->getQuote();
        $prefferedSkus = YOUR_SKUS;

        foreach($cart->getAllVisibleItems() as $product){
            if (in_array($product->getSku(), $prefferedSkus)) {
                return true;
            }
        }
        return false;
    }
}
|improve this answer|||||
  • Wow Alex thank you for the detailed response! I will give this a go. – Billy Parker Jan 22 '16 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.