Index: branches/5.2.x/units/product_option_combinations/product_option_combinations_event_handler.php =================================================================== diff -u -N -r14258 -r14625 --- branches/5.2.x/units/product_option_combinations/product_option_combinations_event_handler.php (.../product_option_combinations_event_handler.php) (revision 14258) +++ branches/5.2.x/units/product_option_combinations/product_option_combinations_event_handler.php (.../product_option_combinations_event_handler.php) (revision 14625) @@ -1,6 +1,6 @@ Set($event->getPrefixSpecial().'_GoId', ''); } - function LoadItem(&$event) + /** + * Load item if id is available + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function LoadItem(&$event) { $object =& $event->getObject(); + /* @var $object kDBItem */ + $id = $this->getPassedID($event); - if (!$id) { + + if ( !$id ) { $event->CallSubEvent('OnNew'); + + return ; } - else { - if ($object->Load($id) ) - { - $actions =& $this->Application->recallObject('kActions'); - $actions->Set($event->getPrefixSpecial().'_id', $object->GetId() ); - } - else - { - //$object->setID($id); - } + + if ( $object->Load($id) ) { + $actions =& $this->Application->recallObject('kActions'); + /* @var $actions Params */ + + $actions->Set($event->getPrefixSpecial() . '_id', $object->GetId()); } } @@ -277,8 +288,18 @@ return $special; } - 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); + $event->Init($event->Prefix, '-item'); $object =& $event->getObject(); @@ -306,9 +327,13 @@ * Restore back values from live table to temp table before overwriting live with temp * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeDeleteFromLive(&$event) + protected function OnBeforeDeleteFromLive(&$event) { + parent::OnBeforeDeleteFromLive($event); + // check if product inventory management is via options and then proceed $id = $event->getEventParam('id'); @@ -317,24 +342,25 @@ $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); $sql = 'SELECT p.InventoryStatus - FROM '.$products_table.' p - LEFT JOIN '.$table_name.' poc ON poc.ProductId = p.ProductId - WHERE poc.'.$id_field.' = '.$id; + FROM ' . $products_table . ' p + LEFT JOIN ' . $table_name . ' poc ON poc.ProductId = p.ProductId + WHERE poc.' . $id_field . ' = ' . $id; + $inventory_status = $this->Conn->GetOne($sql); - if ($this->Conn->GetOne($sql) == 2) { - $live_object =& $this->Application->recallObject($event->Prefix.'.itemlive', null, Array('skip_autoload' => true)); + if ( $inventory_status == ProductInventory::BY_OPTIONS ) { + $live_object =& $this->Application->recallObject($event->Prefix . '.itemlive', null, Array ('skip_autoload' => true)); /* @var $live_object kDBItem */ $live_object->SwitchToLive(); $live_object->Load($id); - $temp_object =& $this->Application->recallObject($event->Prefix.'.itemtemp', null, Array('skip_autoload' => true)); + $temp_object =& $this->Application->recallObject($event->Prefix . '.itemtemp', null, Array ('skip_autoload' => true)); /* @var $temp_object kDBItem */ $temp_object->SwitchToTemp(); $temp_object->Load($id); - $temp_object->SetDBFieldsFromHash($live_object->GetFieldValues(), Array('QtyInStock','QtyReserved','QtyBackOrdered','QtyOnOrder')); + $temp_object->SetDBFieldsFromHash($live_object->GetFieldValues(), Array ('QtyInStock', 'QtyReserved', 'QtyBackOrdered', 'QtyOnOrder')); $temp_object->Update(); } }