/** * @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')); } }
/** * {@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; }
/** * @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')); } }
public function execute() { try { $order = $this->_getCheckoutSession()->getLastRealOrder(); $method = $order->getPayment()->getMethod(); $methodInstance = $this->_paymentHelper->getMethodInstance($method); if ($methodInstance instanceof \Paynl\Payment\Model\Paymentmethod\Paymentmethod) { $redirectUrl = $methodInstance->startTransaction($order, $this->_url); $this->_redirect($redirectUrl); } else { throw new Error('Method is not a paynl payment method'); } } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong, please try again later')); $this->_logger->critical($e); $this->_getCheckoutSession()->restoreQuote(); $this->_redirect('checkout/cart'); } }
/** * @param \Magento\Framework\Event\Observer $observer * @throws \Exception */ public function execute(\Magento\Framework\Event\Observer $observer) { $orderIds = $observer->getEvent()->getData('order_ids'); if (isset($orderIds[0])) { $order = $this->orderRepository->get($orderIds[0]); if (!$order->getCustomerId()) { $isEmailAvailable = $this->accountManagement->isEmailAvailable($order->getCustomerEmail()); //$this->logger->addInfo(print_r($isEmailAvailable,true)); if ($isEmailAvailable) { try { $this->orderCustomerService->create($orderIds[0]); } catch (\Exception $e) { $this->messageManager->addException($e, $e->getMessage()); throw $e; } $this->coreRegistry->register('automatic_account', true); } } } }
public function execute() { try { /** @var \Magento\Checkout\Model\Type\Onepage $onepage */ $onepage = $this->_objectManager->get('Magento\\Checkout\\Model\\Type\\Onepage'); /** @var \Magento\Quote\Model\Quote $quote */ $quote = $onepage->getQuote(); $quote->collectTotals(); $quote->reserveOrderId(); $orderId = $quote->getReservedOrderId(); $payment = $quote->getPayment()->getMethodInstance(); $total = $quote->getGrandTotal(); $items = $quote->getAllVisibleItems(); $currency = $quote->getQuoteCurrencyCode(); $returnUrl = $this->_url->getUrl('paynl/finish/'); $exchangeUrl = $this->_url->getUrl('paynl/exchange/'); $paymentOptionId = $payment->getPaymentOptionId(); $arrBillingAddress = $quote->getBillingAddress()->toArray(); $arrShippingAddress = $quote->getShippingAddress()->toArray(); $enduser = array('initials' => substr($arrBillingAddress['firstname'], 0, 1), 'lastName' => $arrBillingAddress['lastname'], 'phoneNumber' => $arrBillingAddress['telephone'], 'emailAddress' => $arrBillingAddress['email']); $address = array(); $arrAddress = \Paynl\Helper::splitAddress($arrBillingAddress['street']); $address['streetName'] = $arrAddress[0]; $address['houseNumber'] = $arrAddress[1]; $address['zipCode'] = $arrBillingAddress['postcode']; $address['city'] = $arrBillingAddress['city']; $address['country'] = $arrBillingAddress['country_id']; $shippingAddress = array(); $arrAddress2 = \Paynl\Helper::splitAddress($arrShippingAddress['street']); $shippingAddress['streetName'] = $arrAddress2[0]; $shippingAddress['houseNumber'] = $arrAddress2[1]; $shippingAddress['zipCode'] = $arrShippingAddress['postcode']; $shippingAddress['city'] = $arrShippingAddress['city']; $shippingAddress['country'] = $arrShippingAddress['country_id']; $data = array('amount' => $total, 'returnUrl' => $returnUrl, 'paymentMethod' => $paymentOptionId, 'description' => $orderId, 'extra1' => $orderId, 'extra1' => $quote->getId(), 'exchangeUrl' => $exchangeUrl, 'currency' => $currency); $data['address'] = $address; $data['shippingAddress'] = $shippingAddress; $data['enduser'] = $enduser; $arrProducts = array(); foreach ($items as $item) { $arrItem = $item->toArray(); if ($arrItem['price_incl_tax'] != null) { $product = array('id' => $arrItem['product_id'], 'name' => $arrItem['name'], 'price' => $arrItem['price_incl_tax'], 'qty' => $arrItem['qty'], 'tax' => $arrItem['tax_amount']); } $arrProducts[] = $product; } //shipping $shippingCost = $quote->getShippingAddress()->getShippingInclTax(); $shippingTax = $quote->getShippingAddress()->getShippingTaxAmount(); $shippingDescription = $quote->getShippingAddress()->getShippingDescription(); $arrProducts[] = array('id' => 'shipping', 'name' => $shippingDescription, 'price' => $shippingCost, 'qty' => 1, 'tax' => $shippingTax); // kortingen $discount = $quote->getSubtotal() - $quote->getSubtotalWithDiscount(); if ($discount > 0) { $arrProducts[] = array('id' => 'discount', 'name' => __('Discount'), 'price' => $discount * -1, 'qty' => 1, 'tax' => 0); } $data['products'] = $arrProducts; if ($this->_config->isTestMode()) { $data['testmode'] = 1; } $data['ipaddress'] = $quote->getRemoteIp(); \Paynl\Config::setApiToken($this->_config->getApiToken()); \Paynl\Config::setServiceId($this->_config->getServiceId()); $transaction = \Paynl\Transaction::start($data); $onepage->saveOrder(); $this->_redirect($transaction->getRedirectUrl()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong, please try again later')); $this->_redirect('checkout/cart'); } }