2

What script i have to write to create a CSV for reading google in magento?

  • please do add some more information, what you want to do with csv ? – Khushbu_sipl Apr 27 '17 at 12:53
1

If you have development background you can use this but you will need to modify it a littile bit

<?php
define('SAVE_FEED_LOCATION','/googlebase/google_base_feed_04.txt');//you can set a new folder and file if you want, don't forget to chmod the folder to 777

// make sure we don't time out
set_time_limit(0);

require_once '/app/Mage.php';
Mage::app();


// start 
try {

    // Open File
    $handle = fopen(SAVE_FEED_LOCATION, 'w');
    $heading = array('id','mpn','title','description','link','image_link','price','sale price', 'brand','google_product_category','product_type','condition','weight', 'shipping','availability' ); 
    $feed_line=implode("\t", $heading)."\r\n";
    fwrite($handle, $feed_line);

    // Get Product Collection 
    $products = Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToFilter('status', 1)
            ->addAttributeToFilter('visibility', 4)
            ->addAttributeToSelect('*');

    $products->joinField('is_in_stock',
                'cataloginventory/stock_item',
                'is_in_stock',
                'product_id=entity_id',
                'is_in_stock=1',
                '{{table}}.stock_id=1',
                'left'); 

    foreach ($products as $product) :

        $product_data['id'] = $product->getId();
        $product_data['mbn'] = $product->getSku();
        $product_data['title'] = $product->getName();
        $desc = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($product->getShortDescription()))))));
        $product_data['description'] = $desc; 


        $product_data['link'] = $product->getProductUrl();
        $product_data['image_link'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();

        $product_data['price']=round($product->getPrice(), 2) . 'GBP';
        $product_data['sale_price']=round($product->getFinalPrice(), 2) . ' GBP';
        $product_data['brand']=$product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($product);
        $product_data['google_product_category']="add your category - or you can call it from attibute";
        $product_data['product_type']="add your category - or you can call it from attibute";
        $product_data['condition']=$product->getCondition()?$product->getCondition():"new";
        $product_data['weight'] = $product->getWeight();
        $product_data['shipping']="GB::Ground:0.00";
        $product_data['availability']="in stock";

        $feed_line = implode("\t", $product_data)."\r\n";

        fwrite($handle, $feed_line);
        fflush($handle);

    endforeach;


    //---------------------- WRITE THE FEED
    fclose($handle);

    $end_time = microtime(true);

    $time = $end_time - $start_time;

    echo "Done in $time seconds. ";
    echo "<br/>Memory Usage: ". memory_get_usage(false). " bytes";



} catch(Exception $e) {
    die($e->getMessage());
}

If you after a module I suggest you look at https://www.wyomind.com/google-shopping-magento.html very good and it is working for me on different sites

  • thanks i create this now i want to set this in cron i have no idea about corn what i do? – uber Apr 28 '17 at 7:17
  • what control panel you have? plesk or cpanel? – Ahmed Elawadi Apr 28 '17 at 10:13
  • cpanel is my host – uber Apr 28 '17 at 10:32
  • Please follow this magento.stackexchange.com/questions/8012/… – Ahmed Elawadi Apr 28 '17 at 10:34
  • thanks my question is that i have create catalog.php script which create product csv now i want to run this using cron – uber Apr 28 '17 at 10:36
1

Please read good article http://inchoo.net/magento/adding-magento-products-to-google-base/

You can also use ready extensions https://www.magentocommerce.com/magento-connect/catalogsearch/result/?q=google+feed&pl=0

Not the answer you're looking for? Browse other questions tagged or ask your own question.