我正在尝试构建CSV格式的产品Feed(Magento community v1.7)但是我在提取某些数据时遇到了一些麻烦。我不介意共享代码所以它如下所示,如果有人能让我知道我可以使用获取某些我无法提取的产品值,我将非常感激。
我想提取:(我怎样才能获得下面的值)
define('SAVE_FEED_LOCATION','productfeed.csv');
$objDateTime = new DateTime('NOW');
require 'app/Mage.php';
Mage::app('default');
try{
$handle = fopen(SAVE_FEED_LOCATION, 'w');
$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToFilter('status', 1); //1 is set to select product in stock
$products->addAttributeToFilter('visibility', 4); //4 is set to select active products
$products->addAttributeToSelect('*');
$prodIds=$products->getAllIds();
$product = Mage::getModel('catalog/product');
$counter = 0;
foreach($prodIds as $productId) {
if (++$counter < 50000){
$product->load($productId);
$title_temp = $product->getName();
if (strlen($title_temp) > 255){
$title_temp = str_replace("Supply", "", $title_temp);
$title_temp = str_replace(" ", " ", $title_temp);
} //$title_temp will hold the product name
$maincat = $subcats = '';
$cats = $product->getCategoryIds();
//$eee = implode(",",$cats);
foreach ($cats as $category_id) {
$_cat = Mage::getModel('catalog/category')->load($category_id) ;
if($subcats == ''){
$maincat = $subcats = $_cat->getName();
}else {
$subcats .= ">".$_cat->getName();
}
} //creating and setting parent category and other categories
$product_data = array();
$product_data['ProductID'] = $productId;
$product_data['ProductName'] = substr(iconv("UTF-8","UTF-8//IGNORE",$title_temp), 0, 255);
$product_data['SKUnumber'] = $product->getSku();
$product_data['PrimaryCategory'] = $maincat; //this is spitting same data for all products
$product_data['SecondaryCategory'] = $subcats; //this is spitting same data for all products
$product_data['ProductURL'] = $StoreURL.$product->getUrlPath(); //$StroeURL is set as a string
$product_data['ProductImageURL'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();
$product_data['ShortProductDescription'] = substr(iconv("UTF-8","UTF-8//IGNORE",$product->getDescription()), 0, 80)."...";
$product_data['LongProductDescription'] = substr(iconv("UTF-8","UTF-8//IGNORE",$product->getDescription()), 0, 2000);
$product_data['SalePrice'] = round($product->getFinalPrice(),2); this need to be checked result not as expected
$product_data['RetailPrice'] = round($product->getPrice(),2);
$product_data['Brand'] = $product->getData('brand'); //not working
$product_data['ManufacturerPartNumber'] = ''; //need variable
$product_data['ManufacturerName'] = $product_data['manufacturer']; //not working
$product_data['Quantity'] = ''; //need variable
$product_data['UniversalProductCode'] = $product->getData('upc'); //need variable
$product_data['Currency'] = Mage::app()->getStore()->getCurrentCurrencyCode();
$product_data['Sizes']= '';
$product_data['Colours']= '';
$product_data['Gender']= '';
foreach($product_data as $k=>$val){
$bad=array('"',"\r\n","\n","\r","\t");
$good=array(""," "," "," ","");
$product_data[$k] = str_replace($bad,$good,$val);
}
echo $counter . " ";
$feed_line = implode("|", $product_data)."\r\n";
fwrite($handle, $feed_line);
fflush($handle);
}
}
fclose($handle);
}