Index: branches/5.2.x/units/shipping_costs/shipping_costs_event_handler.php =================================================================== diff -u -N -r15047 -r15061 --- branches/5.2.x/units/shipping_costs/shipping_costs_event_handler.php (.../shipping_costs_event_handler.php) (revision 15047) +++ branches/5.2.x/units/shipping_costs/shipping_costs_event_handler.php (.../shipping_costs_event_handler.php) (revision 15061) @@ -1,6 +1,6 @@ getObject(Array ('skip_autoload' => true)); /* @var $object kDBItem */ @@ -170,15 +172,22 @@ */ function OnClearAll(&$event) { - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); + /* @var $object kDBItem */ + $zones_object =& $this->Application->recallObject('z'); + /* @var $zones_object kDBItem */ - $sql = 'SELECT ZoneID FROM '.$zones_object->TableName.' WHERE ShippingTypeID='.$this->Application->GetVar('s_id'); + $sql = 'SELECT ZoneID + FROM ' . $zones_object->TableName . ' + WHERE ShippingTypeID = ' . $this->Application->GetVar('s_id'); $res = $this->Conn->GetCol($sql); - $sql = 'DELETE FROM '.$object->TableName.' WHERE ZoneID IN ('.implode(',', $res).')'; + + $sql = 'DELETE FROM ' . $object->TableName . ' + WHERE ZoneID IN (' . implode(',', $res) . ')'; $this->Conn->Query($sql); - $event->setRedirectParams(Array('opener' => 's', 'pass_events' => false), true); + $event->setRedirectParams(Array ('opener' => 's', 'pass_events' => false)); $event->status = kEvent::erSUCCESS; } @@ -190,7 +199,7 @@ * @return void * @access protected */ - protected function customProcessing(&$event, $type) + protected function customProcessing(kEvent &$event, $type) { if ( $type == 'before' && $this->Application->GetVar('sc') ) { $shipping_obj =& $this->Application->recallObject('s'); @@ -221,35 +230,70 @@ { $event->CallSubEvent('OnCreate'); $event->redirect = false; - $event->setRedirectParams(Array('opener'=>'s','pass'=>'all'), true); + $event->setRedirectParams(Array ('opener' => 's', 'pass' => 'all')); } - function OnAfterCopyToTemp(&$event) + /** + * Occurs after an item has been copied to temp + * Id of copied item is passed as event' 'id' param + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnAfterCopyToTemp(kEvent &$event) { + parent::OnAfterCopyToTemp($event); + $id = $event->getEventParam('id'); - $object =& $this->Application->recallObject($event->Prefix.'.-item', $event->Prefix); + + $object =& $this->Application->recallObject($event->Prefix . '.-item', $event->Prefix); + /* @var $object kDBItem */ + $object->SwitchToTemp(); $object->Load($id); + $shipping_obj =& $this->Application->recallObject('s'); + /* @var $shipping_obj kDBItem */ + $lang_object =& $this->Application->recallObject('lang.current'); + /* @var $lang_object LanguagesItem */ + // by weight and US/UK system - we need to store recalculated price per Kg cause shipping calculation is done per Kg! - if ($shipping_obj->GetDBField('Type') == 1 && $lang_object->GetDBField('UnitSystem') == 2) { + if ( $shipping_obj->GetDBField('Type') == 1 && $lang_object->GetDBField('UnitSystem') == 2 ) { $object->SetDBField('PerUnit', $object->GetDBField('PerUnit') * kUtil::POUND_TO_KG); $object->Update(null, true); } } - function OnBeforeCopyToLive(&$event) + /** + * Occurs before an item is copied to live table (after all foreign keys have been updated) + * Id of item being copied is passed as event' 'id' param + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeCopyToLive(kEvent &$event) { + parent::OnBeforeCopyToLive($event); + $id = $event->getEventParam('id'); - $object =& $this->Application->recallObject($event->Prefix.'.-item', $event->Prefix); + + $object =& $this->Application->recallObject($event->Prefix . '.-item', $event->Prefix); + /* @var $object kDBItem */ + $object->SwitchToTemp(); $object->Load($id); $shipping_obj =& $this->Application->recallObject('s'); + /* @var $shipping_obj kDBItem */ + $lang_object =& $this->Application->recallObject('lang.current'); + /* @var $lang_object LanguagesItem */ + // by weight and US/UK system - we need to store recalculated price per Kg cause shipping calculation is done per Kg! - if ($shipping_obj->GetDBField('Type') == 1 && $lang_object->GetDBField('UnitSystem') == 2) { + if ( $shipping_obj->GetDBField('Type') == 1 && $lang_object->GetDBField('UnitSystem') == 2 ) { $object->SetDBField('PerUnit', $object->GetDBField('PerUnit') / kUtil::POUND_TO_KG); $object->Update(null, true); }