Last active
May 14, 2018 09:33
-
-
Save enru/93b08941850bb82831a5 to your computer and use it in GitHub Desktop.
magento google simple shopping configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- Basic Product Information --> | |
| <? | |
| // only use products with enabled parents | |
| $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId()); | |
| if(isset($parentIds[0])) { | |
| $status = Mage::getResourceModel('catalog/product')->getAttributeRawValue($parentIds[0], 'status', 1); | |
| if($status != 1) $myPattern=null; | |
| } | |
| ?> | |
| <g:id><? return substr($product->getId(), 0, 50); ?></g:id> | |
| <g:title>{feed_name parent,[substr],[70],[...]}</g:title> | |
| <g:description><? | |
| $desc = $product->getDescription(); | |
| $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId()); | |
| if(isset($parentIds[0])) { | |
| $desc = Mage::getResourceModel('catalog/product')->getAttributeRawValue($parentIds[0], 'description', 1); | |
| } | |
| $desc = strip_tags(html_entity_decode($desc)); | |
| $desc = preg_replace("/[\r\n]{2,}/", " ", $desc); | |
| $desc = iconv("utf-8", "utf-8//ignore", $desc); | |
| if(strlen($desc > 4999)) $desc = substr($desc, 0, 4997) . "..."; | |
| return $desc; | |
| ?></g:description> | |
| <g:google_product_category>{category_mapping parent,[0]}</g:google_product_category> | |
| <g:product_type>{categories parent, [1], [2], [1]}</g:product_type> | |
| <!--g:link>{url parent,[substr],[2000]}</g:link--> | |
| <g:link> | |
| <? | |
| /* suit products have bundle value attributes */ | |
| $bundleValue = Mage::getResourceModel('catalog/product')->getAttributeRawValue($product->getId(), 'bundle_value', 1); | |
| if($bundleValue) { | |
| return '{url parent,[substr],[2000]}'; | |
| } | |
| else { | |
| $url = $product->setStoreId(1)->getProductUrl(); | |
| $urlHash = array(); | |
| $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId()); | |
| /* | |
| if(isset($parentIds[0])) { | |
| $parent = Mage::getModel('catalog/product')->setStoreId(1)->load($parentIds[0]); | |
| $url = $parent->setStoreId(1)->getProductUrl(); | |
| $attrs = $parent->getTypeInstance(true)->getConfigurableAttributes($parent); | |
| foreach ($attrs as $attribute) { | |
| $productAttribute = $attribute->getProductAttribute(); | |
| $productAttributeId = $productAttribute->getId(); | |
| if($attributeValue = $product->getData($productAttribute->getAttributeCode())) { | |
| $urlHash[$productAttributeId] = $attributeValue; | |
| } | |
| } | |
| } | |
| */ | |
| if(isset($parentIds[0])) { | |
| $rewrite = Mage::getModel('core/url_rewrite'); | |
| $idPath = 'product/'.$parentIds[0]; | |
| $rewrite->loadByIdPath($idPath); | |
| $parentUrl = Mage::getUrl('', array('_direct' => $rewrite->getRequestPath(), '_current' => false, '_store' => 1)); | |
| $url = ($parentUrl ? $parentUrl : $url); | |
| } | |
| if(count($urlHash) > 0) { | |
| $url .= '#'.http_build_query($urlHash); | |
| } | |
| return substr($url, 0, 2000); | |
| } | |
| ?> | |
| </g:link> | |
| <g:image_link>{image parent,[0],[substr],[2000]}</g:image_link> | |
| <g:condition>new</g:condition> | |
| <!-- Availability & Price --> | |
| <g:availability>{is_in_stock?[in stock]:[out of stock]:[out of stock]}</g:availability> | |
| <g:price>{normal_price,[GBR],[0.00]GBR}</g:price> | |
| {G:SALE_PRICE,[GBR],[0.00]} | |
| <!-- Unique Product Identifiers--> | |
| <g:brand>{manufacturer parent,[substr],[70]}</g:brand> | |
| <g:gtin>{barcode_ean_gtin,[substr],[50]}</g:gtin> | |
| <g:mpn>{manufacturer_code parent,[substr],[70]}</g:mpn> | |
| <g:identifier_exists><? | |
| $identifier_exists = "true"; | |
| $gtin = $product->getData('barcode_ean_gtin'); | |
| /* | |
| $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId()); | |
| $brand = Mage::getResourceModel('catalog/product')->getAttributeRawValue($parentIds[0], 'manufacturer', 1); | |
| $mpn = Mage::getResourceModel('catalog/product')->getAttributeRawValue($parentIds[0], 'manufacturer_code', 1); | |
| if(strlen($brand)) { | |
| if(strlen($gtin) < 1 && strlen($mpn) < 1) { | |
| $identifier_exists = "false"; | |
| } | |
| } | |
| else { | |
| $identifier_exists = "false"; | |
| } | |
| if(strtolower($mpn) == "false") { $identifier_exists = "false"; } | |
| */ | |
| if(strtolower($gtin) == "false") { $identifier_exists = "false"; } | |
| return $identifier_exists; | |
| ?></g:identifier_exists> | |
| <!-- Apparel Products --> | |
| <g:gender>male</g:gender> | |
| <g:age_group>adult</g:age_group> | |
| <!-- color and size --> | |
| <g:size_system>UK</g:size_system> | |
| <g:size_type>Big and Tall</g:size_type> | |
| <g:size>{topsize,[substr],[100]}{waist,[substr],[100]}{shoesize,[substr],[100]}{shirtcollar,[substr],[100]} {size_modifier}</g:size> | |
| <g:color>{color parent,[substr],[100]}</g:color> | |
| <!-- Product Variants --> | |
| <g:item_group_id><? | |
| $groupId = null; | |
| if($product->getTypeId() == 'simple'){ | |
| $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId()); | |
| if(isset($parentIds[0])) $groupId = $parentIds[0]; | |
| } | |
| return substr("$groupId", 0, 50); | |
| ?></g:item_group_id> | |
| <g:material>{material parent,[substr],[200]}</g:material> | |
| <g:pattern>{pattern parent,[substr],[100]}</g:pattern> | |
| <!-- Shipping --> | |
| <g:shipping_weight>{weight parent,[float],[2]} kg</g:shipping_weight> | |
| <!-- AdWords attributes --> | |
| <g:adwords_grouping>{adwords_grouping parent}</g:adwords_grouping> | |
| <g:adwords_labels>{adwords_labels parent}</g:adwords_labels> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment