function uc_coupon_save in Ubercart Discount Coupons 6
Same name and namespace in other branches
- 7.3 uc_coupon.module \uc_coupon_save()
- 7.2 uc_coupon.entity.inc \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_register_user in uc_coupon_register/
uc_coupon_register.module - Implementation of hook_user().
File
- ./
uc_coupon.module, line 262 - Provides discount coupons for Ubercart.
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 = 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);
}