Пример #1
0
 /**
  * This function returns the valid shipping states for a given country.
  *
  * Call this function with EITHER $countryType set to 'billing' or
  * 'shipping' - OR - $countryType set to something else entirely and
  * $intCountryId set to a country ID.
  *
  * If $countryType is 'billing' or 'shipping' then $countryType is used in
  * preference to $intCountryId. Otherwise $intCountryId is used. If
  * $countryType is not one of: billing, shipping; and $intCountryId is null
  * or not provided then the default country is used.
  *
  * This is not a good interface for a function but legacy view code relies on it.
  *
  * @param string $countryType Either 'billing' or 'shipping'; or some other value
  * in which case $intCountryId is used.
  * @param int|null $intCountryId An ID of a country.
  * @return CActiveRecord[] An array of States.
  */
 public function getStates($countryType = 'billing', $intCountryId = null)
 {
     if ($intCountryId === null) {
         switch ($countryType) {
             case 'billing':
                 if ($this->billingCountry !== null) {
                     $intCountryId = $this->billingCountry;
                 }
                 break;
             case 'shipping':
                 if ($this->shippingCountry !== null) {
                     $intCountryId = $this->shippingCountry;
                 }
                 break;
                 // For backwards compatibility we can't throw an error if another
                 // value is passed. Some older code (e.g.
                 // views-cities/myaccount.address.php) sends meaningless values
                 // values for $countryType to use the second parameter.
         }
     }
     if ($intCountryId === null) {
         $intCountryId = _xls_get_conf('DEFAULT_COUNTRY', 224);
     }
     return Country::getCountryShippingStates($intCountryId);
 }
 /**
  *  Get available states for a given country.
  *
  * Returns JSON with state IDs and names.
  */
 public function actionGetStates($countryId = null)
 {
     $stateList = Country::getCountryShippingStates($countryId);
     $arr = array();
     foreach ($stateList as $stateId => $stateName) {
         $arr[] = array('id' => $stateId, 'name' => $stateName);
     }
     $this->renderJSON($arr);
 }
Пример #3
0
 /**
  * Set the cart tax code based on an address.
  * The country_id parameter is required, state_id and postal are optional.
  */
 public function actionSetTaxByAddress()
 {
     $intCountryId = Yii::app()->getRequest()->getParam('country_id');
     $intStateId = Yii::app()->getRequest()->getParam('state_id', '');
     $strPostal = Yii::app()->getRequest()->getParam('postal', '');
     $objCountry = Country::Load($intCountryId);
     if ($objCountry === null) {
         throw new CHttpException(400, Yii::t('application errors', 'Invalid country_id.'));
     }
     $strStateCode = null;
     if ($intStateId !== '') {
         $objState = State::Load($intStateId);
         if ($objState === null) {
             throw new CHttpException(400, Yii::t('application errors', 'Invalid state_id.'));
         }
         // Validate the state/country combination.
         $arrShippingStates = Country::getCountryShippingStates($intCountryId);
         if (array_key_exists($intStateId, $arrShippingStates) === false) {
             throw new CHttpException(400, Yii::t('application errors', 'The state_id is not valid for the country_id.'));
         }
         $strStateCode = $objState->code;
     }
     Yii::app()->shoppingcart->setTaxCodeByAddress($objCountry->code, $strStateCode, $strPostal);
     $arrReturn['cartitems'] = $this->renderPartial('/cart/_cartitems', null, true);
     if (Yii::app()->session->get('ship.prices.cache', null) !== null) {
         $arrReturn['action'] = 'triggerCalc';
     }
     return $this->renderJSON($arrReturn);
 }