0

I used

Use Auto-Generation

Magento coupon code but all coupon codes generated uppercase like F1Z8Z2FPQQYL

how can I generate the lowercase coupon?!

I found code but I can't understand it, how does it generate the lowercase coupon code!

 public function generateCode()
    {
        $format  = $this->getFormat();
        if (!$format) {
            $format = Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC;
        }
        $length  = max(1, (int) $this->getLength());
        $split   = max(0, (int) $this->getDash());
        $suffix  = $this->getSuffix();
        $prefix  = $this->getPrefix();

        $splitChar = $this->getDelimiter();
        $charset = Mage::helper('salesrule/coupon')->getCharset($format);

        $code = '';
        $charsetSize = count($charset);
        for ($i=0; $i<$length; $i++) {
            $char = $charset[mt_rand(0, $charsetSize - 1)];
            if ($split > 0 && ($i % $split) == 0 && $i != 0) {
                $char = $splitChar . $char;
            }
            $code .= $char;
        }

        $code = $prefix . $code . $suffix;
        return $code;
    }
  • what are you trying to accomplish? the coupon codes are not case sensitive. – Yehuda Schwartz Nov 30 '18 at 14:48
0

The alphabet characters come from app/code/core/Mage/SalesRule/Model/Coupon/Codegenerator.php

public function generateCode()

{

$alphabet = ($this->getAlphabet() ?     $this->getAlphabet() :     'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');

$lengthMin = ($this->getLengthMin() ? $this->getLengthMin() : 16);

$lengthMax = ($this->getLengthMax() ? $this->getLengthMax() : 32);

$length = ($this->getLength() ? $this->getLength() : rand($lengthMin, $lengthMax));

$result = '';

$indexMax = strlen($alphabet) - 1;

for ($i = 0; $i < $length; $i++) {

$index = rand(0, $indexMax);

$result .= $alphabet{$index};

}

return $result;

}

So unless you have a different module with a different implementation of $this->getAlphabet() then your coupon codes should have both uppercase and lowercase characters.

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.