Following are the code show Premium or Non-Premium along with product name using observer,
<?php
namespace Gta\CustomerMsgPdp\Observer\Product;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class Data implements ObserverInterface
{
/**
* Below is the method that will fire whenever the event runs!
*
* @param Observer $observer
*/
public function execute(Observer $observer)
{
$product = $observer->getProduct();
$originalName = $product->getName();
$price = $product->getPrice();
if($price >= '50')
{
$modifiedName = $originalName . ' - Premium Products';
}
elseif($price <= '50')
{
$modifiedName = $originalName . ' - Non Premium Products';
}
// $modifiedName = $originalName . ' - Modified by Magento 2 Events and Observers';
$product->setName($modifiedName);
}
}
I want to add another observer to check if customer logged-in or not if customer logged-in then only show wheater it is premium or non-premium products.