【问题标题】:Set Magento Product Group Permissions Programatically以编程方式设置 Magento 产品组权限
【发布时间】:2015-08-08 13:37:29
【问题描述】:

当您在 Magento 中编辑产品时,会出现一个权限选项卡,上面有两个多选选项。

禁用产品

隐藏产品价格

我们需要以编程方式设置禁用产品组,方法是包含“Mage.php”并使用脚本更新禁用组。

例如,我们希望为一个产品禁用 10 个特定组的产品。我们已经能够在脚本的管理界面中做几乎所有其他事情,因此应该有一种方法可以使用 Mage::getModel('catalog/product') 或其他模型来访问它。调用一个函数,传入您想要将产品设置为禁用的组 ID。

但似乎无法追踪到它。

谢谢!

【问题讨论】:

    标签: php magento


    【解决方案1】:

    找到数据在数据库中的存储位置,结果直接修改了数据库。

    $groupsDisabledArray 是一个数组,其中包含我要为其禁用产品权限的每个组的 ID。 magento 中的数据只是以逗号分隔的 Group ID 列表形式存储

    例子:

    1,2,3,4,5,6,7,8,9,10
    

    所以我内爆了我禁用的组 ID 的数组以获得逗号分隔的列表

    $groupsList=implode(",", $groupsDisabledArray);
    

    然后插入或更新存储值的 catalog_product_entity_text 表。

    值存储在 catalog_product_entity_text 中

    entity_id = PRODUCT_ID
    attribute_id = 155 (This corresponds to the table eav_attribute where attribute_code = 'aw_cp_disable_product')
    entity_type_id = 4 (This corresponds to table eav_entity_type where entity_type_code = 'catalog_product')
    store_id = STORE_ID (If you just have one store you should just be able to put 0 here for the Default Store)
    

    执行以下完整更新的代码。可能需要更新 Mage.php 的路径,具体取决于您放置脚本的位置。

    include("/app/Mage.php");
    
    /* Get DB Connections */
    $resource = Mage::getSingleton('core/resource');
    $readConnection = $resource->getConnection('core_read');
    $writeConnection = $resource->getConnection('core_write');
    $tableName = $resource->getTableName('catalog_product_entity_text');
    
    /* $groupsDisabledArray - Array of all of the Magento Group ID's I want to disable this product for */
    
    $groupsList=implode(",", $groupsDisabledArray);
    $sql="SELECT * FROM $tableName WHERE entity_id=$product_id AND attribute_id=155 and entity_type_id=4 AND store_id=0;";
    $results = $readConnection->fetchAll($sql);
    if (count($results) > 0) {
        $sql="UPDATE $tableName SET value='$groupsList' WHERE entity_id=$product_id AND attribute_id=155 and entity_type_id=4 AND store_id=0;";
    }
    else
    {
        $sql="INSERT INTO $tableName (entity_id, entity_type_id, store_id, attribute_id, value) VALUES ($product_id, 4, 0, 155, '$groupsList')";
    }
    $writeConnection->query($sql);
    

    【讨论】:

      猜你喜欢
      • 2013-11-23
      • 2013-08-16
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2016-03-14
      • 2012-11-15
      • 2012-12-29
      相关资源
      最近更新 更多