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

1 Answer 1

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);
1
  • tnx for your attention, yes I found my problem
    – Yuseferi
    Commented Feb 24, 2014 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.