i am making a guestwishlist i want to know how i can make a condtion if no product options are selected if must have to redirect me to product view page on add to cart option magento..

i did this so far

if (!$this->customerSession->isLoggedIn()) {
            $cookieValue = explode(', ', $this->cookieManager->getCookie(self::COOKIE_NAME));
            foreach ($cookieValue as $productId) {
                $product = $this->product->load($productId);     
                try {
                    $params = array(
                        'form_key' => $this->formKey->getFormKey(),
                        'product' => $productId, 
                        'qty'   =>1
                    $this->cart->addProduct($product, $params);

                } catch (\Throwable $ex) {
                    $this->messageManager->addError(__($ex->getMessage()).' for '.$product->getName());

        return $this->resultRedirectFactory->create()->setPath($this->_redirect->getRefererUrl());

Your Answer

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

Browse other questions tagged or ask your own question.