首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编程设置Magento产品组权限

编程设置Magento产品组权限
EN

Stack Overflow用户
提问于 2015-05-26 18:19:06
回答 1查看 153关注 0票数 1

在Magento中编辑产品时,有一个权限选项卡,上面有两个多选择。

禁用产品

隐藏产品价格

我们需要通过包括“Mage.php”和使用脚本更新禁用组来编程地设置禁用产品组。

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

但似乎无法找到它。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-27 14:34:07

找到数据存储在数据库中的位置,并最终直接修改数据库。

$groupsDisabledArray是一个数组,它包含要禁用产品权限的每个组的ID。magento中的数据被简单地存储为组ID的逗号分隔列表

示例:

代码语言:javascript
复制
1,2,3,4,5,6,7,8,9,10

因此,我将禁用组ID的数组内爆,以获得逗号分隔的列表

代码语言:javascript
复制
$groupsList=implode(",", $groupsDisabledArray);

然后插入或更新catalog_product_entity_text表,这是存储值的地方。

该值存储在catalog_product_entity_text中,其中

代码语言:javascript
复制
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的路径,这取决于您将脚本放在哪里。

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30466008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档