示例#1
0
 /**
  * Find the tax code associated with the provided address and update the
  * shopping cart to use it.
  *
  * When the shipping country is empty, the Store Default tax code is used.
  * This is generally used before an address is entered and for store
  * pickup.
  *
  * If the provided address is not matched to any destination, the tax code
  * for ANY/ANY is used.
  *
  * @param mixed $shippingCountry The 2-letter country code for the country or the country ID.
  * @param mixed $shippingState The 2-letter code for the state or the state ID.
  * @param string $shippingPostal The postal code with all spaces removed.
  * @return void
  * @throws CException If tax destinations are not configured.
  */
 public function setTaxCodeByAddress($shippingCountry, $shippingState, $shippingPostal)
 {
     $previousTaxCodeId = $this->getModel()->tax_code_id;
     $taxCode = TaxCode::getTaxCodeByAddress($shippingCountry, $shippingState, $shippingPostal);
     $newTaxCodeId = $taxCode->lsid;
     $this->setTaxCodeId($newTaxCodeId);
     // Validate the promo code after saving, since recalculating updates
     // the cart item prices and may invalidate a promo code based on its
     // threshold.
     $this->recalculateAndSave();
     $this->revalidatePromoCode();
     // In a tax inclusive environment there can only be 2 tax codes.
     // Changing tax code means we've gone from tax-inclusive to
     // tax-exclusive or vice versa. This implies that the price display has
     // changed.
     // TODO: Is this always true? What if tax_code_id was null?
     if (CPropertyValue::ensureBoolean(_xls_get_conf('TAX_INCLUSIVE_PRICING')) == 1 && $previousTaxCodeId !== $newTaxCodeId) {
         Yii::app()->user->setFlash('taxModeChange', Yii::t('checkout', 'Prices have changed based on your tax locale.'));
     }
 }
示例#2
0
 /**
  * Update the cart's taxcode based on the current customer's
  * default shipping destination, or on the ANY/ANY destination
  * if the customer doesn't have a default shipping address
  * configured.
  *
  * @throws CHttpException From @see TaxCode::getTaxCodeByAddress when Web
  * Store is not configured correctly.
  */
 public function setTaxCodeByDefaultShippingAddress()
 {
     if (is_null($this->customer_id)) {
         return;
     }
     $objCustomer = $this->customer;
     if ($objCustomer instanceof Customer === false) {
         return;
     }
     $country = null;
     $state = null;
     $postal = null;
     if (isset($objCustomer->defaultShipping)) {
         $country = $objCustomer->defaultShipping->country;
         $state = $objCustomer->defaultShipping->state;
         $postal = $objCustomer->defaultShipping->postal;
     }
     $taxcode = TaxCode::getTaxCodeByAddress($country, $state, $postal);
     $this->tax_code_id = $taxcode->lsid;
     if ($this->item_count > 0) {
         $this->recalculateAndSave();
     }
 }