assign customer to multiple customer groups to magento

后端 未结 2 826
逝去的感伤
逝去的感伤 2021-02-04 21:10

Hello I want to assign multiple groups to particular customer like \"Rajat the customer\" belogs to \"Wholesale,retailer,electric\". actually I saw the same thread on Multiple c

2条回答
  •  粉色の甜心
    2021-02-04 21:38

    Rajat Modi's solution worked pretty well for me thank you but doing this did break the display of the groups column on the customer grid if more than one is selected, plus broke the ability to filter customers by group.

    To fix that, create this file to use as the renderer for customer groups: /app/code/local/Mage/Adminhtml/Block/Customer/Renderer/Group.php

    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);
    }
    }
    

    Then override /app/code/core/Mage/Adminhtml/Block/Customer/Grid.phpenter code here (copy it to /app/code/local/Mage/Adminhtml/Block/Customer/Grid.php)

    In the _prepareColumns() function, change this (around line 95):

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

    to this:

    $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')
    ));
    

    then it will use that class for rendering groups on the grid.

    Also in the _prepareCollection() function, around line 52 find ->addAttributeToSelect('group_id') and add after: ->addAttributeToSelect('customer_group_id')

    Having multiple groups per customer also seems to interfere with tiered pricing (where a product has a different price depending on customer group). To fix that on the frontend display... Fix for customer group-based product pricing tiers when calculating on the front-end:

    In /app/code/core/Mage/Catalog/Model/Product/Type/Price.php Around line 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) {

    Do the same thing in /app/code/core/Mage/Bundle/Model/Product/Price.php if you use bundles.

    I do not yet have a fix for displaying the customer group tier price when creating an order or reorder from the backend dashboard - they just show up the standard product prices.

    Finally, when figuring all this out we did have some instances where mgnt_catalog_product_entity_group_price got emptied and I'm still not sure why it happened, so do make sure to take backups. For that table I restored it from an SQL backup, but re-indexing things and maybe flushing the Magento cache is also often required when getting into this stuff.

    When doing things such as searching for customers by group programmatically in your own scripts or modules you may have to take into account that it is now a multiselect for example by doing things like this:

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

    Although I'm not sure that that piece of code will work right until all the customers have rows in the mgnt_customer_entity_varchar table which is where the new value for a customer's groups is stored when there are more than one group selected. Only a single group ID remains stored in mgnt_customer_entity as that field isn't varchar.

    For that reason be aware that yes it can affect modules which extend or use the functionality of customer groups.

提交回复
热议问题