$attributes = array(
'Category' => 'type',
'Manufacturer' => 'brand',
'Title' => 'meta_title',
'Description' => 'description',
'Product Link' => 'url_path',
'Price' => 'price',
'Product-image link' => 'image',
'SKU' => 'sku',
'Stock' => 'qty',
'Condition' => 'condition',
'Shipping cost' => 'delivery_cost');
製品コレクションを反復した後、次のような属性のフロントエンド値を取得します。
$attributeId = Mage::getResourceModel('eav/entity_attribute')
->getIdByCode('catalog_product', $attribute_code);
$attribute = Mage::getModel('catalog/resource_eav_attribute')
->load($attributeId);
$value = $attribute->getFrontend()->getValue($product);
$product->getDate($attribute)
はドロップダウンやマルチ選択では機能しません。フロントエンドの値ではなくIDだけを返します。
上記のコードはうまく動作しますが、値を得るのが難しいようですが、もっと重要なことに、それはかなり遅くなります。製品属性のフロントエンド値を取得するためのより迅速な、より賢明な方法がありますか?
を編集する私は今、以下のようにしています(image
やqty
のような特別なケースを扱った後)。
$inputType = $product->getResource()
->getAttribute($attribute_code)
->getFrontend()
->getInputType();
switch ($inputType) {
case 'multiselect':
case 'select':
case 'dropdown':
$value = $product->getAttributeText($attribute_code);
if (is_array($value)) {
$value = implode(', ', $value);
}
break;
default:
$value = $product->getData($attribute_code);
break;
}
$attributesRow[] = $value;
誰かがこれを改善できれば(より簡単で効率的に)、回答を投稿してください。
は、この記事を見てみましょうhttp://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-値/ –
ありがとう、役に立つ記事。 – Jamie