/** * Main function for handling the addition of a new address * or editing of an existing address. * * @param $strType - either 'shipping' or 'billing' * @param $intAction - add address or edit address * @param null $intAddressId - id of address to be edited * @return void * @throws Exception */ protected function addressEditor($strType, $intAction, $intAddressId = null) { if ($strType === 'billing') { $strCancelAction = 'final'; $strRedirectPath = '/checkout/final'; $strPartial = '_paymentaddress'; if ($intAction === self::EDITADDRESS) { $strHeader = Yii::t('checkout', 'Update Billing Address'); } else { $strHeader = Yii::t('checkout', 'Add Billing Address'); } } else { // it's shipping $strCancelAction = 'shippingaddress'; $strRedirectPath = '/checkout/shippingaddress'; $strPartial = '_shippingaddress'; if ($intAction === self::EDITADDRESS) { $strHeader = Yii::t('checkout', 'Update Shipping Address'); } else { $strHeader = Yii::t('checkout', 'Add Shipping Address'); } } // we shouldn't be in here if user is a guest if (Yii::app()->user->isGuest === true) { $this->redirect($this->createUrl($strRedirectPath)); } $this->publishJS('shipping'); $this->publishJS('zippo'); $this->layout = '/layouts/checkout'; $this->checkoutForm = MultiCheckoutForm::loadFromSessionOrNew(); if ($intAction === self::EDITADDRESS) { $this->checkoutForm->fillAddressFields($intAddressId, $strType); } else { // action is addaddress so clear all address // fields and display a blank form $this->checkoutForm->clearAddressFields($strType); } if (isset($_POST['MultiCheckoutForm'])) { $this->checkoutForm->attributes = $_POST['MultiCheckoutForm']; $this->checkoutForm->pickupFirstName = null; $this->checkoutForm->pickupLastName = null; if ($strType === 'billing') { $this->checkoutForm->billingPostal = strtoupper($this->checkoutForm->billingPostal); if ($intAction === self::EDITADDRESS) { $this->checkoutForm->intBillingAddress = $intAddressId; CustomerAddress::updateAddressFromForm($intAddressId, $this->checkoutForm, $strType); } else { $this->checkoutForm->billingSameAsShipping = 0; $this->checkoutForm->intBillingAddress = null; } } else { $this->checkoutForm->contactFirstName = $this->checkoutForm->shippingFirstName; $this->checkoutForm->contactLastName = $this->checkoutForm->shippingLastName; $this->checkoutForm->shippingPostal = strtoupper($this->checkoutForm->shippingPostal); if ($intAction === self::EDITADDRESS) { $this->checkoutForm->intShippingAddress = $intAddressId; CustomerAddress::updateAddressFromForm($intAddressId, $this->checkoutForm, $strType); } else { $this->checkoutForm->intShippingAddress = null; } } $this->checkoutForm->saveFormToSession(); // Save the address based on the infomation provided if ($this->checkoutForm->updateAddressId($strType)) { $this->checkoutForm->saveFormToSession(); switch ($strType) { case 'billing': $this->redirect($this->createUrl('/checkout/final')); break; default: $this->redirect($this->createUrl('/checkout/shippingaddress')); } } } $this->render('editaddress', array('model' => $this->checkoutForm, 'error' => $this->formatErrors(), 'partial' => $strPartial, 'cancel' => $strCancelAction, 'header' => $strHeader)); }