コード例 #1
0
 public function actionAddress()
 {
     if (Yii::app()->user->isGuest) {
         $this->redirect($this->createUrl("/myaccount"));
     }
     $this->breadcrumbs = array(Yii::t('global', 'My Account') => $this->createUrl("/myaccount"), Yii::t('global', 'Add an address') => $this->createUrl("myaccount/address"));
     $model = new CustomerAddress();
     $model->country_id = _xls_get_conf('DEFAULT_COUNTRY', 224);
     $checkout = new CheckoutForm();
     //For logged in users we grab the current model
     $objCustomer = Customer::GetCurrent();
     $id = null;
     if (Yii::app()->getRequest()->getParam('id') != null) {
         $id = Yii::app()->getRequest()->getParam('id');
     } elseif (isset($_POST['CustomerAddress']) && isset($_POST['CustomerAddress']['id'])) {
         $id = $_POST['CustomerAddress']['id'];
     }
     $objAddress = CustomerAddress::model()->findByPk($id);
     if ($id && $objAddress instanceof CustomerAddress && $objAddress->customer_id == Yii::app()->user->id) {
         $model = $objAddress;
     }
     // collect user input data
     if (isset($_POST['CustomerAddress'])) {
         $model->setScenario('Default');
         $model->attributes = $_POST['CustomerAddress'];
         if ($model->validate()) {
             $model->customer_id = $objCustomer->id;
             if (!$model->save()) {
                 Yii::log('Error creating new customer address ' . print_r($model->getErrors(), true), 'error', 'application.' . __CLASS__ . '.' . __FUNCTION__);
             }
             if (CPropertyValue::ensureBoolean($model->makeDefaultBilling) === true) {
                 $objCustomer->default_billing_id = $model->id;
             } elseif (CPropertyValue::ensureInteger($objCustomer->default_billing_id) === CPropertyValue::ensureInteger($model->id)) {
                 $objCustomer->default_billing_id = null;
             }
             if (CPropertyValue::ensureBoolean($model->makeDefaultShipping) === true) {
                 $objCustomer->default_shipping_id = $model->id;
             } elseif (CPropertyValue::ensureInteger($objCustomer->default_shipping_id) === CPropertyValue::ensureInteger($model->id)) {
                 $objCustomer->default_shipping_id = null;
             }
             $objCustomer->save();
             ShoppingCart::displayNoTaxMessage();
             try {
                 Yii::app()->shoppingcart->setTaxCodeByDefaultShippingAddress();
             } catch (Exception $e) {
                 Yii::log('Error updating customer cart ' . $e->getMessage(), 'error', 'application.' . __CLASS__ . '.' . __FUNCTION__);
             }
             Yii::app()->shoppingcart->save();
             if (Yii::app()->request->isAjaxRequest === false) {
                 $this->redirect($this->createUrl("/myaccount"));
             }
         }
     }
     if ($id && $objCustomer->default_billing_id == $model->id) {
         $model->makeDefaultBilling = 1;
     }
     if ($id && $objCustomer->default_shipping_id == $model->id) {
         $model->makeDefaultShipping = 1;
     }
     // Added Ajax for Brooklyn2014
     if (Yii::app()->request->isAjaxRequest) {
         unset($model->password);
         $errors = $model->getErrors();
         if (empty($errors) === false) {
             $response = array('status' => 'error', 'errors' => $errors);
         } else {
             $response = array('status' => 'success', 'address' => $model);
         }
         $this->renderJSON($response);
     } else {
         $this->render('address', array('model' => $model, 'checkout' => $checkout));
     }
 }
コード例 #2
0
 /**
  * Populate the address fields as required to pass validation
  *
  * @param $intAddressId
  * @param string $str
  * @return void
  */
 public function fillAddressFields($intAddressId, $str = 'billing')
 {
     $objAddress = CustomerAddress::model()->findByPk($intAddressId);
     if (!$objAddress instanceof CustomerAddress) {
         Yii::log('No address found with id: ' . $intAddressId, 'error', 'application.' . __CLASS__ . '.' . __FUNCTION__);
         return;
     }
     switch ($str) {
         case 'billing':
             $this->billingAddress1 = $objAddress->address1;
             $this->billingAddress2 = $objAddress->address2;
             $this->billingCity = $objAddress->city;
             $this->billingState = $objAddress->state_id;
             $this->billingPostal = $objAddress->postal;
             $this->billingCountry = $objAddress->country_id;
             break;
         case 'shipping':
             $this->shippingFirstName = $objAddress->first_name;
             $this->shippingLastName = $objAddress->last_name;
             $this->shippingCompany = $objAddress->company;
             $this->shippingAddress1 = $objAddress->address1;
             $this->shippingAddress2 = $objAddress->address2;
             $this->shippingCity = $objAddress->city;
             $this->shippingState = $objAddress->state_id;
             $this->shippingPostal = $objAddress->postal;
             $this->shippingCountry = $objAddress->country_id;
             $this->shippingResidential = $objAddress->residential;
             if (isset($objAddress->phone) && $objAddress->phone !== '') {
                 // the intended behaviour is to always set the shipping address
                 // phone number (if it exists) as the contact number...
                 $this->contactPhone = $objAddress->phone;
             } else {
                 // ...otherwise we set it to the customer's main phone number
                 $this->contactPhone = $objAddress->customer->mainphone;
             }
             break;
     }
 }
コード例 #3
0
 /**
  * Display the logged in user's list of addresses
  * and handle them choosing one
  *
  * @return void
  */
 public function actionShippingAddress()
 {
     $this->publishJS('shipping');
     $this->publishJS('zippo');
     $this->layout = '/layouts/checkout';
     $error = null;
     $this->checkoutForm = MultiCheckoutForm::loadFromSessionOrNew();
     $arrObjAddresses = CustomerAddress::getActiveAddresses();
     // if the logged in customer has no addresses saved on file
     // take them to the page where they can enter an address
     if (count($arrObjAddresses) < 1) {
         $this->redirect($this->createAbsoluteUrl('/checkout/shipping'));
     }
     $arrFirst = array();
     $objCart = Yii::app()->shoppingcart;
     // if the logged in user has a default shipping address
     // make it appear first
     foreach ($arrObjAddresses as $key => $address) {
         if ($address->id == $objCart->customer->default_shipping_id) {
             $arrFirst['first'] = $address;
             // assign an index to avoid accidental overwrite
             unset($arrObjAddresses[$key]);
         }
     }
     $this->checkoutForm->objAddresses = array_values($arrFirst + $arrObjAddresses);
     $this->checkoutForm->saveFormToSession();
     // populate our form with some default values in case the user
     // was logged in already and bypassed checkout login
     if (isset($this->checkoutForm->contactEmail) === false) {
         $this->checkoutForm->contactEmail = $objCart->customer->email;
     }
     if (isset($this->checkoutForm->contactEmail_repeat) === false) {
         $this->checkoutForm->contactEmail_repeat = $objCart->customer->email;
     }
     if (isset($_POST['MultiCheckoutForm'])) {
         $this->checkoutForm->attributes = $_POST['MultiCheckoutForm'];
     }
     $hasErrors = false;
     $inStorePickupSelected = isset($_POST['storePickupCheckBox']) && $_POST['storePickupCheckBox'] == 1;
     // If in-store pickup was previously selected but has been deselected, make sure it's no longer used.
     if ($inStorePickupSelected === false && $this->checkoutForm->isStorePickupSelected()) {
         // TODO: Factor out this and the similar check in actionShipping.
         $this->checkoutForm->shippingProvider = null;
         $this->checkoutForm->shippingPriority = null;
         $this->checkoutForm->pickupFirstName = null;
         $this->checkoutForm->pickupLastName = null;
     }
     $addressId = Yii::app()->getRequest()->getPost('Address_id');
     $wishlistId = Yii::app()->getRequest()->getPost('wishlistId');
     // Store pickup.
     if ($inStorePickupSelected === true) {
         // store pickup is chosen
         $this->checkoutForm->fillFieldsForStorePickup();
         $this->checkoutForm->setScenario('StorePickup');
         $redirectUrl = $this->createUrl('/checkout/final');
         if ($this->checkoutForm->validate() === false) {
             $hasErrors = true;
         }
     } elseif ($addressId || $wishlistId) {
         $customerId = null;
         if ($wishlistId) {
             $wishlist = Wishlist::model()->findByPk($wishlistId);
             $addressId = $wishlist->ship_option;
             $customerId = $wishlist->customer_id;
         }
         // An existing shipping address is chosen.
         $result = $this->checkoutForm->fetchCustomerShippingAddress($addressId, $customerId);
         if ($result === false) {
             $this->redirect($this->createAbsoluteUrl("/checkout/shippingaddress"));
         }
         $this->checkoutForm->setScenario('Shipping');
         $redirectUrl = $this->createUrl('/checkout/shippingoptions');
         if ($this->checkoutForm->validate() == false) {
             $hasErrors = true;
         }
     } else {
         $wishlist = null;
         $wishlistAddress = null;
         // If any of the cart items are on a wishlist, then we show the
         // wishlist address to the user.
         foreach ($objCart->cartItems as $item) {
             if ($item->wishlist_item !== null) {
                 $wishlist = $item->wishlistItem()->registry();
                 $wishlistAddressId = $wishlist->ship_option;
                 $wishlistAddress = CustomerAddress::model()->findByPk($wishlistAddressId);
                 break;
                 // Multiple wishlist addresses are not yet supported.
             }
         }
         // Nothing was posted, just render the shipping address page.
         $this->render('shippingaddress', array('model' => $this->checkoutForm, 'error' => $this->formatErrors(), 'wishlist' => $wishlist, 'wishlistAddress' => $wishlistAddress));
         return;
     }
     // Update address ID if there are no errors.
     if ($hasErrors === false) {
         $this->checkoutForm->updateAddressId();
         // An error occurred in updateAddressId.
         if (count($this->checkoutForm->getErrors())) {
             $hasErrors = true;
         }
     }
     // A validation error occurred.
     if ($hasErrors === true) {
         $this->render('shippingaddress', array('model' => $this->checkoutForm, 'error' => $this->formatErrors()));
         return;
     }
     // Update the shipping scenarios based on the new address.
     $this->checkoutForm->saveFormToSession();
     Shipping::updateCartScenariosInSession();
     // If in-store pickup was selected we need to update the cart now
     // before moving to checkout/final. Otherwise, the address will be
     // validated at the next step and the taxes updated.
     if ($inStorePickupSelected === true) {
         // Update the shopping cart taxes.
         Yii::app()->shoppingcart->setTaxCodeByCheckoutForm($this->checkoutForm);
         // Update shipping. If in-store pickup was chosen then we need to
         // ensure the cart shipping values are updated.
         // Update shipping. If in-store pickup was chosen then we need to
         // ensure the cart shipping values are updated.
         $objShipping = CartShipping::getOrCreateCartShipping();
         if ($objShipping->hasErrors() === false) {
             $objShipping->updateShipping();
             $this->checkoutForm->addErrors($objShipping->getErrors());
         } else {
             $this->checkoutForm->addErrors($objShipping->getErrors());
         }
     }
     // Save the passed scenario and redirect to the next stage.
     $this->checkoutForm->passedScenario = $this->checkoutForm->getScenario();
     $this->redirect($redirectUrl);
 }
コード例 #4
0
ファイル: PaymentController.php プロジェクト: KaranSofat/yii
 public function actionAjaxAddress()
 {
     $rec = PaymentCustomerUser::model()->findByAttributes(array('email' => $_REQUEST['email']));
     $detail = CustomerAddress::model()->findAll(array('condition' => 'customer_id=:cId AND zipcode=:zip ', 'params' => array(':cId' => $rec->id, ':zip' => $_REQUEST['zip'])));
     foreach ($detail as $d) {
         $val[] = $d->address;
     }
     echo json_encode($val);
     exit;
 }
コード例 #5
0
 /**
  * Finds the customer's address based on his id and the address
  * id that is requested.
  * @param $userId The current user id
  * @param $addressId The address id that was selected
  * @return CustomerAddress
  */
 public static function findCustomerAddress($userId, $addressId)
 {
     return CustomerAddress::model()->find('customer_id=:customer_id AND id=:id', array(':customer_id' => $userId, ':id' => $addressId));
 }
コード例 #6
0
 /**
  * Extract shipping and billing address information, create address book and map to the carts
  */
 protected function actionConvertAddressBook()
 {
     $sql = "select * from xlsws_cart where billaddress_id IS NULL and address_bill IS NOT NULL order by id limit 500";
     $arrProducts = Yii::app()->db->createCommand($sql)->query();
     while (($result = $arrProducts->read()) !== false) {
         $result['email'] = strtolower($result['email']);
         //verify that Customer ID really exists in customer table
         $objCust = Customer::model()->findByPk($result['customer_id']);
         if (!$objCust instanceof Customer) {
             $result['customer_id'] = 0;
         }
         if (strlen($result['address_bill']) > 0) {
             $arrAddress = explode("\n", $result['address_bill']);
             if (count($arrAddress) == 5) {
                 //old format address, should be 6 pieces
                 $arrAddress[5] = $arrAddress[4];
                 $strSt = $arrAddress[3];
                 if ($strSt[0] == " ") {
                     //no state on this address
                     $arrAddress[4] = substr($strSt, 1, 100);
                     $arrAddress[3] = "";
                 } else {
                     $arrSt = explode(" ", $strSt);
                     $arrAddress[3] = $arrSt[0];
                     $arrAddress[4] = str_replace($arrSt[0] . " ", "", $strSt);
                 }
             }
             $objAddress = new CustomerAddress();
             if (count($arrAddress) >= 5) {
                 $objCountry = Country::LoadByCode($arrAddress[5]);
                 if ($objCountry) {
                     $objAddress->country_id = $objCountry->id;
                     $objState = State::LoadByCode($arrAddress[3], $objCountry->id);
                     if ($objState) {
                         $objAddress->state_id = $objState->id;
                     }
                 }
                 $objAddress->address1 = $arrAddress[0];
                 $objAddress->address2 = $arrAddress[1];
                 $objAddress->city = $arrAddress[2];
                 $objAddress->postal = $arrAddress[4];
                 $objAddress->first_name = $result['first_name'];
                 $objAddress->last_name = $result['last_name'];
                 $objAddress->company = $result['company'];
                 $objAddress->phone = $result['phone'];
                 $objAddress->residential = CustomerAddress::RESIDENTIAL;
                 $objAddress->created = $result['datetime_cre'];
                 $objAddress->modified = $result['datetime_cre'];
                 $objAddress->active = 1;
                 if (empty($objAddress->address2)) {
                     $objAddress->address2 = null;
                 }
                 if (empty($objAddress->company)) {
                     $objAddress->company = null;
                 }
                 $blnFound = false;
                 if ($result['customer_id'] > 0) {
                     //See if this is already in our database
                     $objPriorAddress = CustomerAddress::model()->findByAttributes(array('address1' => $objAddress->address1, 'address2' => $objAddress->address2, 'city' => $objAddress->city, 'postal' => $objAddress->postal, 'first_name' => $objAddress->first_name, 'last_name' => $objAddress->last_name, 'company' => $objAddress->company, 'phone' => $objAddress->phone));
                     if ($objPriorAddress instanceof CustomerAddress) {
                         Yii::app()->db->createCommand("update xlsws_cart set billaddress_id=" . $objPriorAddress->id . " where id=" . $result['id'])->execute();
                         $blnFound = true;
                     } else {
                         $objAddress->customer_id = $result['customer_id'];
                     }
                 } else {
                     //We need a shell customer record just for the email
                     $objC = Customer::model()->findByAttributes(array('email' => $result['email']));
                     if ($objC instanceof Customer) {
                         Yii::app()->db->createCommand("UPDATE xlsws_cart set customer_id=" . $objC->id . " where id=" . $result['id'])->execute();
                     } else {
                         $objC = new Customer();
                         $objC->record_type = Customer::GUEST;
                         $objC->email = $result['email'];
                         $objC->first_name = $objAddress->first_name;
                         $objC->last_name = $objAddress->last_name;
                         $objC->company = $objAddress->company;
                         if (!$objC->validate()) {
                             $arrErr = $objC->getErrors();
                             if (isset($arrErr['email'])) {
                                 $objC->email = $result['id'] . "*****@*****.**";
                             }
                             if (!$objC->validate()) {
                                 return print_r($objC->getErrors(), true);
                             }
                         }
                         if (!$objC->save()) {
                             Yii::log("Import Error " . print_r($objC->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                             return print_r($objC->getErrors(), true);
                         } else {
                             $cid = $objC->id;
                         }
                         Yii::app()->db->createCommand("UPDATE xlsws_cart set customer_id=" . $cid . " where id=" . $result['id'])->execute();
                     }
                     $result['customer_id'] = $objC->id;
                     $objAddress->customer_id = $result['customer_id'];
                 }
                 if (!$blnFound) {
                     if (!$objAddress->save()) {
                         //We have a corrupt billing address, just blank it out so import goes on
                         Yii::app()->db->createCommand("update xlsws_cart set address_bill=null where id=" . $result['id'])->execute();
                     } else {
                         $cid = $objAddress->id;
                         Yii::app()->db->createCommand("update xlsws_cart set billaddress_id=" . $cid . " where id=" . $result['id'])->execute();
                     }
                 }
             } else {
                 //We have a corrupt billing address, just blank it out so import goes on
                 Yii::app()->db->createCommand("update xlsws_cart set address_bill=null where id=" . $result['id'])->execute();
             }
             $objAddress = new CustomerAddress();
             $objCountry = Country::LoadByCode($result['ship_country']);
             if ($objCountry) {
                 $objAddress->country_id = $objCountry->id;
                 $objState = State::LoadByCode($result['ship_state'], $objCountry->id);
                 if ($objState) {
                     $objAddress->state_id = $objState->id;
                 }
             }
             $objAddress->first_name = $result['ship_firstname'];
             $objAddress->last_name = $result['ship_lastname'];
             $objAddress->company = $result['ship_company'];
             $objAddress->address1 = $result['ship_address1'];
             $objAddress->address2 = $result['ship_address2'];
             $objAddress->city = $result['ship_city'];
             $objAddress->postal = $result['ship_zip'];
             $objAddress->phone = $result['ship_phone'];
             $objAddress->residential = CustomerAddress::RESIDENTIAL;
             $objAddress->created = $result['datetime_cre'];
             $objAddress->modified = $result['datetime_cre'];
             $objAddress->active = 1;
             if (empty($objAddress->address2)) {
                 $objAddress->address2 = null;
             }
             if (empty($objAddress->company)) {
                 $objAddress->company = null;
             }
             $blnFound = false;
             if ($result['customer_id'] > 0) {
                 //See if this is already in our database
                 $objPriorAddress = CustomerAddress::model()->findByAttributes(array('address1' => $objAddress->address1, 'city' => $objAddress->city, 'postal' => $objAddress->postal, 'first_name' => $objAddress->first_name, 'last_name' => $objAddress->last_name, 'company' => $objAddress->company, 'phone' => $objAddress->phone));
                 if ($objPriorAddress instanceof CustomerAddress) {
                     Yii::app()->db->createCommand("update xlsws_cart set shipaddress_id=" . $objPriorAddress->id . " where id=" . $result['id'])->execute();
                     $blnFound = true;
                 } else {
                     $objAddress->customer_id = $result['customer_id'];
                 }
             }
             if (!$blnFound) {
                 if (!$objAddress->save()) {
                     Yii::log("Import Error " . print_r($objAddress->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 } else {
                     $cid = $objAddress->id;
                     Yii::app()->db->createCommand("update xlsws_cart set shipaddress_id=" . $cid . " where id=" . $result['id'])->execute();
                 }
             }
         }
         $objShipping = new CartShipping();
         $objShipping->shipping_method = $result['shipping_method'];
         $objShipping->shipping_module = $result['shipping_module'];
         $objShipping->shipping_data = $result['shipping_data'];
         $objShipping->shipping_cost = $result['shipping_cost'];
         $objShipping->shipping_sell = $result['shipping_sell'];
         if (!$objShipping->save()) {
             return print_r($objShipping->getErrors());
         } else {
             $cid = $objShipping->id;
         }
         Yii::app()->db->createCommand("update xlsws_cart set shipping_id=" . $cid . " where id=" . $result['id'])->execute();
         $objPayment = new CartPayment();
         $objPayment->payment_method = $result['payment_method'];
         $objPayment->payment_module = str_replace(".php", "", $result['payment_module']);
         $objPayment->payment_data = $result['payment_data'];
         $objPayment->payment_amount = $result['payment_amount'];
         $objPayment->datetime_posted = $result['datetime_posted'];
         if ($result['fk_promo_id'] > 0) {
             $objPromo = PromoCode::model()->findByPk($result['fk_promo_id']);
             if ($objPromo) {
                 $objPayment->promocode = $objPromo->code;
             }
         }
         if (!$objPayment->save()) {
             return print_r($objPayment->getErrors());
         } else {
             $cid = $objPayment->id;
         }
         Yii::app()->db->createCommand("update xlsws_cart set payment_id=" . $cid . " where id=" . $result['id'])->execute();
     }
     $results2 = Yii::app()->db->createCommand("select count(*) from xlsws_cart where billaddress_id IS NULL and address_bill IS NOT NULL")->queryScalar();
     if ($results2 == 0) {
         $remain = 8;
     } else {
         $remain = 3;
     }
     return array('result' => "success", 'makeline' => $remain, 'total' => 50, 'tag' => 'Converting cart addresses, ' . $results2 . ' remaining');
 }
コード例 #7
0
ファイル: Cart.php プロジェクト: uiDeveloper116/webstore
 public function GiftAddress()
 {
     foreach ($this->cartItems as $item) {
         if (isset($item->wishlist_item)) {
             if ($item->wishlistItem->registry->customer_id != Yii::app()->user->id && $item->wishlistItem->registry->ship_option > 0) {
                 return CustomerAddress::model()->findAllByPk($item->wishlistItem->registry->ship_option);
             }
         }
     }
     return null;
 }