Index: branches/5.2.x/units/orders/orders_event_handler.php =================================================================== diff -u -N -r14582 -r14594 --- branches/5.2.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 14582) +++ branches/5.2.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 14594) @@ -1,6 +1,6 @@ Application->isAdminUser) { if ($event->Name == 'OnCreate') { @@ -1084,11 +1086,14 @@ * Load item if id is available * * @param kEvent $event + * @return void + * @access protected */ - function LoadItem(&$event) + protected function LoadItem(&$event) { $id = $this->getPassedID($event); - if ($id == FAKE_ORDER_ID) { + + if ( $id == FAKE_ORDER_ID ) { // if we already know, that there is no such order, // then don't run database query, that will confirm that @@ -1209,20 +1214,14 @@ if ($this->Application->GetVar('check_shipping_address')) { $has_tangibles = $order->HasTangibleItems(); $req_fields = array('ShippingTo', 'ShippingAddress1', 'ShippingCity', 'ShippingZip', 'ShippingCountry', 'ShippingPhone'); - foreach ($req_fields as $field) { - $order->setRequired($field, $has_tangibles); - } - + $order->setRequired($req_fields, $has_tangibles); $order->setRequired('ShippingState', $cs_helper->CountryHasStates( $field_values['ShippingCountry'] )); } // billing address required fields if ($this->Application->GetVar('check_billing_address')) { $req_fields = array('BillingTo', 'BillingAddress1', 'BillingCity', 'BillingZip', 'BillingCountry', 'BillingPhone'); - foreach ($req_fields as $field) { - $order->setRequired($field, true); - } - + $order->setRequired($req_fields); $order->setRequired('BillingState', $cs_helper->CountryHasStates( $field_values['BillingCountry'] )); } @@ -1242,9 +1241,7 @@ $req_fields = array('PaymentCardType', 'PaymentAccount', 'PaymentNameOnCard', 'PaymentCCExpDate', 'PaymentCVV2'); } - foreach ($req_fields as $field) { - $order->setRequired($field, true); - } + $order->setRequired($req_fields); } } @@ -1278,20 +1275,25 @@ /* ======================== ADMIN ONLY ======================== */ /** - * Prepare temp tables and populate it - * with items selected in the grid + * 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(); + /* @var $object kDBItem */ $this->setNextOrderNumber($event); $object->SetDBField('OrderIP', $_SERVER['REMOTE_ADDR']); + $order_type = $this->getTypeBySpecial( $this->Application->GetVar('order_type') ); $object->SetDBField('Status', $order_type); } @@ -1300,9 +1302,13 @@ * When cloning orders set new order number to them * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeClone(&$event) + protected function OnBeforeClone(&$event) { + parent::OnBeforeClone($event); + $object =& $event->getObject(); if (substr($event->Special, 0, 9) == 'recurring') { @@ -1979,27 +1985,34 @@ * Split one timestamp field into 2 virtual fields * * @param kEvent $event - * @access public + * @return void + * @access protected */ - function OnAfterItemLoad(&$event) + protected function OnAfterItemLoad(&$event) { - // get user fields + parent::OnAfterItemLoad($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ + + // get user fields $user_id = $object->GetDBField('PortalUserId'); - if($user_id) - { + + if ( $user_id ) { $user_info = $this->Conn->GetRow('SELECT *, CONCAT(FirstName,\' \',LastName) AS UserTo FROM '.TABLE_PREFIX.'PortalUser WHERE PortalUserId = '.$user_id); - $fields = Array('UserTo'=>'UserTo','UserPhone'=>'Phone','UserFax'=>'Fax','UserEmail'=>'Email', - 'UserAddress1'=>'Street','UserAddress2'=>'Street2','UserCity'=>'City','UserState'=>'State', - 'UserZip'=>'Zip','UserCountry'=>'Country','UserCompany'=>'Company'); - foreach($fields as $object_field => $user_field) - { - $object->SetDBField($object_field,$user_info[$user_field]); + $fields = Array( + 'UserTo'=>'UserTo','UserPhone'=>'Phone','UserFax'=>'Fax','UserEmail'=>'Email', + 'UserAddress1'=>'Street','UserAddress2'=>'Street2','UserCity'=>'City','UserState'=>'State', + 'UserZip'=>'Zip','UserCountry'=>'Country','UserCompany'=>'Company' + ); + + foreach ($fields as $object_field => $user_field) { + $object->SetDBField($object_field, $user_info[$user_field]); } } - $object->SetDBField('PaymentCVV2', $this->Application->RecallVar('CVV2Code') ); + $object->SetDBField('PaymentCVV2', $this->Application->RecallVar('CVV2Code')); $cs_helper =& $this->Application->recallObject('CountryStatesHelper'); /* @var $cs_helper kCountryStatesHelper */ @@ -2017,8 +2030,10 @@ * Processes states * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { parent::OnBeforeItemCreate($event); @@ -2030,11 +2045,13 @@ } /** - * Enter description here... + * Processes states * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { parent::OnBeforeItemUpdate($event); @@ -2044,12 +2061,12 @@ $old_payment_type = $object->GetOriginalField('PaymentType'); $new_payment_type = $object->GetDBField('PaymentType'); - if ($new_payment_type != $old_payment_type) { + if ( $new_payment_type != $old_payment_type ) { // payment type changed -> check that it's allowed $available_payment_types = $this->Application->siteDomainField('PaymentTypes'); - if ($available_payment_types) { - if (strpos($available_payment_types, '|' . $new_payment_type . '|') === false) { + if ( $available_payment_types ) { + if ( strpos($available_payment_types, '|' . $new_payment_type . '|') === false ) { // payment type isn't allowed in site domain $object->SetDBField('PaymentType', $old_payment_type); } @@ -2062,25 +2079,26 @@ $cs_helper->PopulateStates($event, 'ShippingState', 'ShippingCountry'); $cs_helper->PopulateStates($event, 'BillingState', 'BillingCountry'); - if ($object->HasTangibleItems()) { + if ( $object->HasTangibleItems() ) { $cs_helper->CheckStateField($event, 'ShippingState', 'ShippingCountry', false); } $cs_helper->CheckStateField($event, 'BillingState', 'BillingCountry', false); - if ($object->GetDBField('Status') > ORDER_STATUS_PENDING) { + if ( $object->GetDBField('Status') > ORDER_STATUS_PENDING ) { return ; } $this->CheckUser($event); - if(!$object->GetDBField('OrderIP')) - { + + if ( !$object->GetDBField('OrderIP') ) { $object->SetDBField('OrderIP', $_SERVER['REMOTE_ADDR']); } $shipping_option = $this->Application->GetVar('OriginalShippingOption'); $new_shipping_option = $object->GetDBField('ShippingOption'); - if ($shipping_option != $new_shipping_option) { + + if ( $shipping_option != $new_shipping_option ) { $this->UpdateShippingOption($event); } else { @@ -2095,10 +2113,11 @@ * Apply any custom changes to list's sql query * * @param kEvent $event + * @return void * @access protected - * @see OnListBuild + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject(); @@ -3331,19 +3350,30 @@ return array_merge($columns, $new_columns); } - 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) { - $copied_ids = unserialize($this->Application->RecallVar($event->Prefix.'_copied_ids'.$this->Application->GetVar('wid'), serialize(array()))); - foreach ($copied_ids as $id) { - $an_event = new kEvent($this->Prefix.':Dummy'); - $this->Application->SetVar($this->Prefix.'_id', $id); - $this->Application->SetVar($this->Prefix.'_mode', ''); // this is to fool ReserveItems to use live table - $this->ReserveItems($an_event); - } + parent::OnSave($event); + + if ( $event->status != kEvent::erSUCCESS ) { + return ; } - return $res; + + $copied_ids = unserialize($this->Application->RecallVar($event->Prefix . '_copied_ids' . $this->Application->GetVar('wid'), serialize(Array ()))); + + foreach ($copied_ids as $id) { + $an_event = new kEvent($this->Prefix . ':Dummy'); + $this->Application->SetVar($this->Prefix . '_id', $id); + $this->Application->SetVar($this->Prefix . '_mode', ''); // this is to fool ReserveItems to use live table + $this->ReserveItems($an_event); + } } /**