function uc_coupon_save in Ubercart Discount Coupons 7.2
Same name and namespace in other branches
- 6 uc_coupon.module \uc_coupon_save()
- 7.3 uc_coupon.module \uc_coupon_save()
Save a coupon object.
If the 'cid' field is set, then this will update an existing coupon. Otherwise, a new bulk seed will be generated, the coupon will be inserted into the database, and $coupon->cid will be set.
Parameters
$coupon: The coupon to save.
$edit: An optional array of extra data that other modules may need to save.
3 calls to uc_coupon_save()
- uc_coupon_add_form_submit in ./
uc_coupon.admin.inc - Coupon form submit handler.
- uc_coupon_purchase_create in uc_coupon_purchase/
uc_coupon_purchase.module - Create newly purchased coupons, based on the supplied coupon object.
- uc_coupon_workflow_assign in uc_coupon_workflow/
uc_coupon_workflow.rules.inc - Action callback to assign a coupon to a user.
File
- ./
uc_coupon.entity.inc, line 55
Code
function uc_coupon_save(&$coupon, $edit = array()) {
// Allow other modules to alter the coupon before saving.
foreach (module_implements('uc_coupon_presave') as $module) {
$callback = $module . '_uc_coupon_presave';
$callback($coupon, $edit);
}
if (isset($coupon->cid)) {
drupal_write_record('uc_coupons', $coupon, 'cid');
}
else {
$coupon->created = REQUEST_TIME;
$coupon->bulk_seed = md5(uniqid());
drupal_write_record('uc_coupons', $coupon);
}
// Notify other modules that a coupon has been saved.
module_invoke_all('uc_coupon_save', $coupon);
}