Question

I am using drupal with drupal commerce, when a user like the page with facebook like button, I generate a coupon and serve it to the client.

All is going well atm. except for one thing, how do I generate a new coupon?

Was it helpful?

Solution

Ok,

I found a way to do it. I copy an existing coupon and change it.

$coupon = commerce_coupon_load_by_code("facebook_coupon");

    unset($coupon->coupon_id);
    unset($coupon->created);
    unset($coupon->changed);
    unset($coupon->data);
    unset($coupon->commerce_coupon_code);

    // Save 
    commerce_coupon_save($coupon);

    //  rules_invoke_event('facebook_coupon', $coupon);
    echo $coupon->commerce_coupon_code['und'][0]['value'];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top