0

Guys I'm wondering how to add a special price for a specific customer group? For example, I have a group called "Special Customers", I want to set 10% price increase on every product for this specified group only. Thank you in advance.

2
  • I thin you can use group pricing. take a look at this docs.magento.com/user-guide/catalog/product-price-group.html You can use the configuration settings in the Admin to set prices for discounted items based on customer groups in your store. This is called group pricing.
    – Korbin
    Commented May 2, 2022 at 7:35
  • 1
    I've answered, let's have a check on it too.If its working then accept it too
    – S.Shah
    Commented Jul 26, 2022 at 11:04

2 Answers 2

1

First you create di.xml for plugin

etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Product">
        <plugin name="change_product" type="Vendor\Module\Plugin\Product"/>
    </type>
</config>

and then create a plugin for it

app/code/Vendor/Module/Plugin/Product.php

<?php
declare(strict_types=1);

namespace Vendor\Module\Plugin;

use Magento\Customer\Model\Session;

/**
 * class for changing product price
 */
class Product
{
    protected Session $customersession;

    /**
     * @param \Magento\Catalog\Model\Product $subject
     * @param $result
     * @return int
     */
    public function __construct(
        Session $customerSession
    ){
        $this->customersession = $customerSession;

    }
    public function afterGetPrice(
        \Magento\Catalog\Model\Product $subject,
                                       $result
    ) {
    $customerGroup=$this->customersession->getCustomer()->getGroupId();
    if($customerGroup == 4){
        return $result * 1.2;
    }
    return $result;
    }
}

Mine customer group id is 4 like this $customerGroup == 4 in your case you have to check yours first and then try it.

1
  • I've answered, let's have a check on it too.If it's working then accept it too
    – S.Shah
    Commented Jul 26, 2022 at 11:07
1

Try this

<?php

namespace Test\Sample\Controller\Index;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Catalog\Api\ProductTierPriceManagementInterface;

class Index extends Action
{

    protected $tierPrice;

    public function __construct(Context $context, ProductTierPriceManagementInterface $tier)
    {
        $this->tierPrice = $tier;
        parent::__construct($context);
    }

     public function execute()
    {
        $sku = 'test-sku'; //Product sku
        $customerGroupId = 2; //Wholsaler group id
        $price = 200;
        $qty = 55;

        $this->tierPrice->add($sku,$customerGroupId,$price, $qty);
    }
}
2
  • How to use this on the products category page? e.x in list.phtml file. Commented May 15, 2022 at 18:19
  • Very Simple, Just create the object of $this->tierPrice using the block or use directly OM, and then pass the required details like sku, customergpId, price and qty. For Reference use how to override it : rakeshjesadiya.com/… Commented May 16, 2022 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.