質問

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?

役に立ちましたか?

解決

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'];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top