Magento:产品饲料的产品数据提取

时间:2013-07-30 20:40:49

标签: php magento-1.7 feed feeds

我正在尝试构建CSV格式的产品Feed(Magento community v1.7)但是我在提取某些数据时遇到了一些麻烦。我不介意共享代码所以它如下所示,如果有人能让我知道我可以使用获取某些我无法提取的产品值,我将非常感激。

我想提取:(我怎样才能获得下面的值)

  1. 产品类别(我能够提取数组,但它们的值与列出的类别产品不一致,即整个列表具有相同的类别)
  2. 产品的带(文本格式)
  3. 产品制造商(文字格式)
  4. 制造商部件号
  5. 可用数量
  6. UPC
  7. 小图片网址(不是缓存网址)
  8. 缩略图图片网址(不是缓存网址)
  9. 产品的尺寸(数组或字符串格式)
  10. 产品的颜色(数组或字符串格式)
  11. 性别(如果已分配)
  12. 我正在使用的代码如下

    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);
    }
    

0 个答案:

没有答案