0

数千の製品を扱う Magento ストアがあり、それらのサブセットの「page_layout」属性が「更新なし」以外に設定されています。レイアウトはcatalog.xml内で1列に設定されていますが、表示されるレイアウトは「page_layout」属性の値に対応しています。

すべての製品のこの属性を一度にプログラムで変更したいと考えています。これまでのところ、次のような製品でこの属性の値を得ることができました。

$attributes = $product->getAttributes();

foreach ($attributes as $attribute) {
    $attributeCode = $attribute->getAttributeCode();
    $code = 'page_layout';

    if ($attributeCode == $code) 
    {
        $label = $attribute->getStoreLabel($product);
        $value = $attribute->getFrontend()->getValue($product);
        echo $attributeCode . '-' . $label . '-' . $value;
    }
}

正しい属性を絞り込んだので、それを設定したいと思います。これまでのところあまり運がありませんが、これに関する経験はありますか?ありがとう!

4

2 に答える 2

1

$product->setPageLayout(null); を試しましたか? 編集:もちろん、その後 $product->save() 。

于 2012-12-20T15:45:07.063 に答える
0

ストック magento インスタンスの page_layout の可能な値は次のとおりです。

  • ヌル
  • 空の
  • two_columns_left
  • two_columns_right
  • three_columns

例として「two_columns_left」を使用して、この値をサイト内のすべての製品に設定します。

$pageLayout = 'two_columns_left';
$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->setDataToAll('page_layout', $pageLayout)
    ->save()
;

非常に多くの製品があるため、実行に時間がかかる可能性が高くなります。少しスピードアップするには、インデックス作成モードを変更できます。管理者を介して、またはコードで直接:

$processCollection = Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach ($processCollection as $process) {
    $process->setMode(Mage_Index_Model_Process::MODE_MANUAL)
        ->save();
}

あとがきを元に戻すには:

$process->setMode(Mage_Index_Model_Process::MODE_REAL_TIME)
    ->save();
于 2012-12-20T20:08:29.880 に答える