1

Magento DB に問題があり、カスタム製品のエクスポート ファイルの属性を一致させることができません。

属性を取得するには助けが必要です。このスクリプトはこのヘッダーだけで終了しましたが、attribute_set、visibility、size_cloth は名前ではなく数値を返しています。おそらく、これは match 関数で解決できます。

より多くの属性を取得する必要があります。たとえば、category_ids、これを取得できません... color、size_shoes、size_etc.

私のスクリプトを確認してください。

'store', '_website', 'attribute_set', 'type', 'sku', 'name', 'description', 'short_description', 'visibility', 'has_option', 'price', 'special_price', 'size_cloth', 'link', 'image'



<?php

    //Setup Connection information
    $dbhost = 'localhost';
    $dbuser = 'user';
    $dbpass = 'pass';

    //Connect to the database
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');

    //Point to specific DB
    $dbname = 'database_name';
    mysql_select_db($dbname);

    //Create the Query to get the products
    $sql = "SELECT DISTINCT P.attribute_set_id, P.type_id, P.sku, P.has_options, V.value AS Name, T1.value AS ProdDesc, T2.value AS ShortDesc,
    T5.value AS visibility, D.value AS Price, S.value AS Special_Price, SIZE_CLOTH.value AS size_cloth, CONCAT('http://www.website.com/', V1.value) AS Link, 
    CASE
        WHEN V2.Value IS NULL
            THEN NULL
        ELSE CONCAT('http://www.website.com/media/catalog/product', V2.value)
    END AS Image
    FROM  catalog_product_entity AS P INNER JOIN

    catalog_product_entity_varchar AS V  ON P.entity_id = V.entity_id  AND V.attribute_id  = 60  LEFT JOIN
    catalog_product_entity_varchar AS V1 ON P.entity_id = V1.entity_id AND V1.attribute_id = 87  LEFT JOIN
    catalog_product_entity_varchar AS V2 ON P.entity_id = V2.entity_id AND V2.attribute_id = 74  LEFT JOIN
    catalog_product_entity_text    AS T1 ON P.entity_id = T1.entity_id AND T1.attribute_id = 61  LEFT JOIN
    catalog_product_entity_text    AS T2 ON P.entity_id = T2.entity_id AND T2.attribute_id = 62  LEFT JOIN
    catalog_product_entity_int    AS T5 ON P.entity_id = T5.entity_id AND T5.attribute_id = 91 LEFT JOIN
    catalog_product_entity_decimal AS D  ON P.entity_id = D.entity_id  AND D.attribute_id  = 64 LEFT JOIN
    catalog_product_entity_int AS SIZE_CLOTH  ON P.entity_id = SIZE_CLOTH.entity_id  AND SIZE_CLOTH.attribute_id  = 122 LEFT JOIN
    catalog_product_entity_decimal AS S  ON P.entity_id = S.entity_id  AND S.attribute_id  = 65";

    //Run the query
    $query = mysql_query($sql);
    //But after this i will prepare the csv file for export.
    $file = fopen('products_export.csv', 'w');
    // Custom header for csv file
    $header = array('store', '_website', 'attribute_set', 'type', 'sku', 'name', 'description', 'short_description', 'visibility', 'has_option', 'price', 'special_price', 'size_cloth', 'link', 'image');
    // this will arrange all data by comma 
    fputcsv($file, $header, ',', '"');    
    //Loop through and print each products info
    while($row = mysql_fetch_array($query))
        { 
        $item = array();
            $value1 = ("admin");
            $value2 = ("base");
            $value3 = ($row['attribute_set_id']);
            $value4 = ($row['type_id']);
            $value5 = ($row['sku']);
            $value6 = ($row['Name']);
            $value7 = ($row['ProdDesc']);
            $value8 = ($row['ShortDesc']);
            $value9 = ($row['visibility']);
            $value10 = ($row['has_options']);
            $value11 = ($row['Price']);
            $value111 = ($row['Special_Price']);
            $value112 = ($row['size_cloth']);
            $value12 = ($row['Link']);
            //$value13 = ($row['Image']);
            $item[] = $value1;
            $item[] = $value2;
            $item[] = $value3;
            $item[] = $value4;
            $item[] = $value5;
            $item[] = $value6;
            $item[] = $value7;
            $item[] = $value8;
            $item[] = $value9;
            $item[] = $value10;
            $item[] = $value11;
            $item[] = $value111;
            $item[] = $value112;
            $item[] = $value12;

            // put all data in csv file
            fputcsv($file, $item, ',', '"');    
        }
        {
            // close csv file and finish.
        fclose($file);
   }
?>

最善の解決策はデータになると思います。例:

if ( $value112 == need to array the list of numbers, 1, 2, 3, 4, 5) {
    echo "S, M, L, XL";
} else {
    echo " ";
}

しかし、これを配列アイテムに挿入する方法がわかりません...

4

1 に答える 1

2

MagentoのDBと直接対話することは、私の最初の選択肢ではありません。実際に機能する代替案:

  1. Magentoのインポート/エクスポートモジュールを使用する

  2. MagentoDataflowのインポート/エクスポートを使用する

  3. Magentoの製品コレクションを使用して、エクスポートファイル http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collectionsを生成します

于 2012-09-30T15:04:26.677 に答える