【问题标题】:Changing Magento page_layout attribute on products?更改产品的 Magento page_layout 属性?
【发布时间】:2012-12-20 15:34:38
【问题描述】:

我有一个 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;
    }
}

现在我已经确定了正确的属性,我想设置它。到目前为止,我运气不佳,对此有什么经验吗?谢谢!

【问题讨论】:

    标签: php database magento e-commerce


    【解决方案1】:

    你试过 $product->setPageLayout(null); 编辑:当然之后是 $product->save()。

    【讨论】:

      【解决方案2】:

      股票 magento 实例中 page_layout 的可能值是:

      • two_columns_left
      • two_columns_right
      • 三列

      以“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();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-29
        • 1970-01-01
        • 2015-03-24
        • 1970-01-01
        相关资源
        最近更新 更多