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;
    }

According to the statistics, you may find helpfull the following question about magento 2 500 error after upgrade.

How can we help you?

Didn’t you find the answer to your question? We are always happy to help you out.