I am using Magento Enterprise 1.14.0.1 On the success.phtml I have a php code that automatically generates a coupon code. The code does generate the coupon I see in the Magento admin.However I can not figure out how to display it on the page?
Here is my code that generates the coupon
//Below is code to generate a coupon code and display it in a jquery popup window
$todaysdateis = date('Y-m-d', strtotime('+1 year'));
$generator = Mage::getModel('salesrule/coupon_massgenerator');
$data = array
(
'max_probability' => .25,
'max_attempts' => 10,
'uses_per_customer' => 1,
'uses_per_coupon' => 1,
'qty' => 1, //number of coupons to generate
'length' => 14, //length of coupon string
'to_date' => "$todaysdateis", //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' => 68 //the id of the shopping cart rule you will use as a template
);
$generator->validateData($data);
$generator->setData($data);
$generator->generatePool();
//get the generate coupon code
$salesRule = Mage::getModel('salesrule/rule')->load($data['rule_id']);
$collection = Mage::getResourceModel('salesrule/coupon_collection')
->addRuleToFilter($salesRule)
->addGeneratedCouponsFilter();
$thecode = $generator->getCode();
echo "Your Code Is $thecode";
//End code to generate a coupon code and display it in a jquery popup window ?>
The goal is I want to eventually display this to the page not send it in an email.