Magento 2 current product how to check it is come from the cart edit in observer.
Please refer the cart edit url:
http://127.0.0.1/mage231/checkout/cart/configure/id/26/product_id/1/
Thanks in Advanced
Magento 2 current product how to check it is come from the cart edit in observer.
Please refer the cart edit url:
http://127.0.0.1/mage231/checkout/cart/configure/id/26/product_id/1/
Thanks in Advanced
USE This Code
private $request;
public function __construct(
...
\Magento\Framework\App\Request\Http $request
) {
...
$this->request = $request;
}
Use This Condition ......
$moduleName = $this->request->getModuleName();// checkout
$controller = $this->request->getControllerName();// cart
$action = $this->request->getActionName();// configure
$route = $this->request->getRouteName();// checkout
if (($moduleName == 'checkout') && ($controller == 'cart') && ($action == 'configure') && ($route == 'checkout'))
{
//Your Code
}
Try this:
$quote_data = $objectManager->get('\Magento\Checkout\Model\Session')->getQuote();
$result = $quote_data_->getAllVisibleItems();
$itemsIds = array();
foreach ($result as $quote_data_Item) {
array_push($itemsIds, $quote_data_Item->getProduct()->getId());
}
if(in_array($productId, $itemsIds)){
echo "in cart";
}
Use following code to check controller and module
echo $controllerName = $this->getRequest()->getControllerName();
echo $actionName = $this->getRequest()->getActionName();
echo $routeName = $this->getRequest()->getRouteName();
echo $moduleName = $this->getRequest()->getModuleName();
You can verify by controller and module name, it would be different than default product view. use if
condition to do this.
Hope you find your solution