1

Is there any way to generate Drupal commerce coupon code bulky? I found commerce_coupon_batch module but it require Commerce_coupon_ui module that there is not exist in sub module of commerce_coupon version 7.x-2.0-beta1.

I don't try anything yet, How can I generate coupon code bulky? I look at db and found there is a table for coupon ,commerce_coupon is just sufficient to add record to this table programmatically?

I try below code to create one coupon , but nothing added to coupon list in admin/commerce/coupons :

$No=$form_state["values"]["code_NO"];
    $type_id=$form_state["values"]["type"];
    $record['type']='discount_coupon';
    $record['code']=commerce_coupon_generate_coupon_code($type_id);
    $record['commerce_discount_reference']['und']['0']['target_id'] =$type_id;
    $record['commerce_coupon_conditions']['und'][0]=Array('condition_name'=>'commerce_coupon_usage_evaluate_usage',
            'condition_settings' =>Array( 'max_usage'=> 1),
            'remove_condition'=> 'Remove',);
ym(entity_get_controller('commerce_coupon')->create($record));

enter image description here

0

I think your code is good but you forget save entity .I hope this get clue to you to achieve your job.

$No=$form_state["values"]["code_NO"];
    $type_id=$form_state["values"]["type"];
    $record['type']='discount_coupon';
    $record['code']=commerce_coupon_generate_coupon_code($type_id);
    $record['commerce_discount_reference']['und']['0']['target_id'] =$type_id;
    $record['commerce_coupon_conditions']['und'][0]=Array('condition_name'=>'commerce_coupon_usage_evaluate_usage',
            'condition_settings' =>Array( 'max_usage'=> 1),
            'remove_condition'=> 'Remove',);
$entity=entity_get_controller('commerce_coupon')->create($record);
commerce_coupon_save($entity);
|improve this answer|||||
  • tnx for your attention, yes I found my problem – Yusef Feb 24 '14 at 8:17

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.