/** * Add success message * * @return void */ private function addSuccessMessage() { $params = $this->getParams(); if (isset($params['redirect_parent'])) { $this->messageManager->addSuccess(__('You created the order.')); } }
protected function updateWireProduct($_product, $actionName = '') { // get the products SKU $_sku = $this->getSKU($_product); if ($_sku) { if ($actionName) { $actionName = $actionName . ' - '; } $message = $actionName . "syncing product with Processwire - sku: " . $_sku; $this->_messageManager->addSuccess($message); $this->_logger->info($message); } }
/** * 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); } } }
/** * Ping AvaTax using configured live/production mode * * @param $scopeId * @param $scopeType * @return array */ protected function sendPing($scopeId, $scopeType) { $errors = []; if (!$this->config->isModuleEnabled($scopeId, $scopeType)) { return $errors; } $message = ''; $type = $this->config->getLiveMode() ? Config::API_PROFILE_NAME_PROD : Config::API_PROFILE_NAME_DEV; try { $result = $this->interactionTax->getTaxService($type, $scopeId, $scopeType)->ping(); if (is_object($result) && $result->getResultCode() != \AvaTax\SeverityLevel::$Success) { foreach ($result->getMessages() as $messages) { $message .= $messages->getName() . ': ' . $messages->getSummary() . "\n"; } } elseif (is_object($result) && $result->getResultCode() == \AvaTax\SeverityLevel::$Success) { $this->messageManager->addSuccess(__('Successfully connected to AvaTax using the ' . '<a href="#row_tax_avatax_connection_settings_header">%1 credentials</a>', $type)); } } catch (\Exception $exception) { $message = $exception->getMessage(); } if ($message) { $errors[] = __('Error connecting to AvaTax using the ' . '<a href="#row_tax_avatax_connection_settings_header">%1 credentials</a>: %2', $type, $message); } return $errors; }
/** * Add success message for valid VAT ID * * @param Address $customerAddress * @param DataObject $validationResult * @return $this */ protected function addValidMessage($customerAddress, $validationResult) { $message = [(string) __('Your VAT ID was successfully validated.')]; $customer = $customerAddress->getCustomer(); if (!$this->scopeConfig->isSetFlag(HelperAddress::XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT) && !$customer->getDisableAutoGroupChange()) { $customerVatClass = $this->_customerVat->getCustomerVatClass($customerAddress->getCountryId(), $validationResult); $message[] = $customerVatClass == Vat::VAT_CLASS_DOMESTIC ? (string) __('You will be charged tax.') : (string) __('You will not be charged tax.'); } $this->messageManager->addSuccess(implode(' ', $message)); return $this; }
/** * Involve new customer to system * * @return $this */ protected function _involveNewCustomer() { $customer = $this->getQuote()->getCustomer(); $confirmationStatus = $this->accountManagement->getConfirmationStatus($customer->getId()); if ($confirmationStatus === \Magento\Customer\Model\AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED) { $url = $this->_customerUrl->getEmailConfirmationUrl($customer->getEmail()); $this->messageManager->addSuccess(__('You must confirm your account. Please check your email for the confirmation link or <a href="%1">click here</a> for a new link.', $url)); } else { $this->getCustomerSession()->loginById($customer->getId()); } return $this; }
/** * Involve new customer to system * * @return $this */ protected function _involveNewCustomer() { $customer = $this->_quote->getCustomerData(); $confirmationStatus = $this->_customerAccountService->getConfirmationStatus($customer->getId()); if ($confirmationStatus === CustomerAccountServiceInterface::ACCOUNT_CONFIRMATION_REQUIRED) { $url = $this->_customerData->getEmailConfirmationUrl($customer->getEmail()); $this->_messageManager->addSuccess(__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%1">click here</a>.', $url)); } else { $this->getCustomerSession()->regenerateId(); $this->getCustomerSession()->loginById($customer->getId()); } return $this; }
/** * Involve new customer to system * * @return $this */ protected function _involveNewCustomer() { $customer = $this->_quote->getCustomer(); $confirmationStatus = $this->_accountManagement->getConfirmationStatus($customer->getId()); if ($confirmationStatus === AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED) { $this->_messageManager->addSuccess(__('Thank you for registering with Main Website Store.')); } else { $this->getCustomerSession()->regenerateId(); $this->getCustomerSession()->loginById($customer->getId()); } return $this; }
/** * Move all wishlist item to cart * * @param Wishlist $wishlist * @param array $qtys * @return string * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function moveAllToCart(Wishlist $wishlist, $qtys) { $isOwner = $wishlist->isOwner($this->customerSession->getCustomerId()); $messages = []; $addedItems = []; $notSalable = []; $hasOptions = []; $cart = $this->cart; $collection = $wishlist->getItemCollection()->setVisibilityFilter(); foreach ($collection as $item) { /** @var \Magento\Wishlist\Model\Item */ try { $disableAddToCart = $item->getProduct()->getDisableAddToCart(); $item->unsProduct(); // Set qty if (isset($qtys[$item->getId()])) { $qty = $this->quantityProcessor->process($qtys[$item->getId()]); if ($qty) { $item->setQty($qty); } } $item->getProduct()->setDisableAddToCart($disableAddToCart); // Add to cart if ($item->addToCart($cart, $isOwner)) { $addedItems[] = $item->getProduct(); } } catch (\Magento\Framework\Exception\LocalizedException $e) { if ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_NOT_SALABLE) { $notSalable[] = $item; } elseif ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) { $hasOptions[] = $item; } else { $messages[] = __('%1 for "%2".', trim($e->getMessage(), '.'), $item->getProduct()->getName()); } $cartItem = $cart->getQuote()->getItemByProduct($item->getProduct()); if ($cartItem) { $cart->getQuote()->deleteItem($cartItem); } } catch (\Exception $e) { $this->logger->critical($e); $messages[] = __('We cannot add this item to your shopping cart.'); } } if ($isOwner) { $indexUrl = $this->helper->getListUrl($wishlist->getId()); } else { $indexUrl = $this->urlBuilder->getUrl('wishlist/shared', ['code' => $wishlist->getSharingCode()]); } if ($this->cartHelper->getShouldRedirectToCart()) { $redirectUrl = $this->cartHelper->getCartUrl(); } elseif ($this->redirector->getRefererUrl()) { $redirectUrl = $this->redirector->getRefererUrl(); } else { $redirectUrl = $indexUrl; } if ($notSalable) { $products = []; foreach ($notSalable as $item) { $products[] = '"' . $item->getProduct()->getName() . '"'; } $messages[] = __('We couldn\'t add the following product(s) to the shopping cart: %1.', join(', ', $products)); } if ($hasOptions) { $products = []; foreach ($hasOptions as $item) { $products[] = '"' . $item->getProduct()->getName() . '"'; } $messages[] = __('Product(s) %1 have required options. Each product can only be added individually.', join(', ', $products)); } if ($messages) { $isMessageSole = count($messages) == 1; if ($isMessageSole && count($hasOptions) == 1) { $item = $hasOptions[0]; if ($isOwner) { $item->delete(); } $redirectUrl = $item->getProductUrl(); } else { foreach ($messages as $message) { $this->messageManager->addError($message); } $redirectUrl = $indexUrl; } } if ($addedItems) { // save wishlist model for setting date of last update try { $wishlist->save(); } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t update wish list.')); $redirectUrl = $indexUrl; } $products = []; foreach ($addedItems as $product) { $products[] = '"' . $product->getName() . '"'; } $this->messageManager->addSuccess(__('%1 product(s) have been added to shopping cart: %2.', count($addedItems), join(', ', $products))); // save cart and collect totals $cart->save()->getQuote()->collectTotals(); } $this->helper->calculate(); return $redirectUrl; }
public function addSuccess($message, $popupText = null, $popupTitle = null) { $popupId = $this->addPopup($popupText, $popupTitle); $this->messageManager->addSuccess($this->getMessageText($message, $popupId)); }
/** * Move all wishlist item to cart * * @param Wishlist $wishlist * @param array $qtys * @return string * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function moveAllToCart(Wishlist $wishlist, $qtys) { $isOwner = $wishlist->isOwner($this->customerSession->getCustomerId()); $messages = []; $addedProducts = []; $notSalable = []; $cart = $this->cart; $collection = $wishlist->getItemCollection()->setVisibilityFilter(); foreach ($collection as $item) { /** @var $item \Magento\Wishlist\Model\Item */ try { $disableAddToCart = $item->getProduct()->getDisableAddToCart(); $item->unsProduct(); // Set qty if (isset($qtys[$item->getId()])) { $qty = $this->quantityProcessor->process($qtys[$item->getId()]); if ($qty) { $item->setQty($qty); } } $item->getProduct()->setDisableAddToCart($disableAddToCart); // Add to cart if ($item->addToCart($cart, $isOwner)) { $addedProducts[] = $item->getProduct(); } } catch (LocalizedException $e) { if ($e instanceof ProductException) { $notSalable[] = $item; } else { $messages[] = __('%1 for "%2".', trim($e->getMessage(), '.'), $item->getProduct()->getName()); } $cartItem = $cart->getQuote()->getItemByProduct($item->getProduct()); if ($cartItem) { $cart->getQuote()->deleteItem($cartItem); } } catch (\Exception $e) { $this->logger->critical($e); $messages[] = __('We can\'t add this item to your shopping cart right now.'); } } if ($isOwner) { $indexUrl = $this->helper->getListUrl($wishlist->getId()); } else { $indexUrl = $this->urlBuilder->getUrl('wishlist/shared', ['code' => $wishlist->getSharingCode()]); } if ($this->cartHelper->getShouldRedirectToCart()) { $redirectUrl = $this->cartHelper->getCartUrl(); } elseif ($this->redirector->getRefererUrl()) { $redirectUrl = $this->redirector->getRefererUrl(); } else { $redirectUrl = $indexUrl; } if ($notSalable) { $products = []; foreach ($notSalable as $item) { $products[] = '"' . $item->getProduct()->getName() . '"'; } $messages[] = __('We couldn\'t add the following product(s) to the shopping cart: %1.', join(', ', $products)); } if ($messages) { foreach ($messages as $message) { $this->messageManager->addError($message); } $redirectUrl = $indexUrl; } if ($addedProducts) { // save wishlist model for setting date of last update try { $wishlist->save(); } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t update the Wish List right now.')); $redirectUrl = $indexUrl; } $products = []; foreach ($addedProducts as $product) { /** @var $product \Magento\Catalog\Model\Product */ $products[] = '"' . $product->getName() . '"'; } $this->messageManager->addSuccess(__('%1 product(s) have been added to shopping cart: %2.', count($addedProducts), join(', ', $products))); // save cart and collect totals $cart->save()->getQuote()->collectTotals(); } $this->helper->calculate(); return $redirectUrl; }