Magento 1.8。如何在两个或多个组中添加一个客户?

时间:2014-06-08 08:39:47

标签: magento magento-1.7 magento-1.8

Magento 1.8。 如何在两个或多个组中添加一个客户? Magento 1.8。 如何在两个或多个组中添加一个客户?

1 个答案:

答案 0 :(得分:0)

默认情况下,magento首先不提供此类型功能。

如果你想这样做,你可以使用这种黑客方法

请注意,这不是实现此目的的标准方法,我不确定应用购物车规则时的行为方式

首先转到database并点击eav_attribute表,然后在group_id字段中找到attribute code并修改此记录。

frontend_inputselect更改为multiselect // ,它将允许您选择多组客户

然后

backend_typestatic更改为varchar

通过这种方式,您可以选择多个客户群,但是如果您想在客户网格中显示多个客户群,那么您必须遵循此

/app/code/local/Mage/Adminhtml/Block/Customer/Renderer/Group.php

<?php
class Mage_Adminhtml_Block_Customer_Renderer_Group
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
public function render(Varien_Object $row)
{
$value = $row->getData($this->getColumn()->getIndex());
$groups = Mage::getModel('customer/group')->getCollection()
->addFieldToFilter('customer_group_id', array('in' => explode(',', $value)));
$groupNames = array();
foreach ($groups as $group)
{
$groupNames[] = $group->getCustomerGroupCode();
}
return implode(', ', $groupNames);
}
}

然后覆盖

/app/code/core/Mage/Adminhtml/Block/Customer/Grid.php(将其复制到/app/code/local/Mage/Adminhtml/Block/Customer/Grid.php

_prepareColumns()函数

$this->addColumn('group', array(
'header'    =>  Mage::helper('customer')->__('Group'),
'width'     =>  '100',
'index'     =>  'group_id',
'type'      =>  'options',
'options'   =>  $groups,
));

到这个

$this->addColumn('group_id', array(
'header'    =>  Mage::helper('customer')->__('Group'),
'width'     =>  '100',
'index'     =>  'group_id',
'type'      =>  'options',
'options'   =>  $groups,
'renderer' => 'Mage_Adminhtml_Block_Customer_Renderer_Group',
'filter_condition_callback' => array($this, '_filterGroupCondition')
));

然后它将使用该类在网格上渲染组。

同样在_prepareCollection()函数中,第52行左右找到->addAttributeToSelect('group_id') and add after: ->addAttributeToSelect('customer_group_id')

每个客户拥有多个群组似乎也会干扰分层定价(根据客户群,产品的价格会有所不同)。要在前端显示上修复此问题...在前端计算时修复基于客户组的产品定价层:

/app/code/core/Mage/Catalog/Model/Product/Type/Price.php第138行附近,

FIND:

$customerGroup = $this->_getCustomerGroupId($product);

ADD AFTER:

 $customerGroups = explode(',',$customerGroup);

FIND:

if ($groupPrice['cust_group'] == $customerGroup && $groupPrice['website_price'] < $matchedPrice) { REPLACE WITH: if (in_array($groupPrice['cust_group'],$customerGroups) && $groupPrice['website_price'] < $matchedPrice) {

如果您使用捆绑包,请在/app/code/core/Mage/Bundle/Model/Product/Price.php中执行相同的操作。

在创建订单或从后端信息中心重新排序时,我还没有显示客户组级价格的修复程序 - 它们只是显示标准产品价格。

最后,当弄清楚这一切时,我们确实遇到了catalog_product_entity_group_price被清空的一些情况,我仍然不确定它为什么会发生,所以请务必进行备份。对于该表,我从SQL备份中恢复了它,但是在进入这些内容时,通常还需要重新编制索引并可能刷新Magento缓存。

当您在自己的脚本或模块中以编程方式按组搜索客户时,您可能必须考虑到它现在是多选的,例如通过这样做:

$allowedGroups = array(
array(
"finset" => array(10)
),
array(
"finset" => array(42)
)
);
$collection = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('group_id', $allowedGroups);

虽然我不确定那段代码是否正常工作,直到所有客户在customer_entity_varchar表中都有行,而这些行是存储客户组的新值的时候选择了多个组。只有一个组ID仍保存在customer_entity中,因为该字段不是varchar

如果您有任何疑问,请告诉我

相关问题