Coupon codes creation in Magento, how to do it?

$generator = Mage::getModel('salesrule/coupon_massgenerator');

Now you have to set some options:

$data = array(
    'max_probability' => .25,
    'max_attempts' => 10,
    'uses_per_customer' => 1,
    'uses_per_coupon' => 1,
    'qty' => 5, // ​​number of coupons to generate
    'length' => 14, // ​​length of coupon string
    'to_date' => '2013-12-31 ', // ​​ending date of generated promo
     * Possible values ​​include:
     * Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC
     * Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHABETICAL
     * Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_NUMERIC
    'format' => Mage_SalesRule_Helper_Coupon::COUPON_FORMAT_ALPHANUMERIC,
    'rule_id' => 1234 // the id of the rule you will use as a template

Checking $data:


Then you have to save these parameters for generator:


Now we can start to create codes:


fill up parameters in salesrule_coupon tab.

It works pretty good,in Magento admin panel you can also delete the received coupon codes. To do this, refer to the section "Manage Coupon Codes".

If you want to display the collection, use:

$salesRule = Mage::getModel('salesrule/rule')->load($data['rule_id']);
$collection = Mage::getResourceModel('salesrule/coupon_collection')

You are also able to see quantity of  successfully generated coupon codes in magento


Some more good practices here Good luck, and thank you for your attention!