Exemplo n.º 1
1
 /**
  * Fetch quote totals data
  *
  * @param Quote $quote
  * @return array
  */
 public function map(Quote $quote)
 {
     $totals = [Totals::BASE_GRAND_TOTAL => $quote->getBaseGrandTotal(), Totals::GRAND_TOTAL => $quote->getGrandTotal(), Totals::BASE_SUBTOTAL => $quote->getBaseSubtotal(), Totals::SUBTOTAL => $quote->getSubtotal(), Totals::BASE_SUBTOTAL_WITH_DISCOUNT => $quote->getBaseSubtotalWithDiscount(), Totals::SUBTOTAL_WITH_DISCOUNT => $quote->getSubtotalWithDiscount(), Totals::BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), Totals::QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode()];
     $shippingAddress = $quote->getShippingAddress();
     $totals[Totals::DISCOUNT_AMOUNT] = $shippingAddress->getDiscountAmount();
     $totals[Totals::BASE_DISCOUNT_AMOUNT] = $shippingAddress->getBaseDiscountAmount();
     $totals[Totals::SHIPPING_AMOUNT] = $shippingAddress->getShippingAmount();
     $totals[Totals::BASE_SHIPPING_AMOUNT] = $shippingAddress->getBaseShippingAmount();
     $totals[Totals::SHIPPING_DISCOUNT_AMOUNT] = $shippingAddress->getShippingDiscountAmount();
     $totals[Totals::BASE_SHIPPING_DISCOUNT_AMOUNT] = $shippingAddress->getBaseShippingDiscountAmount();
     $totals[Totals::TAX_AMOUNT] = $shippingAddress->getTaxAmount();
     $totals[Totals::BASE_TAX_AMOUNT] = $shippingAddress->getBaseTaxAmount();
     $totals[Totals::SHIPPING_TAX_AMOUNT] = $shippingAddress->getShippingTaxAmount();
     $totals[Totals::BASE_SHIPPING_TAX_AMOUNT] = $shippingAddress->getBaseShippingTaxAmount();
     $totals[Totals::SUBTOTAL_INCL_TAX] = $shippingAddress->getSubtotalInclTax();
     $totals[Totals::BASE_SUBTOTAL_INCL_TAX] = $shippingAddress->getBaseSubtotalTotalInclTax();
     $totals[Totals::SHIPPING_INCL_TAX] = $shippingAddress->getShippingInclTax();
     $totals[Totals::BASE_SHIPPING_INCL_TAX] = $shippingAddress->getBaseShippingInclTax();
     return $totals;
 }
Exemplo n.º 2
0
 /**
  * Retrieve payment method and assign additional template values
  *
  * @return $this
  */
 protected function _beforeToHtml()
 {
     $methodInstance = $this->_quote->getPayment()->getMethodInstance();
     $this->setPaymentMethodTitle($methodInstance->getTitle());
     $this->setShippingRateRequired(true);
     if ($this->_quote->getIsVirtual()) {
         $this->setShippingRateRequired(false);
     } else {
         // prepare shipping rates
         $this->_address = $this->_quote->getShippingAddress();
         $groups = $this->_address->getGroupedAllShippingRates();
         if ($groups && $this->_address) {
             $this->setShippingRateGroups($groups);
             // determine current selected code & name
             foreach ($groups as $code => $rates) {
                 foreach ($rates as $rate) {
                     if ($this->_address->getShippingMethod() == $rate->getCode()) {
                         $this->_currentShippingRate = $rate;
                         break 2;
                     }
                 }
             }
         }
         $canEditShippingAddress = $this->_quote->getMayEditShippingAddress() && $this->_quote->getPayment()->getAdditionalInformation(\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_BUTTON) == 1;
         // misc shipping parameters
         $this->setShippingMethodSubmitUrl($this->getUrl("{$this->_controllerPath}/saveShippingMethod"))->setCanEditShippingAddress($canEditShippingAddress)->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod());
     }
     $this->setEditUrl($this->getUrl("{$this->_controllerPath}/edit"))->setPlaceOrderUrl($this->getUrl("{$this->_controllerPath}/placeOrder"));
     return parent::_beforeToHtml();
 }
Exemplo n.º 3
0
 /**
  * Assign customer address to quote address and save quote address
  *
  * @param bool $unsetId
  */
 protected function _setCustomerAddressAndSave($unsetId)
 {
     $shippingAddress = $this->_quote->getShippingAddress();
     if ($unsetId) {
         $shippingAddress->setId(null);
     }
     $shippingAddress->setSameAsBilling(0)->setCustomerAddressData($this->_customer->getDefaultBillingAddress())->save();
 }
Exemplo n.º 4
0
 /**
  * Make sure addresses will be saved without validation errors
  *
  * @return void
  */
 private function _ignoreAddressValidation()
 {
     $this->_quote->getBillingAddress()->setShouldIgnoreValidation(true);
     if (!$this->_quote->getIsVirtual()) {
         $this->_quote->getShippingAddress()->setShouldIgnoreValidation(true);
         if (!$this->_config->getConfigValue('requireBillingAddress') && !$this->_quote->getBillingAddress()->getEmail()) {
             $this->_quote->getBillingAddress()->setSameAsBilling(1);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Set gift message to item or quote
  *
  * @param \Magento\Sales\Model\Quote $quote
  * @param string $type
  * @param \Magento\GiftMessage\Service\V1\Data\Message $giftMessage
  * @param null|int $entityId
  * @return void
  * @throws \Magento\Framework\Exception\CouldNotSaveException
  * @throws \Magento\Framework\Exception\State\InvalidTransitionException
  */
 protected function setMessage(\Magento\Sales\Model\Quote $quote, $type, $giftMessage, $entityId = null)
 {
     if (is_null($quote->getBillingAddress()->getCountryId())) {
         throw new InvalidTransitionException('Billing address is not set');
     }
     // check if shipping address is set
     if (is_null($quote->getShippingAddress()->getCountryId())) {
         throw new InvalidTransitionException('Shipping address is not set');
     }
     $configType = $type == 'quote' ? '' : 'items';
     if (!$this->helper->getIsMessagesAvailable($configType, $quote, $this->storeManager->getStore())) {
         throw new CouldNotSaveException('Gift Message is not available');
     }
     $message[$type][$entityId] = ['from' => $giftMessage->getSender(), 'to' => $giftMessage->getRecipient(), 'message' => $giftMessage->getMessage()];
     try {
         $this->giftMessageManager->add($message, $quote);
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not add gift message to shopping cart');
     }
 }
Exemplo n.º 6
0
 /**
  * Send email id payment was failed
  *
  * @param \Magento\Sales\Model\Quote $checkout
  * @param string $message
  * @param string $checkoutType
  * @return $this
  */
 public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage')
 {
     $this->inlineTranslation->suspend();
     $template = $this->_scopeConfig->getValue('checkout/payment_failed/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
     $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId());
     $copyMethod = $this->_scopeConfig->getValue('checkout/payment_failed/copy_method', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
     $bcc = array();
     if ($copyTo && $copyMethod == 'bcc') {
         $bcc = $copyTo;
     }
     $_receiver = $this->_scopeConfig->getValue('checkout/payment_failed/receiver', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
     $sendTo = array(array('email' => $this->_scopeConfig->getValue('trans_email/ident_' . $_receiver . '/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()), 'name' => $this->_scopeConfig->getValue('trans_email/ident_' . $_receiver . '/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId())));
     if ($copyTo && $copyMethod == 'copy') {
         foreach ($copyTo as $email) {
             $sendTo[] = array('email' => $email, 'name' => null);
         }
     }
     $shippingMethod = '';
     if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) {
         $data = explode('_', $shippingInfo);
         $shippingMethod = $data[0];
     }
     $paymentMethod = '';
     if ($paymentInfo = $checkout->getPayment()) {
         $paymentMethod = $paymentInfo->getMethod();
     }
     $items = '';
     foreach ($checkout->getAllVisibleItems() as $_item) {
         /* @var $_item \Magento\Sales\Model\Quote\Item */
         $items .= $_item->getProduct()->getName() . '  x ' . $_item->getQty() . '  ' . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
     }
     $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal();
     foreach ($sendTo as $recipient) {
         $transport = $this->_transportBuilder->setTemplateIdentifier($template)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()))->setTemplateVars(array('reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => $this->_localeDate->date(), 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(), 'customerEmail' => $checkout->getCustomerEmail(), 'billingAddress' => $checkout->getBillingAddress(), 'shippingAddress' => $checkout->getShippingAddress(), 'shippingMethod' => $this->_scopeConfig->getValue('carriers/' . $shippingMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'paymentMethod' => $this->_scopeConfig->getValue('payment/' . $paymentMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'items' => nl2br($items), 'total' => $total))->setFrom($this->_scopeConfig->getValue('checkout/payment_failed/identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()))->addTo($recipient['email'], $recipient['name'])->addBcc($bcc)->getTransport();
         $transport->sendMessage();
     }
     $this->inlineTranslation->resume();
     return $this;
 }
Exemplo n.º 7
0
 /**
  * Prepare Quote
  *
  * @param \Magento\Sales\Model\Quote $quote
  */
 protected function _prepareQuote($quote)
 {
     /** @var $rate \Magento\Sales\Model\Quote\Address\Rate */
     $rate = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Sales\\Model\\Quote\\Address\\Rate');
     $rate->setCode('freeshipping_freeshipping');
     $rate->getPrice(1);
     $quote->getShippingAddress()->setShippingMethod('freeshipping_freeshipping');
     $quote->getShippingAddress()->addShippingRate($rate);
     $quote->setCheckoutMethod(\Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER);
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function getTaxContainer()
 {
     return $this->_salesModel->getIsVirtual() ? $this->_salesModel->getBillingAddress() : $this->_salesModel->getShippingAddress();
 }
Exemplo n.º 9
0
 /**
  * Prepare quote for testing assignCustomerWithAddressChange method.
  *
  * Customer with two addresses created. First address is default billing, second is default shipping.
  *
  * @param \Magento\Sales\Model\Quote $quote
  * @return \Magento\Customer\Service\V1\Data\Customer
  */
 protected function _prepareQuoteForTestAssignCustomerWithAddressChange($quote)
 {
     $objectManager = Bootstrap::getObjectManager();
     /** @var \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerService */
     $customerService = $objectManager->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
     $fixtureCustomerId = 1;
     /** @var \Magento\Customer\Model\Customer $customer */
     $customer = $objectManager->create('Magento\\Customer\\Model\\Customer');
     $fixtureSecondAddressId = 2;
     $customer->load($fixtureCustomerId)->setDefaultShipping($fixtureSecondAddressId)->save();
     $customerData = $customerService->getCustomer($fixtureCustomerId);
     $this->assertEmpty($quote->getBillingAddress()->getId(), "Precondition failed: billing address should be empty.");
     $this->assertEmpty($quote->getShippingAddress()->getId(), "Precondition failed: shipping address should be empty.");
     return $customerData;
 }
Exemplo n.º 10
0
 /**
  * Check whether payment method is applicable to quote
  * Purposed to allow use in controllers some logic that was implemented in blocks only before
  *
  * @param PaymentMethodChecksInterface $paymentMethod
  * @param \Magento\Sales\Model\Quote $quote
  * @return bool
  */
 public function isApplicable(PaymentMethodChecksInterface $paymentMethod, Quote $quote)
 {
     $total = $quote->getBaseSubtotal() + $quote->getShippingAddress()->getBaseShippingAmount();
     return !($total < 0.0001 && $paymentMethod->getCode() != 'free');
 }