Magento World

As a Magento parner, we are very honoured to offer you the best Magento Extensions, Magento Modules, Magento Themes and Magento Templates. You will get full support until you feel satisfied! View our Magento page to find what you need!

Thứ Sáu, 23 tháng 3, 2012

Products In Google (Updated)

After many a month on the Blog we’ve decided to re-launch the Google Base script with a few changes – compiling most of the comments that were recieved on the old one. There is another script on the web that is a lot like this one but I don’t think it has been edited at all recently for the changes to Magento – and in any case I cannot find it again – I would credit the start of this script with whoever wrote the original one when I find out your name.

In order to make the most out of this service please follow these steps:

Install this script and run itFollow the Setting Up Cron Tutorial (Making sure you schedule your gproducts script)Follow the Google Scheduling TutorialSit back and relax – no actually start making product and watch as they magically appear on Google!

Now to install this script simply perform the following:

Create a directory on your root called “export” and then create 2 files to put in there:

Make sure that your folder has enough permissions on it as well as those 2 files (to make sure just make them 777 or 775).

Inside your gbase.php file paste the following:

loadArea(Mage_Core_Model_App_Area::AREA_FRONTEND); // fix for catalog price rulestry {$handle = fopen(SAVE_FEED_LOCATION, 'w');$heading = array('id','mpn','title','description','link','image_link','price','brand','product_type','condition', 'availability', 'google_product_category');$feed_line= implode("\t", $heading)."\r\n";fwrite($handle, $feed_line);$products = Mage::getModel('catalog/product')->getCollection();$products->addAttributeToFilter('status', 1);$products->addAttributeToFilter('visibility', 4);$products->addAttributeToSelect('sku');$products->addAttributeToSelect('name');$products->addAttributeToSelect('description');$products->addAttributeToSelect('short_description');$products->addAttributeToSelect('url');$products->addAttributeToSelect('image');$products->addAttributeToSelect('price');$products->addAttributeToSelect('special_price');$products->addAttributeToSelect('manufacturer');$products->addAttributeToSelect('category_ids');$count = count($products);echo "Writing $count Products
";foreach($products as $product) {$product_data = array();$product_data['sku'] = $product->getSku();$product_data['mpn'] = $product->getSku(); // Thanks to jennifer for this$product_data['title'] = $product->getName();$description = str_replace('

 

','',$product->getDescription());if($description == "" || empty($description) || !$description){echo "short
";$product_data['description'] = str_replace('

 

','',iconv("UTF-8","UTF-8//IGNORE",$product->getShortDescription()));} else {echo "long
";$product_data['description'] = iconv("UTF-8","UTF-8//IGNORE",$description); // removes most the utf8 errors (doesnt like row if empty too!)}//$product_data['Deeplink'] = "http://".$_SERVER['HTTP_HOST']."/".$product->getUrlPath(); // thanks to hamish for this$product_data['Deeplink'] = $product->getProductUrl(); // thanks to webmaster128 for this one$product_data['image_link'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();if($product->getSpecialPrice() != NULL){ // update to check for special price or discount$product_data['price'] = round($product->getSpecialPrice(),2);} else {$product_data['price'] = round($product->getPrice(),2);}$brand = $product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($product);if($brand != "No"){$product_data['brand'] = $product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($product);} else {if(Mage::app()->getStore()->getName() == "Default Store View"){$product_data['brand'] = $product->getName();} else {$product_data['brand'] = Mage::app()->getStore()->getName();}}$product_data['product_type'] = '';$product_data['condition'] = "new";$product_data['availability'] = "In Stock"; // thanks to jennifer for thisforeach($product->getCategoryIds() as $_categoryId){$category = Mage::getModel('catalog/category')->load($_categoryId);$product_data['product_type'] .= $category->getName().', ';}$product_data['product_type'] = rtrim($product_data['product_type'],', ');echo "Added Successfully ".$product->getName()." (".$product_data["sku"].")
";$thecat = "";$product_data["google_product_category"] = $thecat;foreach($product_data as $k=>$val){$bad=array('"',"\r\n","\n","\r","\t");$good=array(""," "," "," ","");$product_data[$k] = '"'.str_replace($bad,$good,$val).'"';}$feed_line = implode("\t", $product_data)."\r\n";fwrite($handle, $feed_line);fflush($handle);}fclose($handle);}catch(Exception $e){die($e->getMessage());}

Now as long as you have followed all the steps above you should have a working google base script that automatically updates – check your google_feed.txt to see if it is populated.

As this script will no doubt keep being refinied I’ll let you all know now that any changes made will be edited in the script above – with a date of when the update was performed – so please any comments/amendments are welcome!

Thanks for visiting the Magento Blog here at E-commerce Web Design.

Robert Kent Author Page


View the original article here

Không có nhận xét nào:

Đăng nhận xét