2

製品を作成するとき、API 経由で以下を使用できます。

$newProductData = array(
                'name'              => (string)$stockItem->STOCK_DESC,
                'websites'          => array(1,2), // array(1,2,3,...)
                'short_description' => (string)$stockItem->STOCK_DESC,
                'description'       => (string)$stockItem->LONG_DESC,
                'status'            => 1,
                'weight'            => $stockItem->WEIGHT,
                'tax_class_id'      => 1,
                'categories'        => array(3108),
                'price'             => $stockItem->SELL_PRICE
            );

            $my_set_id = 9;  // Use whatever set_id you want here
            $type = 'simple';

            $mc = new Mage_Catalog_Model_Product_Api();
            $mc->create($type, $my_set_id, $stockItem->STOCK_CODE, $newProductData);

$mc->create呼び出しを調べると、次のようになっていることがわかります。

foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
}

これは、オブジェクトに対して編集できる属性のリストがあることを示しています。

これらを見つけるにはどうすればよいですか?この情報が見つかる特定の場所はありますか?

編集:私はちょうどやった:

Mage::log($product->getTypeInstance(true)->getEditableAttributes($product)); 

そして結果を見ました。編集可能なすべての属性が下にある[attribute_code] =>ようですが、このリストを取得するためにどこを見ればよいかを知るためのより良い方法が必要です.

4

1 に答える 1

2

これは、編集しようとしている商品の属性セットと、個々の属性の構成に完全に依存します。これらの属性を一覧表示する UI の場所はありません。あなたの最善の策は、製品のカスタムコードを実行することです

$product = Mage::getModel('catalog/product')->load($product_id);
foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $code=>$attribute)    
{
    var_dump($code); 
}

この情報を追跡する方法は次のとおりです。getEditableAttributesメソッドにジャンプすると

#File: app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php
public function getEditableAttributes($product = null)
{
    $cacheKey = '_cache_editable_attributes';
    if (!$this->getProduct($product)->hasData($cacheKey)) {
        $editableAttributes = array();
        foreach ($this->getSetAttributes($product) as $attributeCode => $attribute) {
            if (!is_array($attribute->getApplyTo())
                || count($attribute->getApplyTo())==0
                || in_array($this->getProduct($product)->getTypeId(), $attribute->getApplyTo())) {
                $editableAttributes[$attributeCode] = $attribute;
            }
        }
        $this->getProduct($product)->setData($cacheKey, $editableAttributes);
    }
    return $this->getProduct($product)->getData($cacheKey);
}

このメソッドは、特定の製品に設定されたすべての属性のリストを取得することがわかります (つまり、製品の属性セットのメンバーであるすべての属性)。このリストを取得すると、それぞれを調べて、そのapply_toプロパティが現在の製品のタイプ ID と一致するかどうかを確認します。

[適用先] 属性は次の場所に設定されています

Catalog -> Attributes -> Manage Attributes -> [Pick Attribute]

ここに画像の説明を入力

このフォーム フィールドは、データベース テーブルを更新しますcatalog_eav_attribute。次のクエリを実行すると、保存されているこの値の例を見ることができます

select attribute_id, apply_to from catalog_eav_attribute where apply_to is NOT NULL;
75  simple,configurable,virtual,bundle,downloadable
76  simple,configurable,virtual,bundle,downloadable
77  simple,configurable,virtual,bundle,downloadable
78  simple,configurable,virtual,bundle,downloadable
79  virtual,downloadable    

したがって、製品の属性セットを取得します。そのセット内の属性のリストを取得します。属性のapply_toフィールドの値と商品の の値を比較しますtype_id。これにより、これらの属性のリストを作成できます。

于 2013-02-21T17:25:22.173 に答える