Strona główna forum Wsparcie Konfiguracja Eksport produktów do Google Merchant Center

Eksport produktów do Google Merchant Center

Wszystko o konfiguracji, możliwościach i ustawieniach...


Posty: 13
Gadu-Gadu: 0

Witam!
Mam problem. Chciałbym podłączyć sklep magento z Google Merchant Center, ale mam z mały problem z eksportem produktów. Znalazłem skrypt który ma to robić.

<?php // Code updated 31/01/2014
 
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
 
function flush_buffers(){
ob_end_flush();
ob_flush();
flush();
ob_start();
}
 
define('SAVE_FEED_LOCATION','google_simple.txt');
set_time_limit(0);
require_once '../app/Mage.php'; // get our magento connection from the app folder
Mage::app(); // or use Mage::app('default'); for eariler versions of magento
Mage::app()->loadArea(Mage_Core_Model_App_Area::AREA_FRONTEND); // fix for catalog price rules
try {
$handle = fopen(SAVE_FEED_LOCATION, 'w');
$heading = array('id','numer MPN','tytuł','opis','link','link do zdjęcia','cena','marka','typ produktu','stan dostępność','kategoria produktów google');
$feed_line= implode("\t", $heading)."\r\n";
$categories=array(7,8);
fwrite($handle, $feed_line);
$products = Mage::getModel('catalog/product')->getCollection();
$products->joinField(
    'qty',
    'cataloginventory/stock_item',
    'qty',
    'product_id=entity_id',
    '{{table}}.stock_id=1',
    'left'
);
$products->addAttributeToFilter('qty', array('neq' => 0));
$products->addAttributeToFilter('type_id','simple');
$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->addAttributeToFilter('price');
$products->addAttributeToSelect('special_price');
$products->addAttributeToSelect('manufacturer');
$products->joinField('category_id',
    'catalog/category_product',
    'category_id',
    'product_id=entity_id',
    null,
    'left'
);
$products->addAttributeToFilter('category_id', array('in' => array(27,28)));
 
$count = count($products);
echo "Writing $count Products<br/>";
 
foreach($products as $product) {
$product_data = array();
 
$product_data['sku'] = $product->getSku();
 
$product_data['mpn'] = $product->getSku(); // Thanks to jennifer for this
//$product_data['qty'] = $product->getQty();
$product_data['title'] = $product->getName();
$description = str_replace('<p>&#160;</p>','',$product->getDescription());
if($description == "" || empty($description) || !$description){
echo "short<br/>";
$product_data['description'] = str_replace('<p>&#160;</p>','',iconv("UTF-8","UTF-8//IGNORE",$product->getShortDescription()));
} else {
echo "long<br/>";
$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 <cite>webmaster128 for this one</cite>
$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).'PLN';
} else {
$product_data['price'] = round($product->getPrice(),2).'PLN';
}
 
$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'] = 'nowy';
$product_data['availability'] = 'w magazynie'; // thanks to jennifer for this
 
foreach($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"].")<br/>";
 
$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());
}


Zrobiłem [prawdopodobnie] tak jak w instrukcji, czyli stworzyłem plik eksport.php, wgrałem go do nowo utworzonego katalogu eksport, ustawiłem prawa do pliku i tegoż katalogu na pełne (777) i poszedłem na stronę http://(mojastrona).pl/eksport/eksport.php [(mojastrona) to moja domena oczywiscie :) ] i wyskoczył mi komunikat:

Writing 0 Products


i pojawił sie nowy pusty plik txt w folderze.

Dodam jeszcze, że w orginale było:

$products->addAttributeToFilter('category_id', array('in' => array(1,2,3)));


Jednak było tam napisane, że zamiast 1,2,3 trzeba dać id swojej kategorii produktów.

Nie wiem czy ja robie coś źle, czy ten kod jest zły.

Pozdrawiam,
Krzysiek

Eksport produktów do Google Merchant Center

PostTeraz jest 25 sie 2019, o 08:56
Google

Posty: 427
Lokalizacja: Internet

Powrót do Konfiguracja



cron