assign customer to multiple customer groups to magento

后端 未结 2 825
逝去的感伤
逝去的感伤 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:32

    I found the solution,

    First of all go to database and click on the eav_attribute and then search for group_id in the attribute code field and edit this record.

    now Step 1:-

    change frontend_input from select to multiselect.

    step 2:-

    change backend_type from static to varchar.

    although it is not standard way but it worked for me. :)

    PS. I'm using magento 1.7.0.2 community version.

    0 讨论(0)
  • 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

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

    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.

    0 讨论(0)
提交回复
热议问题