【问题标题】:Delete product attribute value from database从数据库中删除产品属性值
【发布时间】:2012-03-07 00:01:48
【问题描述】:

假设我有一个 store=3 的 price 属性值和另一个 store=1 的值,我如何使用 magento 模型从 store_id=3 和 attribute_id=69 的 catalog_product_entity_decimal 中删除?

类似这个问题:Magento EAV: how to hard delete an attribute value?

【问题讨论】:

    标签: magento


    【解决方案1】:

    这样的?

    // get store 1
    $this->setCurrentStore('codeforstore1'); 
    $product->setData('price',null);
    or
    $product->setPrice(null);
    $product->save();
    
    // get store 2
    $this->setCurrentStore('codeforstore2'); 
    $product->setData('price',null);
    or
    $product->setPrice(null);
    $product->save();
    

    这将以编程方式摆脱它。

    另一种选择是这样做:

    DELETE DATA
    $id is the database table row id to be deleted.
    // $id = $this->getRequest()->getParam('id');
    $id = 13;
    $model = Mage::getModel('catalog/resource_eav_attribute');
    try {
            $model->setId($id)->delete();
            echo "Data deleted successfully."; 
        } catch (Exception $e){
            echo $e->getMessage();
    }
    

    HTH

    【讨论】:

    • 我不认为这会从数据库中删除该行。
    【解决方案2】:
    <?php
    $product->setStoreId($storeId)->load($id);
    $product->setAttributeCode(false);
    $product->save();
    

    此代码将从商店 $storeId 中删除属性 attribute_code 的值。

    【讨论】:

      猜你喜欢
      • 2019-10-30
      • 1970-01-01
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      相关资源
      最近更新 更多