Index: branches/5.2.x/units/products/products_event_handler.php =================================================================== diff -u -N -r14436 -r14625 --- branches/5.2.x/units/products/products_event_handler.php (.../products_event_handler.php) (revision 14436) +++ branches/5.2.x/units/products/products_event_handler.php (.../products_event_handler.php) (revision 14625) @@ -1,6 +1,6 @@ getObject(); + /* @var $object kDBItem */ - $product_approve_events = Array( + $product_approve_events = Array ( 2 => 'p:OnSubscriptionApprove', 4 => 'p:OnDownloadableApprove', 5 => 'p:OnPackageApprove' ); $product_type = $object->GetDBField('Type'); - $type_found = in_array($product_type, array_keys($product_approve_events) ); + $type_found = in_array($product_type, array_keys($product_approve_events)); - if ($type_found && !$object->GetDBField('ProcessingData') ) { - $processing_data = Array('ApproveEvent' => $product_approve_events[$product_type] ); - $object->SetDBField( 'ProcessingData', serialize($processing_data) ); + if ( $type_found && !$object->GetDBField('ProcessingData') ) { + $processing_data = Array ('ApproveEvent' => $product_approve_events[$product_type]); + $object->SetDBField('ProcessingData', serialize($processing_data)); } } @@ -285,22 +288,37 @@ } } - function OnBeforeDeleteFromLive(&$event) + /** + * Occurs before an item is deleted from live table when copying from temp + * (temp handler deleted all items from live and then copy over all items from temp) + * Id of item being deleted is passed as event' 'id' param + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeDeleteFromLive(&$event) { - $id = $event->getEventParam('id'); - $product =& $this->Application->recallObject($event->Prefix.'.itemlive', null, Array('skip_autoload' => true)); + parent::OnBeforeDeleteFromLive($event); + + $product =& $this->Application->recallObject($event->Prefix . '.itemlive', null, Array ('skip_autoload' => true)); /* @var $product kCatDBItem */ $product->SwitchToLive(); - if (!$product->Load($id)) return ; // this will make sure New product will not be overwritten with empty data + $id = $event->getEventParam('id'); - $temp =& $this->Application->recallObject($event->Prefix.'.itemtemp', null, Array('skip_autoload' => true)); + if ( !$product->Load($id) ) { + // this will make sure New product will not be overwritten with empty data + return ; + } + + $temp =& $this->Application->recallObject($event->Prefix . '.itemtemp', null, Array ('skip_autoload' => true)); /* @var $temp kCatDBItem */ $temp->SwitchToTemp(); $temp->Load($id); - $temp->SetDBFieldsFromHash($product->GetFieldValues(), Array('QtyInStock','QtyReserved','QtyBackOrdered','QtyOnOrder')); + $temp->SetDBFieldsFromHash($product->GetFieldValues(), Array ('QtyInStock', 'QtyReserved', 'QtyBackOrdered', 'QtyOnOrder')); $temp->Update(); } @@ -311,23 +329,42 @@ $this->Application->RemoveVar('inventory_actions'); } - function OnSave(&$event) + /** + * Saves content of temp table into live and + * redirects to event' default redirect (normally grid template) + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnSave(&$event) { - $res = parent::OnSave($event); - if ($event->status == kEvent::erSUCCESS) { + parent::OnSave($event); + + if ( $event->status == kEvent::erSUCCESS ) { $this->RunScheduledInventoryActions($event); } - return $res; } - function OnPreCreate(&$event) + /** + * 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 + */ + protected function OnPreCreate(&$event) { parent::onPreCreate($event); - $object =& $event->GetObject(); - $object->SetDBField('Type', $this->Application->GetVar( $event->getPrefixSpecial(true).'_new_type' )); + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $object->SetDBField('Type', $this->Application->GetVar($event->getPrefixSpecial(true) . '_new_type')); } - /** * Enter description here... * @@ -865,11 +902,14 @@ } /** - * Checks, that all required product options are filled in before product is saved + * Saves edited item into temp table + * If there is no id, new item is created in temp table * * @param kEvent $event + * @return void + * @access protected */ - function OnPreSave(&$event) + protected function OnPreSave(&$event) { $this->CheckRequiredOptions($event); @@ -880,8 +920,10 @@ * Set new price to ProductsPricing * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemCreate(&$event) + protected function OnAfterItemCreate(&$event) { parent::OnAfterItemCreate($event); @@ -996,15 +1038,23 @@ * * @param kEvent $event */ - function OnAfterItemLoad(&$event) + + /** + * Load price from temp table if product mode is temp table + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnAfterItemLoad(&$event) { parent::OnAfterItemLoad($event); $object =& $event->getObject(); /* @var $object ProductsItem */ $a_pricing = $object->getPrimaryPricing(); - if (!$a_pricing) { + if ( !$a_pricing ) { // pricing doesn't exist for new products $price = $cost = null; }