magento® extensions you love
Magento Extension Builder

Protect your store from fraudful orders

Not enough memory or server 500 error while generating coupons in Magento

You can get such errors while using Generate & Import Coupons extension. This is a known bug in old magento versions, it has been fixed in the latest one.

There errors occur as basically Magento tries to load all coupons in the memory. You can also fix them yourself.

Find this file
app\code\core\Mage\SalesRule\Model\Validator.php

and replace this

protected function _maintainAddressCouponCode($address, $rule)
    {
        foreach ($rule->getCoupons() as $coupon) {
            if (strtolower($coupon->getCode()) == strtolower($this->getCouponCode())) {
                $address->setCouponCode($this->getCouponCode());
                break;
            }
        }
    }


with that

      protected function _maintainAddressCouponCode($address, $rule)
    {
        /*
        Rule is a part of rules collection, which includes only rules with 'No Coupon' type or with validated coupon.
        As a result, if rule uses coupon code(s) ('Specific' or 'Auto' Coupon Type), it always contains validated coupon
        */
        if ($rule->getCouponType() != Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON) {
            $address->setCouponCode($this->getCouponCode());
        }

        return $this;
    }

Rate the answer?