Index: branches/5.2.x/units/coupons/coupons_event_handler.php =================================================================== diff -u -N -r14587 -r14625 --- branches/5.2.x/units/coupons/coupons_event_handler.php (.../coupons_event_handler.php) (revision 14587) +++ branches/5.2.x/units/coupons/coupons_event_handler.php (.../coupons_event_handler.php) (revision 14625) @@ -1,6 +1,6 @@ SetDBField('DefaultExpiration_time', $default_expiration); } - - function OnBeforeClone(&$event) + /** + * Occurs before an item has been cloned + * Id of newly created item is passed as event' 'id' param + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeClone(&$event) { parent::OnBeforeClone($event); @@ -206,33 +213,69 @@ } /** - * Enter description here... + * Prepare temp tables for creating new item + * but does not create it. Actual create is + * done in OnPreSaveCreated * * @param kEvent $event + * @return void + * @access protected */ - function OnPreCreate(&$event){ - + protected function OnPreCreate(&$event) + { parent::OnPreCreate($event); - $object = &$event->getObject(); - $exp_date = adodb_mktime(); + $object =& $event->getObject(); + /* @var $object kDBItem */ + $exp_date = adodb_mktime(); $default_duration = $this->Application->ConfigValue('Comm_DefaultCouponDuration'); - if ($default_duration && $default_duration>0){ - $exp_date += (int)$default_duration*86400; + if ( $default_duration && $default_duration > 0 ) { + $exp_date += (int)$default_duration * 86400; } + $object->SetDBField('Expiration_date', $exp_date); } - function OnBeforeItemUpdate(&$event) + /** + * Occurs before updating item + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeItemUpdate(&$event) { - $object =& $event->getObject(); - $object->SetDBField( 'Amount', abs($object->GetDBField('Amount')) ); + parent::OnBeforeItemUpdate($event); + + $this->itemChanged($event); } - function OnBeforeItemCreate(&$event) + /** + * Occurs before creating item + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeItemCreate(&$event) { - $this->OnBeforeItemUpdate($event); + parent::OnBeforeItemCreate($event); + + $this->itemChanged($event); } + + /** + * Occurs before item is changed + * + * @param kEvent $event + */ + function itemChanged(&$event) + { + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $object->SetDBField('Amount', abs($object->GetDBField('Amount'))); + } } \ No newline at end of file