/** * Update items stock status and low stock date. * * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { if (!$this->newRelicWrapper->isExtensionInstalled()) { $this->config->disableModule(); $this->messageManager->addError(__('The New Relic integration requires the newrelic-php5 agent, which is not installed. More information on installing the agent is available <a target="_blank" href="%1">here</a>.', 'https://docs.newrelic.com/docs/agents/php-agent/installation/php-agent-installation-overview'), $this->messageManager->getDefaultGroup()); } } }
/** * @param \Magento\Framework\Event\Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(\Magento\Framework\Event\Observer $observer) { try { $this->checkoutSession->loadCustomerQuote(); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Load customer quote error')); } }
/** * Handle exception * * @param \Exception $e * @return void */ protected function handleException($e) { $needToMaskDisplayMessage = !$e instanceof \Magento\Framework\Exception\LocalizedException && $this->appState->getMode() != State::MODE_DEVELOPER; $displayMessage = $needToMaskDisplayMessage ? (string) new \Magento\Framework\Phrase('An error occurred while processing your request') : $e->getMessage(); $this->messageManager->addError($displayMessage); $this->logger->critical($e->getMessage()); }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function getWishlist($wishlistId = null) { if ($this->wishlist) { return $this->wishlist; } try { if (!$wishlistId) { $wishlistId = $this->request->getParam('wishlist_id'); } $customerId = $this->customerSession->getCustomerId(); $wishlist = $this->wishlistFactory->create(); if (!$wishlistId && !$customerId) { return $wishlist; } if ($wishlistId) { $wishlist->load($wishlistId); } elseif ($customerId) { $wishlist->loadByCustomerId($customerId, true); } if (!$wishlist->getId() || $wishlist->getCustomerId() != $customerId) { throw new \Magento\Framework\Exception\NoSuchEntityException(__('The requested Wish List doesn\'t exist.')); } } catch (\Magento\Framework\Exception\NoSuchEntityException $e) { $this->messageManager->addError($e->getMessage()); return false; } catch (\Exception $e) { $this->messageManager->addException($e, __('We can\'t create the Wish List right now.')); return false; } $this->wishlist = $wishlist; return $wishlist; }
/** * Before execute login * * @param Login $login * @return void */ public function beforeExecute(Login $login) { $logoutReasonCode = $this->securityCookieHelper->getLogoutReasonCookie(); if ($this->isLoginForm($login) && $logoutReasonCode >= 0) { $this->messageManager->addError($this->sessionsManager->getLogoutReasonMessageByStatus($logoutReasonCode)); $this->securityCookieHelper->deleteLogoutReasonCookie(); } }
/** * Add user logout notification * * @return $this */ protected function addUserLogoutNotification() { if ($this->isAjaxRequest()) { $this->securityCookieHelper->setLogoutReasonCookie($this->sessionsManager->getCurrentSession()->getStatus()); } else { $this->messageManager->addError($this->sessionsManager->getLogoutReasonMessage()); } return $this; }
/** * @return void */ public function loadCustomerQuote() { try { $this->_checkoutSession->loadCustomerQuote(); } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Load customer quote error')); } }
/** * Check if required fields is not empty * * @param array $data * @return bool */ public function validateRequireEntry(array $data) { $requiredFields = ['title' => __('Page Title'), 'stores' => __('Store View'), 'is_active' => __('Status')]; $errorNo = true; foreach ($data as $field => $value) { if (in_array($field, array_keys($requiredFields)) && $value == '') { $errorNo = false; $this->messageManager->addError(__('To apply changes you should fill in hidden required "%1" field', $requiredFields[$field])); } } return $errorNo; }
/** * Update saved shipping methods available for ShipperHQ * * @param EventObserver $observer * @return void */ public function execute(EventObserver $observer) { if ($this->shipperDataHelper->getConfigValue('carriers/shipper/active')) { $refreshResult = $this->shipperCarrier->refreshCarriers(); if (array_key_exists('error', $refreshResult)) { $message = __($refreshResult['error']); $this->messageManager->addError($message); } else { $message = __('%1 carriers have been updated from ShipperHQ', count($refreshResult)); $this->messageManager->addSuccess($message); } } }
/** * Check CAPTCHA on Contact Us page * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { $formId = 'contact_us'; $captcha = $this->_helper->getCaptcha($formId); if ($captcha->isRequired()) { /** @var \Magento\Framework\App\Action\Action $controller */ $controller = $observer->getControllerAction(); if (!$captcha->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) { $this->messageManager->addError(__('Incorrect CAPTCHA.')); $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->redirect->redirect($controller->getResponse(), 'contact/index/index'); } } }
/** * @param Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { $webhook = $this->storeManager->getStore()->getBaseUrl() . "cpwebhook/"; try { $client = new Client($this->model->getPublicKey(), $this->model->getPrivateKey(), $this->model->getLiveMode()); Validations::validateGateway($client); $client->api->createWebhook($webhook); $response = $client->api->hookRetro($this->model->getConfigData('active') == 1); if ($response[0]) { $this->messageManager->addNotice("ComproPago: {$response[1]}"); } } catch (\Exception $e) { $this->messageManager->addError("ComproPago: {$e->getMessage()}"); } }
/** * Check file system full path * * @param string $fullPath * @param bool $recursive * @param bool $existence * @return bool */ protected function _checkFullPath($fullPath, $recursive, $existence) { $result = true; $directory = $this->_filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::ROOT_DIR); $path = $directory->getRelativePath($fullPath); if ($recursive && $directory->isDirectory($path)) { $pathsToCheck = $directory->read($path); array_unshift($pathsToCheck, $path); } else { $pathsToCheck = array($path); } $skipFileNames = array('.svn', '.htaccess'); foreach ($pathsToCheck as $pathToCheck) { if (in_array(basename($pathToCheck), $skipFileNames)) { continue; } if ($existence) { $setError = !$directory->isWritable($path); } else { $setError = $directory->isExist($path) && !$directory->isWritable($path); } if ($setError) { $this->messageManager->addError(__('Path "%1" must be writable.', $pathToCheck)); $result = false; } } return $result; }
/** * Check captcha on user login page * * @param \Magento\Framework\Event\Observer $observer * @throws NoSuchEntityException * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $formId = 'user_login'; $captchaModel = $this->_helper->getCaptcha($formId); $controller = $observer->getControllerAction(); $loginParams = $controller->getRequest()->getPost('login'); $login = is_array($loginParams) && array_key_exists('username', $loginParams) ? $loginParams['username'] : null; if ($captchaModel->isRequired($login)) { $word = $this->captchaStringResolver->resolve($controller->getRequest(), $formId); if (!$captchaModel->isCorrect($word)) { try { $customer = $this->getCustomerRepository()->get($login); $this->getAuthentication()->processAuthenticationFailure($customer->getId()); } catch (NoSuchEntityException $e) { //do nothing as customer existance is validated later in authenticate method } $this->messageManager->addError(__('Incorrect CAPTCHA')); $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->_session->setUsername($login); $beforeUrl = $this->_session->getBeforeAuthUrl(); $url = $beforeUrl ? $beforeUrl : $this->_customerUrl->getLoginUrl(); $controller->getResponse()->setRedirect($url); } } $captchaModel->logAttempt($login); return $this; }
/** * Method allows to display message about not working cron job in admin panel. * Need call at start of adminhtml controller action. * * @param string $jobCode Cron job code (from crontab.xml). * @param bool $output By default - return cron error as adminhtml error message, otherwise - as string. * @param string $prefix Additional text to cron job error message. * @return array [$status, $message] */ public function checkCronStatus($jobCode, $output = true, $prefix = '') { if (!$this->isCronRunning($jobCode)) { $message = ''; if ($prefix) { $message .= $prefix . ' '; } $message .= __('Cron for magento is not running.' . ' To setup a cron job follow the <a target="_blank" href="%1">link</a>', 'http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cron.html'); if ($output) { $this->messageManager->addError($message); } else { return [false, $message]; } } return [true, '']; }
/** * Load invoice * @deprecated * @param int $orderId * @param null|int $invoiceId * @param array $invoiceItems * @return \Magento\Sales\Model\Order\Invoice | bool * @throws \Exception */ public function load($orderId, $invoiceId = null, array $invoiceItems = []) { $invoice = false; if ($invoiceId) { $invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Invoice')->load($invoiceId); if (!$invoice->getId()) { $this->messageManager->addError(__('The invoice no longer exists.')); return false; } } elseif ($orderId) { $order = $this->_objectManager->create('Magento\\Sales\\Model\\Order')->load($orderId); /** * Check order existing */ if (!$order->getId()) { $this->messageManager->addError(__('The order no longer exists.')); return false; } /** * Check invoice create availability */ if (!$order->canInvoice()) { $this->messageManager->addError(__('The order does not allow an invoice to be created.')); return false; } $invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Service\\Order', array('order' => $order))->prepareInvoice($invoiceItems); if (!$invoice->getTotalQty()) { throw new \Exception(__('Cannot create an invoice without products.')); } } $this->registry->register('current_invoice', $invoice); return $invoice; }
/** * Check Captcha On Forgot Password Page * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $captchaModel = $this->helper->getCaptcha(self::FORM_ID); if ($captchaModel->isRequired()) { /** @var \Magento\Framework\App\Action\Action $controller */ $controller = $observer->getControllerAction(); if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) { $customerId = $this->customerSession->getCustomerId(); $this->authentication->processAuthenticationFailure($customerId); if ($this->authentication->isLocked($customerId)) { $this->customerSession->logout(); $this->customerSession->start(); $message = __('The account is locked. Please wait and try again or contact %1.', $this->scopeConfig->getValue('contact/email/recipient_email')); $this->messageManager->addError($message); } $this->messageManager->addError(__('Incorrect CAPTCHA')); $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->redirect->redirect($controller->getResponse(), '*/*/edit'); } } $customer = $this->customerSession->getCustomer(); $login = $customer->getEmail(); $captchaModel->logAttempt($login); return $this; }
/** * Adding products to cart by ids * * @param int[] $productIds * @return $this */ public function addProductsByIds($productIds) { $allAvailable = true; $allAdded = true; if (!empty($productIds)) { foreach ($productIds as $productId) { $productId = (int) $productId; if (!$productId) { continue; } $product = $this->_getProduct($productId); if ($product->getId() && $product->isVisibleInCatalog()) { try { $this->getQuote()->addProduct($product); } catch (\Exception $e) { $allAdded = false; } } else { $allAvailable = false; } } if (!$allAvailable) { $this->messageManager->addError(__("We don't have some of the products you want.")); } if (!$allAdded) { $this->messageManager->addError(__("We don't have as many of some products as you want.")); } } return $this; }
/** * Initialize shipment model instance * * @return bool|\Magento\Sales\Model\Order\Shipment * @throws \Magento\Framework\Exception\LocalizedException */ public function load() { $shipment = false; $orderId = $this->getOrderId(); $shipmentId = $this->getShipmentId(); if ($shipmentId) { $shipment = $this->shipmentRepository->get($shipmentId); } elseif ($orderId) { $order = $this->orderRepository->get($orderId); /** * Check order existing */ if (!$order->getId()) { $this->messageManager->addError(__('The order no longer exists.')); return false; } /** * Check shipment is available to create separate from invoice */ if ($order->getForcedShipmentWithInvoice()) { $this->messageManager->addError(__('Cannot do shipment for the order separately from invoice.')); return false; } /** * Check shipment create availability */ if (!$order->canShip()) { $this->messageManager->addError(__('Cannot do shipment for the order.')); return false; } $shipment = $this->shipmentFactory->create($order, $this->getItemQtys(), $this->getTracking()); } $this->registry->register('current_shipment', $shipment); return $shipment; }
/** * Try to load valid order by $_POST or $_COOKIE * * @param App\RequestInterface $request * @param App\ResponseInterface $response * @return bool * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function loadValidOrder(App\RequestInterface $request, App\ResponseInterface $response) { if ($this->customerSession->isLoggedIn()) { $response->setRedirect($this->_urlBuilder->getUrl('sales/order/history')); return false; } $post = $request->getPost(); $errors = false; /** @var $order \Magento\Sales\Model\Order */ $order = $this->orderFactory->create(); $fromCookie = $this->cookieManager->getCookie(self::COOKIE_NAME); if (empty($post) && !$fromCookie) { $response->setRedirect($this->_urlBuilder->getUrl('sales/guest/form')); return false; } elseif (!empty($post) && isset($post['oar_order_id']) && isset($post['oar_type'])) { $type = $post['oar_type']; $incrementId = $post['oar_order_id']; $lastName = $post['oar_billing_lastname']; $email = $post['oar_email']; $zip = $post['oar_zip']; if (empty($incrementId) || empty($lastName) || empty($type) || !in_array($type, array('email', 'zip')) || $type == 'email' && empty($email) || $type == 'zip' && empty($zip)) { $errors = true; } if (!$errors) { $order->loadByIncrementId($incrementId); } $errors = true; if ($order->getId()) { $billingAddress = $order->getBillingAddress(); if (strtolower($lastName) == strtolower($billingAddress->getLastname()) && ($type == 'email' && strtolower($email) == strtolower($billingAddress->getEmail()) || $type == 'zip' && strtolower($zip) == strtolower($billingAddress->getPostcode()))) { $errors = false; } } if (!$errors) { $toCookie = base64_encode($order->getProtectCode() . ':' . $incrementId); $this->setGuestViewCookie($toCookie); } } elseif ($fromCookie) { $cookieData = explode(':', base64_decode($fromCookie)); $protectCode = isset($cookieData[0]) ? $cookieData[0] : null; $incrementId = isset($cookieData[1]) ? $cookieData[1] : null; $errors = true; if (!empty($protectCode) && !empty($incrementId)) { $order->loadByIncrementId($incrementId); if ($order->getProtectCode() == $protectCode) { // renew cookie $this->setGuestViewCookie($fromCookie); $errors = false; } } } if (!$errors && $order->getId()) { $this->coreRegistry->register('current_order', $order); return true; } $this->messageManager->addError(__('You entered incorrect data. Please try again.')); $response->setRedirect($this->_urlBuilder->getUrl('sales/guest/form')); return false; }
/** * Check Captcha On User Login Page * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $formId = 'user_create'; $captchaModel = $this->_helper->getCaptcha($formId); if ($captchaModel->isRequired()) { /** @var \Magento\Framework\App\Action\Action $controller */ $controller = $observer->getControllerAction(); if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) { $this->messageManager->addError(__('Incorrect CAPTCHA')); $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->_session->setCustomerFormData($controller->getRequest()->getPostValue()); $url = $this->_urlManager->getUrl('*/*/create', ['_nosecret' => true]); $controller->getResponse()->setRedirect($this->redirect->error($url)); } } return $this; }
/** * Validate post data * * @param array $data * @return bool Return FALSE if someone item is invalid */ public function validate($data) { $errorNo = true; if (!empty($data['layout_update_xml']) || !empty($data['custom_layout_update_xml'])) { /** @var $validatorCustomLayout \Magento\Framework\View\Model\Layout\Update\Validator */ $validatorCustomLayout = $this->validatorFactory->create(); if (!empty($data['layout_update_xml']) && !$validatorCustomLayout->isValid($data['layout_update_xml'])) { $errorNo = false; } if (!empty($data['custom_layout_update_xml']) && !$validatorCustomLayout->isValid($data['custom_layout_update_xml'])) { $errorNo = false; } foreach ($validatorCustomLayout->getMessages() as $message) { $this->messageManager->addError($message); } } return $errorNo; }
/** * Logout a user if it is locked * * @throws \Magento\Framework\Exception\SessionException * @return void */ protected function workWithLock() { $customerModel = $this->customerSession->getCustomer(); if ($customerModel->isCustomerLocked()) { $this->customerSession->logout(); $this->customerSession->start(); $message = __('The account is locked. Please wait and try again or contact %1.', $this->scopeConfig->getValue('contact/email/recipient_email')); $this->messageManager->addError($message); } }
/** * Check Captcha On User Login Backend Page * * @param \Magento\Framework\Event\Observer $observer * @throws \Magento\Framework\Exception\Plugin\AuthenticationException * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $formId = 'backend_forgotpassword'; $captchaModel = $this->_helper->getCaptcha($formId); $controller = $observer->getControllerAction(); $email = (string) $observer->getControllerAction()->getRequest()->getParam('email'); $params = $observer->getControllerAction()->getRequest()->getParams(); if (!empty($email) && !empty($params)) { if ($captchaModel->isRequired()) { if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) { $this->_session->setEmail((string) $controller->getRequest()->getPost('email')); $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->messageManager->addError(__('Incorrect CAPTCHA')); $controller->getResponse()->setRedirect($controller->getUrl('*/*/forgotpassword', ['_nosecret' => true])); } } } return $this; }
/** * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { if ($observer->getStore()) { $scopeId = $observer->getStore(); $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; } elseif ($observer->getWebsite()) { $scopeId = $observer->getWebsite(); $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE; } else { $scopeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID; $scopeType = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; } foreach ($this->getErrors($scopeId, $scopeType) as $error) { $this->messageManager->addError($error); } foreach ($this->getNotices() as $notice) { $this->messageManager->addNotice($notice); } return $this; }
/** * Delete product item from Google Content * * @param \Magento\Framework\Object $observer * @return $this */ public function deleteProductItem($observer) { $product = $observer->getEvent()->getProduct(); $items = $this->_getItemsCollection($product); try { $this->_operationsFactory->create()->deleteItems($items); } catch (\Zend_Gdata_App_CaptchaRequiredException $e) { $this->messageManager->addError('Cannot delete Google Content Item. Google requires CAPTCHA.'); } return $this; }
/** * Check Captcha On User Login Page * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $formId = 'user_login'; $captchaModel = $this->_helper->getCaptcha($formId); $controller = $observer->getControllerAction(); $loginParams = $controller->getRequest()->getPost('login'); $login = array_key_exists('username', $loginParams) ? $loginParams['username'] : null; if ($captchaModel->isRequired($login)) { $word = $this->captchaStringResolver->resolve($controller->getRequest(), $formId); if (!$captchaModel->isCorrect($word)) { $this->messageManager->addError(__('Incorrect CAPTCHA')); $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->_session->setUsername($login); $beforeUrl = $this->_session->getBeforeAuthUrl(); $url = $beforeUrl ? $beforeUrl : $this->_customerUrl->getLoginUrl(); $controller->getResponse()->setRedirect($url); } } $captchaModel->logAttempt($login); return $this; }
/** * Add error message * * @param Address $customerAddress * @return $this */ protected function addErrorMessage($customerAddress) { $message = [(string) __('Your Tax ID cannot be validated.')]; $customer = $customerAddress->getCustomer(); if (!$this->scopeConfig->isSetFlag(HelperAddress::XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT) && !$customer->getDisableAutoGroupChange()) { $message[] = (string) __('You will be charged tax.'); } $email = $this->scopeConfig->getValue('trans_email/ident_support/email', ScopeInterface::SCOPE_STORE); $message[] = (string) __('If you believe this is an error, please contact us at %1', $email); $this->messageManager->addError(implode(' ', $message)); return $this; }
/** * Load invoice * * @param RequestInterface $request * @return bool * @throws \Exception */ public function load(RequestInterface $request) { $invoice = false; $invoiceId = $request->getParam('invoice_id'); $orderId = $request->getParam('order_id'); if ($invoiceId) { $invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Invoice')->load($invoiceId); if (!$invoice->getId()) { $this->messageManager->addError(__('The invoice no longer exists.')); return false; } } elseif ($orderId) { $order = $this->_objectManager->create('Magento\\Sales\\Model\\Order')->load($orderId); /** * Check order existing */ if (!$order->getId()) { $this->messageManager->addError(__('The order no longer exists.')); return false; } /** * Check invoice create availability */ if (!$order->canInvoice()) { $this->messageManager->addError(__('The order does not allow an invoice to be created.')); return false; } $savedQtys = array(); $data = $request->getParam('invoice'); if (isset($data['items'])) { $savedQtys = $data['items']; } $invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Service\\Order', array('order' => $order))->prepareInvoice($savedQtys); if (!$invoice->getTotalQty()) { throw new \Exception(__('Cannot create an invoice without products.')); } } $this->registry->register('current_invoice', $invoice); return $invoice; }
/** * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute(Observer $observer) { $request = $observer->getEvent()->getRequest(); $sharedWishlist = $this->checkoutSession->getSharedWishlist(); $messages = $this->checkoutSession->getWishlistPendingMessages(); $urls = $this->checkoutSession->getWishlistPendingUrls(); $wishlistIds = $this->checkoutSession->getWishlistIds(); $singleWishlistId = $this->checkoutSession->getSingleWishlistId(); if ($singleWishlistId) { $wishlistIds = [$singleWishlistId]; } if (count($wishlistIds) && $request->getParam('wishlist_next')) { $wishlistId = array_shift($wishlistIds); if ($this->customerSession->isLoggedIn()) { $wishlist = $this->wishlistFactory->create()->loadByCustomerId($this->customerSession->getCustomerId(), true); } elseif ($sharedWishlist) { $wishlist = $this->wishlistFactory->create()->loadByCode($sharedWishlist); } else { return; } $wishlists = $wishlist->getItemCollection()->load(); foreach ($wishlists as $wishlistItem) { if ($wishlistItem->getId() == $wishlistId) { $wishlistItem->delete(); } } $this->checkoutSession->setWishlistIds($wishlistIds); $this->checkoutSession->setSingleWishlistId(null); } if ($request->getParam('wishlist_next') && count($urls)) { $url = array_shift($urls); $message = array_shift($messages); $this->checkoutSession->setWishlistPendingUrls($urls); $this->checkoutSession->setWishlistPendingMessages($messages); $this->messageManager->addError($message); $observer->getEvent()->getResponse()->setRedirect($url); $this->checkoutSession->setNoCartRedirect(true); } }
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { $installer = $setup; $installer->startSetup(); $attributeSetCollection = $this->eavEntitiyType->loadByCode('catalog_product')->getAttributeSetCollection(); $entityTypeId = $this->eavEntitiyType->loadByCode('catalog_product')->getId(); $model = $this->attributeFactory->create(); $data['attribute_code'] = 'is_featured'; $data['is_user_defined'] = 1; $data['frontend_input'] = 'boolean'; $data += ['is_filterable' => 0, 'is_filterable_in_search' => 0, 'apply_to' => []]; $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']); $data['default_value'] = 0; $data['frontend_label'] = 'Is Featured'; $model->addData($data); $model->setEntityTypeId($entityTypeId); $model->setIsUserDefined(1); try { foreach ($attributeSetCollection as $attributeSet) { $attributeSetId = $attributeSet->getId(); $groupCollection = $this->groupCollectionFactory->create()->setAttributeSetFilter($attributeSetId)->load(); $groupCode = 'product-details'; $attributeGroupId = null; foreach ($groupCollection as $group) { if ($group->getAttributeGroupCode() == $groupCode) { $attributeGroupId = $group->getAttributeGroupId(); break; } } $model->setAttributeSetId($attributeSetId); $model->setAttributeGroupId($attributeGroupId); $model->save(); } } catch (\Exception $e) { echo $this->messageManager->addError($e->getMessage()); } $installer->endSetup(); }