0

I want to set different prices for different customers. Can anyone tell me which are the correct events(Observers) to update price for the customer after he/she logged in?

1) Want to show custom price for him/her

2) If customer added product to cart and then he/she logged in then want update quote items prices.

0

You can set product custom price by below code

app/code/Namespace/Module/etc/frontend/events.xml

<event name="checkout_cart_product_add_after">
    <observer name="customprice" instance="Namespace\Module\Observer\CustomPrice" />
</event>

app/code/Namespace/Module/Observer/CustomPrice.php

<?php

namespace Namespace\Module\Observer;

use Magento\Framework\Event\ObserverInterface;

class CustomPrice implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $price = "YourCustomPrice" //You can set your cucstom price here
            $item = $observer->getEvent()->getData('quote_item');
            $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
            $item->setCustomPrice($price);
            $item->setOriginalCustomPrice($price);
            $item->getProduct()->setIsSuperMode(true);
    }
}
  • Thanks. Is this event will satisfy my 2nd condition? – user41818 Jan 18 '18 at 5:20
  • You can use this code for update product price when customer add to cart product. – Suresh Chikani Jan 18 '18 at 5:28
  • Any other suggestions? – user41818 Jan 20 '18 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy