Question

I need to sent an coupon code while new user registration. coupon code i based on category and its valid for one month. How to generate the coupon code in registration page.

Was it helpful?

Solution

You can find here a script that will generate a coupon code.
An other approach you could take is to create a coupon code in the backend and just put a debug code inside Mage_Adminhtml_Promo_QuoteController::saveAction to see how the data sent through post looks like.
Add this

Mage::log($data, null, 'discount.log', true);

right before $model->loadPost($data);.
Then check the file var/log/discount.log.
You should find there how the structure of the coupon data should look like.

Then create an observer for the customer_register_success where you build an array that has the same structure as what is contained in the log file and do this:

$data = ...;//build your array here
$model = Mage::getModel('salesrule/rule');
$model->loadPost($data);
$model->save();

OTHER TIPS

If you need a code to be sent in the same email as the registration confirmation, you can extend the customer class and add a custom method getMyCoupon() with the logic described in Marius' answer.

Then in the email jus use {{var customer.getMyCoupon()}}

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top