【问题标题】:How to save an attribute value for a specific store view?如何保存特定商店视图的属性值?
【发布时间】:2014-06-14 17:38:58
【问题描述】:

我正在尝试在 Magento 1.8 中以编程方式创建产品,然后为其设置一些属性值。到目前为止一切正常,属性在“默认”范围内与产品一起正确保存。

问题是我的商店有两种不同的“商店视图”,一种是英文的,一种是法文的。我不知道如何为特定属性的数据设置“范围”或“存储视图”。

如何告诉 Magento 为特定范围保存属性值?

这是一个使用“简短描述”属性的代码示例:

 $product = new Mage_Catalog_Model_Product();
 $product->setSku($sku);
 $product->setAttributeSetId($attributeSetId);
 $product->setTypeId($typeId);
 $product->setName($sku);
 $product->setWebsiteIDs(array($websiteId));
 $product->setShortDescription('Short description in english');
 $product->setShortDescription('Short description in french'); // Scope change here?

【问题讨论】:

    标签: magento magento-1.8


    【解决方案1】:

    为特定的商店视图添加此项

    $product->setStoreId($storeId);
    

    【讨论】:

      【解决方案2】:
      $store_id = Mage::app()->getStore()->getStoreId();
      
      $product = Mage::getModel('catalog/product')->setStoreId($store_id);
      $brandLabel = $product->setData('brand','adidas')->getResource()->saveAttribute($product, 'brand');
      

      【讨论】:

        【解决方案3】:

        创建产品后,它应该有一个 ID。
        这是一种快速更新特定商店视图的产品名称和简短描述的方法,而无需调用消耗资源的 save 方法。
        假设产品 ID 为 10,商店视图 ID 为 2。
        运行这个:

        $productId = 10;
        $storeId = 2;
        $newName = 'Nom de produit';
        $newShortDescription = 'description de produit';
        Mage::getSingleton('catalog/product_action')->updateAttributes(
            array($productId),
            array('name'=>$newName, 'short_description' => $newShortDescription),
            $storeId
        );
        

        【讨论】:

          【解决方案4】:
          <?php $StoreId = Mage::app()->getStore()->getId();
          
          $product = Mage::getModel('catalog/product')->setStoreId($StoreId);
          $brandLabel = $product->setData('brand','adidas')->getResource()->saveAttribute($product, 'brand'); ?>
          

          【讨论】:

            【解决方案5】:

            用于默认商店视图

            $product = new Mage_Catalog_Model_Product();
             $product->setSku($sku);
             $product->setAttributeSetId($attributeSetId);
             $product->setTypeId($typeId);
             $product->setName($sku);
             $product->setWebsiteIDs(array($websiteId));
             $product->setShortDescription('Short description in english');
             $product->setStoreId(array(0));
            

            【讨论】:

              猜你喜欢
              • 2014-06-27
              • 1970-01-01
              • 2015-05-14
              • 2011-11-07
              • 2015-03-19
              • 1970-01-01
              • 2021-01-31
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多