/**
  * Return mp discount
  *
  * @return float|int
  */
 protected function _getDiscountAmount()
 {
     $quote = $this->_checkoutSession->getQuote();
     $totals = $quote->getShippingAddress()->getTotals();
     $discount = isset($totals['discount_coupon']) ? $totals['discount_coupon']['value'] : 0;
     return $discount;
 }
 /**
  * Push trackEcommerceCartUpdate to tracker on cart view page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Henhed\Piwik\Observer\CartViewObserver
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_dataHelper->isTrackingEnabled()) {
         $this->_trackerHelper->addQuote($this->_checkoutSession->getQuote(), $this->_piwikTracker);
     }
     return $this;
 }
Example #3
0
 /**
  * Retrieve payment info model
  *
  * @return \Magento\Payment\Model\Info|false
  */
 public function getPaymentInfo()
 {
     $info = $this->_checkoutSession->getQuote()->getPayment();
     if ($info->getMethod()) {
         return $info;
     }
     return false;
 }
Example #4
0
 /**
  * Returns an array of SKUs of items in the basket
  *
  * @return array
  */
 protected function _getQuoteItems()
 {
     $skus = [];
     foreach ($this->_checkoutSession->getQuote()->getAllVisibleItems() as $item) {
         $skus[] = $item->getProduct()->getData('sku');
     }
     return $skus;
 }
 /**
  * @param \Magento\Checkout\Model\DefaultConfigProvider $subject
  * @param array $result
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result)
 {
     if ($this->persistentHelper->isEnabled() && $this->persistentSession->isPersistent() && !$this->customerSession->isLoggedIn()) {
         /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
         $quoteIdMask = $this->quoteIdMaskFactory->create();
         $result['quoteData']['entity_id'] = $quoteIdMask->load($this->checkoutSession->getQuote()->getId(), 'quote_id')->getMaskedId();
     }
     return $result;
 }
 /**
  * Fetch coupon info
  *
  * Controller Action
  */
 public function execute()
 {
     $total = $this->getRequest()->getParam('cost');
     $quote = $this->_checkoutSession->getQuote();
     //save value to DiscountCoupon collect
     $this->_registry->register('mercadopago_total_amount', $total);
     $this->quoteRepository->save($quote->collectTotals());
     return;
 }
 /**
  *  Validates minimum quote amount and zero grand total
  *
  * @param bool $isInCatalog
  * @return bool
  */
 public function isQuoteSummaryValid($isInCatalog)
 {
     $quote = $isInCatalog ? null : $this->_checkoutSession->getQuote();
     // validate minimum quote amount and validate quote for zero grandtotal
     if (null !== $quote && (!$quote->validateMinimumAmount() || !$quote->getGrandTotal())) {
         return false;
     }
     return true;
 }
Example #8
0
 /**
  * Dispatch request
  *
  * @return \Magento\Framework\Controller\ResultInterface
  * @throws Action\NotFoundException
  */
 public function execute()
 {
     $quote = $this->checkoutSession->getQuote();
     $address = $quote->getShippingAddress();
     $address->collectShippingRates()->save();
     $rates = $address->getGroupedAllShippingRates();
     $result = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON);
     $result->setData($rates);
     return $result;
 }
 /**
  * @param \Magento\Framework\View\Element\Template\Context $context
  * @param \Magento\Checkout\Model\Session $checkoutSession
  * @param \Yireo\GoogleTagManager2\Helper\Data $helper
  * @param \Yireo\GoogleTagManager2\Model\Container $container
  * @param array $data
  */
 public function __construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Checkout\Model\Session $checkoutSession, \Yireo\GoogleTagManager2\Helper\Data $helper, \Yireo\GoogleTagManager2\Model\Container $container, array $data = [])
 {
     $this->helper = $helper;
     $this->container = $container;
     $this->checkoutSession = $checkoutSession;
     $this->order = $this->checkoutSession->getLastRealOrder();
     $this->quote = $this->checkoutSession->getQuote();
     parent::__construct($context, $data);
     $this->storeManager = $this->_storeManager;
     $this->layout = $this->_layout;
 }
Example #10
0
 /**
  * Get template for button in order review page if HSS method was selected
  *
  * @param string $name template name
  * @return string
  */
 public function getReviewButtonTemplate($name)
 {
     $quote = $this->_checkoutSession->getQuote();
     if ($quote) {
         $payment = $quote->getPayment();
         if ($payment && in_array($payment->getMethod(), $this->_hssMethods)) {
             return $name;
         }
     }
     return '';
 }
Example #11
0
 /**
  * @magentoDataFixture Magento/Paypal/_files/quote_payment_standard.php
  * @magentoConfigFixture current_store payment/paypal_standard/active 1
  * @magentoConfigFixture current_store paypal/general/business_account merchant_2012050718_biz@example.com
  */
 public function testCancelAction()
 {
     $quote = $this->_objectManager->create('Magento\\Sales\\Model\\Quote');
     $quote->load('test01', 'reserved_order_id');
     $this->_session->setQuoteId($quote->getId());
     $this->_session->setPaypalStandardQuoteId($quote->getId())->setLastRealOrderId('100000002');
     $this->dispatch('paypal/standard/cancel');
     $this->_order->load('100000002', 'increment_id');
     $this->assertEquals('canceled', $this->_order->getState());
     $this->assertEquals($this->_session->getQuote()->getGrandTotal(), $quote->getGrandTotal());
     $this->assertEquals($this->_session->getQuote()->getItemsCount(), $quote->getItemsCount());
 }
 /**
  * Add `trackEcommerceCartUpdate' checkout cart customer data
  *
  * @param \Magento\Checkout\CustomerData\Cart $subject
  * @param array $result
  * @return array
  */
 public function afterGetSectionData(\Magento\Checkout\CustomerData\Cart $subject, $result)
 {
     if ($this->_dataHelper->isTrackingEnabled()) {
         $quote = $this->_checkoutSession->getQuote();
         if ($quote->getId()) {
             $tracker = $this->_trackerFactory->create();
             $this->_trackerHelper->addQuote($quote, $tracker);
             $result['piwikActions'] = $tracker->toArray();
         }
     }
     return $result;
 }
 /**
  * Check whether authentication is required and prepare some template data
  *
  * @return string
  */
 protected function _toHtml()
 {
     $method = $this->_checkoutSession->getQuote()->getPayment()->getMethodInstance();
     if ($method->getIsCentinelValidationEnabled()) {
         $centinel = $method->getCentinelValidator();
         if ($centinel && $centinel->shouldAuthenticate()) {
             $this->setAuthenticationStart(true);
             $this->setFrameUrl($centinel->getAuthenticationStartUrl());
             return parent::_toHtml();
         }
     }
     return parent::_toHtml();
 }
 /**
  * @return ResultInterface
  * @throws LocalizedException
  */
 public function execute()
 {
     $isAjax = $this->_request->getParam('isAjax');
     if (!$isAjax) {
         throw new LocalizedException(__('Wrong type of request.'));
     }
     $items = $this->checkoutSession->getQuote()->getAllItems();
     $response = ['isEmpty' => 0 === count($items), 'amount' => $this->checkoutSession->getQuote()->getBaseGrandTotal(), 'currency' => $this->checkoutSession->getQuote()->getCurrency()->getBaseCurrencyCode()];
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
     $resultJson->setData($response);
     return $resultJson;
 }
 /**
  * @return array
  */
 public function getConfig()
 {
     $customFeeConfig = [];
     $enabled = $this->dataHelper->isModuleEnabled();
     $minimumOrderAmount = $this->dataHelper->getMinimumOrderAmount();
     $customFeeConfig['fee_label'] = $this->dataHelper->getFeeLabel();
     $quote = $this->checkoutSession->getQuote();
     $subtotal = $quote->getSubtotal();
     $customFeeConfig['custom_fee_amount'] = $this->dataHelper->getCustomFee();
     $customFeeConfig['show_hide_customfee_block'] = $enabled && $minimumOrderAmount <= $subtotal && $quote->getFee() ? true : false;
     $customFeeConfig['show_hide_customfee_shipblock'] = $enabled && $minimumOrderAmount <= $subtotal ? true : false;
     return $customFeeConfig;
 }
 /**
  * Load already specified item level gift messages.
  *
  * @return \Magento\GiftMessage\Api\Data\MessageInterface[]|null
  */
 protected function getItemLevelGiftMessages()
 {
     $itemMessages = [];
     $cartId = $this->checkoutSession->getQuoteId();
     $items = $this->checkoutSession->getQuote()->getAllVisibleItems();
     foreach ($items as $item) {
         $itemId = $item->getId();
         $message = $this->itemRepository->get($cartId, $itemId);
         if ($message) {
             $itemMessages[$itemId] = $message->getData();
         }
     }
     return count($itemMessages) === 0 ? null : $itemMessages;
 }
 /**
  * @inheritdoc
  */
 public function getConfig()
 {
     /**
      * @var $payment Payupl
      */
     $config = [];
     $payment = $this->paymentHelper->getMethodInstance(Payupl::CODE);
     if ($payment->isAvailable()) {
         $redirectUrl = $payment->getCheckoutRedirectUrl();
         $quote = $this->checkoutSession->getQuote();
         $config = ['payment' => ['orbaPayupl' => ['redirectUrl' => $redirectUrl, 'paytypes' => $this->paytypeHelper->getAllForQuote($quote)]]];
     }
     return $config;
 }
Example #18
0
 /**
  * Get template for button in order review page if HSS method was selected
  *
  * @param string $name template name
  * @param string $block buttons block name
  * @return string
  */
 public function getReviewButtonTemplate($name, $block)
 {
     $quote = $this->_checkoutSession->getQuote();
     if ($quote) {
         $payment = $quote->getPayment();
         if ($payment && in_array($payment->getMethod(), $this->_hssMethods)) {
             return $name;
         }
     }
     $blockObject = $this->_layout->getBlock($block);
     if ($blockObject) {
         return $blockObject->getTemplate();
     }
     return '';
 }
Example #19
0
 /**
  * @param \Magento\Checkout\Controller\Cart $subject
  * @param \Magento\Framework\App\RequestInterface $request
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeDispatch(\Magento\Checkout\Controller\Cart $subject, \Magento\Framework\App\RequestInterface $request)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->checkoutSession->getQuote();
     // Clear shipping addresses and item assignments after Multishipping flow
     if ($quote->isMultipleShippingAddresses()) {
         foreach ($quote->getAllShippingAddresses() as $address) {
             $quote->removeAddress($address->getId());
         }
         $quote->getShippingAddress();
         $quote->setIsMultiShipping(false);
         $quote->collectTotals();
         $this->cartRepository->save($quote);
     }
 }
Example #20
0
 /**
  * Quote object getter
  *
  * @return \Magento\Quote\Model\Quote
  */
 public function getQuote()
 {
     if ($this->_quote === null) {
         return $this->_checkoutSession->getQuote();
     }
     return $this->_quote;
 }
Example #21
0
 /**
  * @return int
  */
 public function getCartItemsCount()
 {
     if (!$this->_cartItemsCount) {
         $this->_cartItemsCount = $this->_createQuote()->setId($this->_checkoutSession->getQuote()->getId())->getItemsCollection()->getSize();
     }
     return $this->_cartItemsCount;
 }
Example #22
0
 /**
  * @return \Magento\Braintree\Model\Checkout
  */
 protected function getCheckout()
 {
     if (!$this->checkout) {
         $this->checkout = $this->checkoutFactory->create(['params' => ['quote' => $this->checkoutSession->getQuote(), 'config' => $this->paypalConfig]]);
     }
     return $this->checkout;
 }
 /**
  * Easy email capture for Newsletter and Checkout.
  */
 public function execute()
 {
     if ($this->getRequest()->getParam('email') && ($quote = $this->checkoutSession->getQuote())) {
         $email = $this->getRequest()->getParam('email');
         if ($quote->hasItems()) {
             try {
                 $quote->setCustomerEmail($email);
                 $quote->getResource()->save($quote);
                 $this->helper->log('ajax emailCapture email: ' . $email);
             } catch (\Exception $e) {
                 $this->helper->debug((string) $e, []);
                 $this->helper->log('ajax emailCapture fail for email: ' . $email);
             }
         }
     }
 }
 public function getAdyenOneclickPaymentMethods()
 {
     $billingAgreements = [];
     if ($this->_customerSession->isLoggedIn()) {
         $customerId = $this->_customerSession->getCustomerId();
         // is admin?
         if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
             //retrieve storeId from quote
             $store = $this->_session->getQuote()->getStore();
         } else {
             $store = $this->_storeManager->getStore();
         }
         $baCollection = $this->_billingAgreementCollectionFactory->create();
         $baCollection->addFieldToFilter('customer_id', $customerId);
         $baCollection->addFieldToFilter('store_id', $store->getId());
         $baCollection->addFieldToFilter('method_code', 'adyen_oneclick');
         $baCollection->addActiveFilter();
         $recurringPaymentType = $this->_getRecurringContractType();
         foreach ($baCollection as $billingAgreement) {
             $agreementData = $billingAgreement->getAgreementData();
             // check if AgreementLabel is set and if contract has an recurringType
             if ($billingAgreement->getAgreementLabel()) {
                 $data = ['reference_id' => $billingAgreement->getReferenceId(), 'agreement_label' => $billingAgreement->getAgreementLabel(), 'agreement_data' => $agreementData];
                 $billingAgreements[] = $data;
             }
         }
     }
     return $billingAgreements;
 }
Example #25
0
 /**
  * Retrieve sales quote model
  *
  * @return Quote
  */
 public function getQuote()
 {
     if (empty($this->quote)) {
         $this->quote = $this->checkoutSession->getQuote();
     }
     return $this->quote;
 }
Example #26
0
 /**
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function _beforeToHtml()
 {
     $result = parent::_beforeToHtml();
     /** @var \Magento\Paypal\Model\Config $config */
     $config = $this->_paypalConfigFactory->create();
     $config->setMethod($this->_paymentMethodCode);
     $isInCatalog = $this->getIsInCatalogProduct();
     if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
         $this->_shouldRender = false;
         return $result;
     }
     $quote = $isInCatalog || !$this->_checkoutSession ? null : $this->_checkoutSession->getQuote();
     // set misc data
     $this->setShortcutHtmlId($this->_mathRandom->getUniqueHash('ec_shortcut_'))->setCheckoutUrl($this->getUrl($this->_startAction));
     // use static image if in catalog
     if ($isInCatalog || null === $quote) {
         $this->setImageUrl($config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale()));
     } else {
         /**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */
         $parameters = ['params' => ['quote' => $quote, 'config' => $config]];
         $checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
         $this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl());
     }
     // ask whether to create a billing agreement
     $customerId = $this->currentCustomer->getCustomerId();
     // potential issue for caching
     if ($this->_paypalData->shouldAskToCreateBillingAgreement($config, $customerId)) {
         $this->setConfirmationUrl($this->getUrl($this->_startAction, [\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => 1]));
         $this->setConfirmationMessage(__('Would you like to sign a billing agreement to streamline further purchases with PayPal?'));
     }
     return $result;
 }
Example #27
0
 /**
  * Retrieve checkout quote model object
  *
  * @return Mage_Sales_Model_Quote
  */
 public function getQuote()
 {
     if ($this->quote !== null) {
         return $this->quote;
     }
     $this->quote = $this->checkoutSession->getQuote();
     return $this->quote;
 }
Example #28
0
 /**
  * Emulate quote by persistent data
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute($observer)
 {
     $stopActions = ['persistent_index_saveMethod', 'customer_account_createpost'];
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent() || $this->_customerSession->isLoggedIn()) {
         return;
     }
     $actionName = $observer->getEvent()->getRequest()->getFullActionName();
     if (in_array($actionName, $stopActions)) {
         return;
     }
     if ($this->_persistentData->isShoppingCartPersist()) {
         $this->_checkoutSession->setCustomerData($this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId()));
         if (!$this->_checkoutSession->hasQuote()) {
             $this->_checkoutSession->getQuote();
         }
     }
 }
Example #29
0
 /**
  * Don't display the shortcut button if customer is not logged in and guest mode is not allowed
  *
  * @return bool
  */
 public function skipShortcutForGuest()
 {
     if ($this->customerSession->isLoggedIn()) {
         return false;
     }
     if ($this->checkoutData->isAllowedGuestCheckout($this->checkoutSession->getQuote())) {
         return false;
     }
     return true;
 }
Example #30
0
 /**
  * Fetch coupon info
  *
  * Controller Action
  */
 public function execute()
 {
     $coupon_id = $this->getRequest()->getParam('id');
     if (!empty($coupon_id)) {
         $response = $this->coreModel->validCoupon($coupon_id);
     } else {
         $response = $this->getArrayErrorResponse();
     }
     if ($response['status'] != 200 && $response['status'] != 201) {
         $response = $this->getArrayErrorResponse();
     }
     //save value to DiscountCoupon collect
     $this->_registry->register('mercadopago_discount_amount', (double) $response['response']['coupon_amount']);
     $quote = $this->_checkoutSession->getQuote();
     $this->quoteRepository->save($quote->collectTotals());
     $jsonData = json_encode($response);
     $this->getResponse()->setHeader('Content-type', 'application/json');
     $this->getResponse()->setBody($jsonData);
 }