/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Varien_Gdata_Gshopping_Entry $entry * @return Varien_Gdata_Gshopping_Entry */ public function convertAttribute($product, $entry) { $entry->cleanTaxes(); if (Mage::helper('tax')->getConfig()->priceIncludesTax()) { return $entry; } $calc = Mage::helper('tax')->getCalculator(); $customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId()); $rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId()); $targetCountry = Mage::getSingleton('googleshopping/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) { Mage::throwException(Mage::helper('googleshopping')->__("Google shopping only supports %d 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; }
/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Varien_Gdata_Gshopping_Entry $entry * @return Varien_Gdata_Gshopping_Entry */ public function convertAttribute($product, $entry) { $url = $product->getProductUrl(false); if ($url) { if (!Mage::getStoreConfigFlag('web/url/use_store')) { $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 = array(); } $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; }
/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Varien_Gdata_Gshopping_Entry $entry * @return Varien_Gdata_Gshopping_Entry */ public function convertAttribute($product, $entry) { $entry->cleanTaxes(); if (Mage::helper('Mage_Tax_Helper_Data')->getConfig()->priceIncludesTax()) { return $entry; } $calc = Mage::helper('Mage_Tax_Helper_Data')->getCalculator(); $customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId()); $rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId()); $targetCountry = Mage::getSingleton('Mage_GoogleShopping_Model_Config')->getTargetCountry($product->getStoreId()); foreach ($rates as $rate) { if ($targetCountry == $rate['country']) { $entry->addTax(array('tax_rate' => $rate['value'] * 100, 'tax_country' => empty($rate['country']) ? '*' : $rate['country'], 'tax_region' => empty($rate['state']) ? '*' : $rate['state'])); } } return $entry; }
/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Varien_Gdata_Gshopping_Entry $entry * @return Varien_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 = Mage::helper('googleshopping')->cleanAtomAttribute($titleText); $entry->setTitle($entry->getService()->newTitle()->setText($titleText)); return $entry; }
/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Varien_Gdata_Gshopping_Entry $entry * @return Varien_Gdata_Gshopping_Entry */ public function convertAttribute($product, $entry) { $mapValue = $this->getProductAttributeValue($product); $description = $this->getGroupAttributeDescription(); if (!is_null($description)) { $mapValue = $description->getProductAttributeValue($product); } if (!is_null($mapValue)) { $descrText = $mapValue; } elseif ($product->getDescription()) { $descrText = $product->getDescription(); } else { $descrText = 'no description'; } $descrText = Mage::helper('googleshopping')->cleanAtomAttribute($descrText); $entry->setContent($entry->getService()->newContent()->setText($descrText)); return $entry; }
/** * Remove attributes which were removed from mapping. * * @param Varien_Gdata_Gshopping_Entry $entry * @param array $existAttributes * @return Varien_Gdata_Gshopping_Entry */ protected function _removeNonexistentAttributes($entry, $existAttributes) { // attributes which can't be removed $ignoredAttributes = array("id", "image_link", "content_language", "target_country", "expiration_date", "adult"); $contentAttributes = $entry->getContentAttributes(); foreach ($contentAttributes as $contentAttribute) { $name = Mage::helper('Mage_GoogleShopping_Helper_Data')->normalizeName($contentAttribute->getName()); if (!in_array($name, $ignoredAttributes) && !in_array($existAttributes, $existAttributes)) { $entry->removeContentAttribute($name); } } return $entry; }
/** * Return item stats array based on Zend Gdata Entry object * * @param Varien_Gdata_Gshopping_Entry $entry * @return array */ protected function _getEntryStats($entry) { $result = array(); $expirationDate = $entry->getContentAttributeByName('expiration_date'); if ($expirationDate instanceof Varien_Gdata_Gshopping_Extension_Attribute) { $result['expires'] = $this->convertContentDateToTimestamp($expirationDate->text); } return $result; }
/** * Delete an entry * * @param Varien_Gdata_Gshopping_Entry $entry The Content entry to remove * @param boolean $dryRun Flag for the 'dry-run' parameter * @return Varien_Gdata_Gshopping_Content Implements fluent interface */ public function deleteItem(Varien_Gdata_Gshopping_Entry $entry, $dryRun = false) { $entry->delete($dryRun); return $this; }
/** * Set current attribute to entry (for specified product) * * @param Mage_Catalog_Model_Product $product * @param Varien_Gdata_Gshopping_Entry $entry * @return Varien_Gdata_Gshopping_Entry */ public function convertAttribute($product, $entry) { $destInfo = Mage::getSingleton('googleshopping/config')->getDestinationsInfo($product->getStoreId()); $entry->setDestinationsMode($destInfo); return $entry; }
/** * Insert/update attribute in the entry * * @param Varien_Gdata_Gshopping_Entry $entry * @param string $name * @param string $type * @param string $value * @param string $unit * @return Varien_Gdata_Gshopping_Entry */ protected function _setAttribute($entry, $name, $type = self::ATTRIBUTE_TYPE_TEXT, $value = '', $unit = null) { if (is_object($value) || (string) $value != $value) { Mage::throwException(Mage::helper('googleshopping')->__('The attribute "%s" has incorrect type for Google Shopping. The product with this attribute hasn\'t been updated in Google Content.', $name)); } $attribute = $entry->getContentAttributeByName($name); if ($attribute instanceof Varien_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; }