0

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.

0

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();
  • Hi,Thanks for your reply. Where to set category id?. I need to set the rules based on the particular categories for newly register customer ( For example , i want to tshirt and pant category only). – Rat Aug 13 '14 at 7:25
  • You need to set the categories in the conditions section. Take the second approach I added and create a coupon for the category you want and see how the array sent through post looks like. – Marius Aug 13 '14 at 7:32
  • hi, where is the second approach. i didn't find the code because I'm new for magento . – Rat Aug 13 '14 at 8:33
  • Hi Marius, Thanks for your post. Its working fine. – Rat Aug 13 '14 at 13:33
0

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()}}

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.