Esempio n. 1
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 public function convertAttribute($product, $entry)
 {
     $entry->cleanTaxes();
     if ($this->_taxData->getConfig()->priceIncludesTax()) {
         return $entry;
     }
     $calc = $this->calculation;
     $customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId());
     $rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId());
     $targetCountry = $this->_config->getTargetCountry($product->getStoreId());
     $ratesTotal = 0;
     foreach ($rates as $rate) {
         if ($targetCountry == $rate['country']) {
             $regions = $this->_parseRegions($rate['state'], $rate['postcode']);
             $ratesTotal += count($regions);
             if ($ratesTotal > self::RATES_MAX) {
                 throw new \Magento\Framework\Model\Exception(__("Google shopping only supports %1 tax rates per product", self::RATES_MAX));
             }
             foreach ($regions as $region) {
                 $entry->addTax(array('tax_rate' => $rate['value'] * 100, 'tax_country' => empty($rate['country']) ? '*' : $rate['country'], 'tax_region' => $region));
             }
         }
     }
     return $entry;
 }
Esempio n. 2
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 public function convertAttribute($product, $entry)
 {
     $url = $product->getProductUrl(false);
     if ($url) {
         $isStoreInUrl = $this->_scopeConfig->isSetFlag(\Magento\Store\Model\Store::XML_PATH_STORE_IN_URL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
         if (!$isStoreInUrl) {
             $urlInfo = parse_url($url);
             $store = $product->getStore()->getCode();
             if (isset($urlInfo['query']) && $urlInfo['query'] != '') {
                 $url .= '&___store=' . $store;
             } else {
                 $url .= '?___store=' . $store;
             }
         }
         $links = $entry->getLink();
         if (!is_array($links)) {
             $links = [];
         }
         $link = $entry->getService()->newLink();
         $link->setHref($url);
         $link->setRel('alternate');
         $link->setType('text/html');
         if ($product->getName()) {
             $link->setTitle($product->getName());
         }
         $links[0] = $link;
         $entry->setLink($links);
     }
     return $entry;
 }
Esempio n. 3
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 public function convertAttribute($product, $entry)
 {
     $mapValue = $this->getProductAttributeValue($product);
     $description = $this->getGroupAttributeDescription();
     if (!is_null($description) && !is_null($description->getAttributeId())) {
         $mapValue = $description->getProductAttributeValue($product);
     }
     if (!is_null($mapValue)) {
         $descrText = $mapValue;
     } elseif ($product->getDescription()) {
         $descrText = $product->getDescription();
     } else {
         $descrText = 'no description';
     }
     $descrText = $this->_gsData->cleanAtomAttribute($descrText);
     $entry->setContent($entry->getService()->newContent()->setText($descrText));
     return $entry;
 }
Esempio n. 4
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 public function convertAttribute($product, $entry)
 {
     $mapValue = $this->getProductAttributeValue($product);
     $name = $this->getGroupAttributeName();
     if (!is_null($name)) {
         $mapValue = $name->getProductAttributeValue($product);
     }
     if (!is_null($mapValue)) {
         $titleText = $mapValue;
     } elseif ($product->getName()) {
         $titleText = $product->getName();
     } else {
         $titleText = 'no title';
     }
     $titleText = $this->_googleShoppingHelper->cleanAtomAttribute($titleText);
     $entry->setTitle($entry->getService()->newTitle()->setText($titleText));
     return $entry;
 }
Esempio n. 5
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 public function convertAttribute($product, $entry)
 {
     $mapValue = $this->getProductAttributeValue($product);
     $description = $this->getGroupAttributeDescription();
     if ($description !== null && $description->getAttributeId() !== null) {
         $mapValue = $description->getProductAttributeValue($product);
     }
     if ($mapValue !== null) {
         $descrText = $mapValue;
     } elseif ($product->getDescription()) {
         $descrText = $product->getDescription();
     } else {
         $descrText = 'no description';
     }
     $descrText = $this->_googleShoppingHelper->cleanAtomAttribute($descrText);
     $entry->setContent($entry->getService()->newContent()->setText($descrText));
     return $entry;
 }
Esempio n. 6
0
 /**
  * Return item stats array based on Zend Gdata Entry object
  *
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return array
  */
 protected function _getEntryStats($entry)
 {
     $result = array();
     $expirationDate = $entry->getContentAttributeByName('expiration_date');
     if ($expirationDate instanceof \Magento\Framework\Gdata\Gshopping\Extension\Attribute) {
         $result['expires'] = $this->convertContentDateToTimestamp($expirationDate->text);
     }
     return $result;
 }
 /**
  * Insert/update attribute in the entry
  *
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @param string $name
  * @param string $type
  * @param string $value
  * @param string $unit
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 protected function _setAttribute($entry, $name, $type = self::ATTRIBUTE_TYPE_TEXT, $value = '', $unit = null)
 {
     if (is_object($value) || (string) $value != $value) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please correct the attribute "%1" type for Google Shopping. The product with this attribute hasn\'t been updated in Google Content.', $name));
     }
     $attribute = $entry->getContentAttributeByName($name);
     if ($attribute instanceof \Magento\Framework\Gdata\Gshopping\Extension\Attribute) {
         $attribute->text = (string) $value;
         $attribute->type = $type;
         if (!is_null($unit)) {
             $attribute->unit = $unit;
         }
     } else {
         $entry->addContentAttribute($name, $value, $type, $unit);
     }
     return $entry;
 }
Esempio n. 8
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  */
 public function convertAttribute($product, $entry)
 {
     $destInfo = $this->_config->getDestinationsInfo($product->getStoreId());
     $entry->setDestinationsMode($destInfo);
     return $entry;
 }
Esempio n. 9
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function convertAttribute($product, $entry)
 {
     $entry->cleanTaxes();
     if ($this->_taxData->getConfig()->priceIncludesTax()) {
         return $entry;
     }
     $defaultCustomerTaxClassId = $this->_getDefaultCustomerTaxClassId($product->getStoreId());
     $rates = $this->_taxRateManagement->getRatesByCustomerAndProductTaxClassId($defaultCustomerTaxClassId, $product->getTaxClassId());
     $targetCountry = $this->_config->getTargetCountry($product->getStoreId());
     $ratesTotal = 0;
     foreach ($rates as $rate) {
         $countryId = $rate->getTaxCountryId();
         $postcode = $rate->getTaxPostcode();
         if ($targetCountry == $countryId) {
             $regions = $this->_getRegionsByRegionId($rate->getTaxRegionId(), $postcode);
             $ratesTotal += count($regions);
             if ($ratesTotal > self::RATES_MAX) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('Google shopping only supports %1 tax rates per product', self::RATES_MAX));
             }
             foreach ($regions as $region) {
                 $adjustments = $product->getPriceInfo()->getAdjustments();
                 if (array_key_exists('tax', $adjustments)) {
                     $taxIncluded = true;
                 } else {
                     $taxIncluded = false;
                 }
                 $quoteDetailsItemDataArray = ['code' => $product->getSku(), 'type' => 'product', 'tax_class_key' => [TaxClassKeyInterface::KEY_TYPE => TaxClassKeyInterface::TYPE_ID, TaxClassKeyInterface::KEY_VALUE => $product->getTaxClassId()], 'unit_price' => $product->getPrice(), 'quantity' => 1, 'tax_included' => $taxIncluded, 'short_description' => $product->getName()];
                 $billingAddressDataArray = ['country_id' => $countryId, 'region' => ['region_id' => $rate->getTaxRegionId()], 'postcode' => $postcode];
                 $shippingAddressDataArray = ['country_id' => $countryId, 'region' => ['region_id' => $rate->getTaxRegionId()], 'postcode' => $postcode];
                 $quoteDetailsDataArray = ['billing_address' => $billingAddressDataArray, 'shipping_address' => $shippingAddressDataArray, 'customer_tax_class_key' => [TaxClassKeyInterface::KEY_TYPE => TaxClassKeyInterface::TYPE_ID, TaxClassKeyInterface::KEY_VALUE => $defaultCustomerTaxClassId], 'items' => [$quoteDetailsItemDataArray]];
                 $quoteDetailsObject = $this->_quoteDetailsFactory->create();
                 $this->dataObjectHelper->populateWithArray($quoteDetailsObject, $quoteDetailsDataArray, '\\Magento\\Tax\\Api\\Data\\QuoteDetailsInterface');
                 $taxDetails = $this->_taxCalculationService->calculateTax($quoteDetailsObject, $product->getStoreId());
                 $taxRate = $taxDetails->getTaxAmount() / $taxDetails->getSubtotal() * 100;
                 $entry->addTax(['tax_rate' => $taxRate, 'tax_country' => $countryId, 'tax_region' => $region]);
             }
         }
     }
     return $entry;
 }
Esempio n. 10
0
 /**
  * Remove attributes which were removed from mapping.
  *
  * @param Entry $entry
  * @param string[] $existAttributes
  * @return Entry
  */
 protected function _removeNonexistentAttributes($entry, $existAttributes)
 {
     // attributes which can't be removed
     $ignoredAttributes = ["id", "image_link", "content_language", "target_country", "expiration_date", "adult"];
     $contentAttributes = $entry->getContentAttributes();
     foreach ($contentAttributes as $contentAttribute) {
         $name = $this->_googleShoppingHelper->normalizeName($contentAttribute->getName());
         if (!in_array($name, $ignoredAttributes) && !in_array($existAttributes, $existAttributes)) {
             $entry->removeContentAttribute($name);
         }
     }
     return $entry;
 }