Index: branches/5.1.x/units/orders/orders_event_handler.php =================================================================== diff -u -r13100 -r13465 --- branches/5.1.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 13100) +++ branches/5.1.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 13465) @@ -1,6 +1,6 @@ Application->recallObject('CountryStatesHelper'); + /* @var $cs_helper kCountryStatesHelper */ + $address =& $this->Application->recallObject('addr.-item','addr', Array('skip_autoload' => true)); $addr_list =& $this->Application->recallObject('addr', 'addr_List', Array('per_page'=>-1, 'skip_counting'=>true) ); $addr_list->Query(); @@ -592,16 +594,6 @@ { $this->setBillingAddress($event); - $cs_helper =& $this->Application->recallObject('CountryStatesHelper'); - - $object =& $event->getObject(); - if( $object->HasTangibleItems() ) - { - $cs_helper->CheckStateField($event, 'ShippingState', 'ShippingCountry'); - } - - $cs_helper->CheckStateField($event, 'BillingState', 'BillingCountry'); - parent::OnUpdate($event); if ($this->Application->isAdminUser) { @@ -616,6 +608,9 @@ } else { // strange: recalculate total amount on error + $object =& $event->getObject(); + /* @var $object kDBItem */ + $object->SetDBField('TotalAmount', $object->getTotalAmount()); } } @@ -664,28 +659,6 @@ } } - /** - * Enter description here... - * - * @param kEvent $event - */ - function OnPreSave(&$event) - { - $cs_helper =& $this->Application->recallObject('CountryStatesHelper'); - - $object =& $event->getObject(); - if ( $object->GetID() !== false) - { - if( $object->HasTangibleItems() ) - { - $cs_helper->CheckStateField($event, 'ShippingState', 'ShippingCountry'); - } - $cs_helper->CheckStateField($event, 'BillingState', 'BillingCountry'); - } - - parent::OnPreSave($event); - } - function OnUpdateCart(&$event) { $this->Application->HandleEvent($items_event, 'orditems:OnUpdate'); @@ -1199,9 +1172,8 @@ foreach ($req_fields as $field) { $order->Fields[$field]['required'] = $has_tangibles; } - if ($cs_helper->CountryHasStates( getArrayValue($field_values, 'ShippingCountry') )) { - $order->Fields['ShippingState']['required'] = true; // $has_tangibles - } + + $order->setRequired('ShippingState', $cs_helper->CountryHasStates( $field_values['ShippingCountry'] )); } // billing address required fields @@ -1210,9 +1182,8 @@ foreach ($req_fields as $field) { $order->Fields[$field]['required'] = true; } - if ($cs_helper->CountryHasStates( getArrayValue($field_values, 'BillingCountry') )) { - $order->Fields['BillingState']['required'] = true; - } + + $order->setRequired('BillingState', $cs_helper->CountryHasStates( $field_values['BillingCountry'] )); } $check_cc = $this->Application->GetVar('check_credit_card'); @@ -1965,6 +1936,8 @@ $object->SetDBField('PaymentCVV2', $this->Application->RecallVar('CVV2Code') ); $cs_helper =& $this->Application->recallObject('CountryStatesHelper'); + /* @var $cs_helper kCountryStatesHelper */ + $cs_helper->PopulateStates($event, 'ShippingState', 'ShippingCountry'); $cs_helper->PopulateStates($event, 'BillingState', 'BillingCountry'); @@ -1975,19 +1948,49 @@ } /** + * Processes states + * + * @param kEvent $event + */ + function OnBeforeItemCreate(&$event) + { + parent::OnBeforeItemCreate($event); + + $cs_helper =& $this->Application->recallObject('CountryStatesHelper'); + /* @var $cs_helper kCountryStatesHelper */ + + $cs_helper->PopulateStates($event, 'ShippingState', 'ShippingCountry'); + $cs_helper->PopulateStates($event, 'BillingState', 'BillingCountry'); + } + + /** * Enter description here... * * @param kEvent $event */ function OnBeforeItemUpdate(&$event) { + parent::OnBeforeItemUpdate($event); + + $object =& $event->getObject(); + /* @var $object OrdersItem */ + $cs_helper =& $this->Application->recallObject('CountryStatesHelper'); + /* @var $cs_helper kCountryStatesHelper */ + $cs_helper->PopulateStates($event, 'ShippingState', 'ShippingCountry'); $cs_helper->PopulateStates($event, 'BillingState', 'BillingCountry'); - $object = &$event->getObject(); - if ($object->GetDBField('Status') > ORDER_STATUS_PENDING) return; + if ($object->HasTangibleItems()) { + $cs_helper->CheckStateField($event, 'ShippingState', 'ShippingCountry', false); + } + $cs_helper->CheckStateField($event, 'BillingState', 'BillingCountry', false); + + if ($object->GetDBField('Status') > ORDER_STATUS_PENDING) { + return ; + } + $this->CheckUser($event); if(!$object->GetDBField('OrderIP')) {