私はmagentoとphpオブジェクトが初めてですが、ルートに単純なphpファイルを作成して、SKU、製品名、および最初の4つの基本画像のURLをcsvにエクスポートする必要があります。残念ながら、img の URL が見つからず、機能する例が見つかりません (「SOMETHING MISSING HERE」テキストの後に問題があります)。
<?php
header('Content-Type: text/html; charset=utf-8');
require 'app/Mage.php';
Mage::app("default");
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*') // all attributes
->addAttributeToFilter('exportornot', 'yes') // custom attribute filter
->addAttributeToFilter('status', 1);//enabled
$fp = fopen('feed.csv', 'w');//open csv file
//-----------------------------MAKE CSV HEADER------------------------------
$csvheader = array(
'title',
'sku',
'photo_url_1',
'photo_url_2',
'photo_url_3',
'photo_url_4',
'category',
'product_url',
'description'
);
fputcsv($fp, $csvheader, $delimiter = ",");//write to the csv header
//-----------------------------MAKE CATEGORY ------------------------------
foreach ($collection as $product) {
$fcmCathegoryPath="";
foreach ($product->getCategoryIds() as $category_id) {
$category = Mage::getModel('catalog/category')->load($category_id);
$fcmCathegoryPath.=$category->getName();
}
//-----------------------------MAKE IMAGE VARIABLES------------------------------
$_gallery = Mage::getModel('catalog/product')->load(
$product->getId())->getMediaGalleryImages();
$imgCount = Mage::getModel('catalog/product')->load(
$product->getId())->getMediaGalleryImages()->count();
if($imgCount >1){
foreach ($_gallery as $_image ){
/*
SOMETHING MISSING HERE
for example:
put the first image url to the first variable
$photo_url_1 = $_image->getFile()
and so on
*/
}
//-----------------------------MAKE CSV CONTENT-----------------------------
fcmFeedContent=array( //put the things to the array
$product->getName(),//title
$product->getSku(),//seller_product_id
$photo_url_1,
$photo_url_2,
$photo_url_3,
$photo_url_4,
$fcmCathegoryPath,
'http://mysite.com/'.$product->getUrlPath(),
$product->getDescription()
);
fputcsv($fp, fcmFeedContent, $delimiter = ",");//write to the csv
}
fclose($fp);
?>