We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
MAGE SE Detect product in cart and redirect
Plugin to detect a cart condition, i.e. product already added and error or redirect...
if ($product && $product->getSku()==='MJ01-XS-Yellow')
{
// default product is simple
//
if ($product->getTypeId()==='configurable')
{
if (isset($requestInfo['super_attribute']))
{
$parentProduct=$product;
$childProduct = $this->configurableProduct->getProductByAttributes($requestInfo['super_attribute'] ,$product);
// change $product to child
$product=$childProduct;
}
}
if ($product && $enableProductCartControl)
{
// check for existence of product in cart...
//
if($this->cartSession->getQuote()->hasProductId($product->getId())){
// redirect to cart
//$this->session->setRedirectUrl($this->url->getUrl('checkout/cart/index'));
throw new \Magento\Framework\Exception\LocalizedException(
__("[x] This product is already in the cart. Testing, testing : ". $product->getSku())
);
}
}
}
