예제 #1
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Google_Service_ShoppingContent_Product $shoppingProduct
  * @return Google_Service_ShoppingContent_Product
  */
 public function convertAttribute($product, $shoppingProduct)
 {
     if (Mage::helper('tax')->getConfig()->priceIncludesTax()) {
         return $shoppingProduct;
     }
     $calc = Mage::helper('tax')->getCalculator();
     $customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId());
     $rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId());
     $targetCountry = Mage::getSingleton('googleshoppingapi/config')->getTargetCountry($product->getStoreId());
     $ratesTotal = 0;
     $taxes = array();
     foreach ($rates as $rate) {
         if ($targetCountry == $rate['country']) {
             $regions = $this->_parseRegions($rate['state'], $rate['postcode']);
             $ratesTotal += count($regions);
             if ($ratesTotal > self::RATES_MAX) {
                 Mage::throwException(Mage::helper('googleshoppingapi')->__("Google shopping only supports %d tax rates per product", self::RATES_MAX));
             }
             foreach ($regions as $region) {
                 $taxes[] = array('country' => empty($rate['country']) ? '*' : $rate['country'], 'region' => $region, 'rate' => $rate['value'] * 100, 'taxShip' => true);
             }
         }
     }
     $shoppingProduct->setTaxes($taxes);
     return $shoppingProduct;
 }