private function updateEstimateAddress() { if ($this->config->get('ENABLE_SHIPPING_ESTIMATE')) { if ($this->request->get('estimate_state_select')) { $this->request->set('estimate_stateID', $this->request->get('estimate_state_select')); } if ($this->request->get('estimate_state_text')) { $this->request->set('estimate_stateName', $this->request->get('estimate_state_text')); } $address = SessionOrder::getDefaultEstimateAddress(); $address->loadRequestData($this->request, 'estimate_'); if ($country = $this->request->get('estimate_country')) { $address->countryID->set($country); } SessionOrder::setEstimateAddress($address); } }
/** * @role login */ public function doSelectAddress() { $this->user->loadAddresses(); $step = $this->request->get('step'); $validator = $this->buildAddressSelectorValidator($this->order, $step); if (!$validator->isValid()) { return new ActionRedirectResponse('checkout', 'selectAddress', array('query' => array('step' => $step))); } // create or edit addresses $types = array('billing', 'shipping'); if ($this->request->get('sameAsBilling') || $this->order->isMultiAddress->get()) { unset($types[1]); } foreach ($types as $type) { if ((!$step || $type == $step) && !$this->request->get($type . 'Address')) { $addressField = 'default' . ucfirst($type) . 'Address'; if ($address = $this->user->{$addressField}->get()) { $address->load(); $this->saveAddress($address->userAddress->get(), $type . '_'); } else { $address = $this->createAddress(ucfirst($type) . 'Address', $type . '_'); } $this->lastAddress = $address; $this->request->set($type . 'Address', $address->userAddress->get()->getID()); } } try { if (!$step || 'billing' == $step) { if (!$this->user->isAnonymous()) { $f = new ARSelectFilter(); $f->setCondition(new EqualsCond(new ARFieldHandle('BillingAddress', 'userID'), $this->user->getID())); $f->mergeCondition(new EqualsCond(new ARFieldHandle('BillingAddress', 'userAddressID'), $this->request->get('billingAddress'))); $r = ActiveRecordModel::getRecordSet('BillingAddress', $f, array('UserAddress')); if ($r->size()) { $billing = $r->get(0); } else { if (!($billing = $this->user->defaultBillingAddress->get())) { throw new ApplicationException('Invalid billing address'); } } $address = $billing->userAddress->get(); } else { $address = $address->userAddress->get(); } $this->order->billingAddress->set($address); } // shipping address if ($this->isShippingRequired($this->order) && !$this->order->isMultiAddress->get() && (!$step || 'shipping' == $step)) { if ($this->request->get('sameAsBilling')) { if (isset($billing)) { $shipping = $billing->userAddress->get(); } else { $shipping = $this->order->billingAddress->get(); } } else { $f = new ARSelectFilter(); $f->setCondition(new EqualsCond(new ARFieldHandle('ShippingAddress', 'userID'), $this->user->getID())); $f->mergeCondition(new EqualsCond(new ARFieldHandle('ShippingAddress', 'userAddressID'), $this->request->get('shippingAddress'))); $r = ActiveRecordModel::getRecordSet('ShippingAddress', $f, array('UserAddress')); if (!$r->size()) { throw new ApplicationException('Invalid shipping address'); } $shipping = $r->get(0)->userAddress->get(); } $this->order->shippingAddress->set($shipping); SessionOrder::setEstimateAddress($shipping); } if ($this->config->get('REQUIRE_SAME_ADDRESS') && $this->order->isShippingRequired()) { $this->order->shippingAddress->set($this->order->billingAddress->get()); $step = 'shipping'; } if ('billing' != $step) { $this->order->resetShipments(); } } catch (Exception $e) { throw $e; return new ActionRedirectResponse('checkout', 'selectAddress', array('query' => array('step' => $step))); } $this->order->loadRequestData($this->request); SessionOrder::save($this->order); if ('billing' == $step && ($this->isShippingRequired($this->order) && !$this->order->isMultiAddress->get())) { return new ActionRedirectResponse('checkout', 'selectAddress', array('query' => array('step' => 'shipping'))); } else { return new ActionRedirectResponse('checkout', 'shipping'); } }