/** * Update quote address * * @param Quote $quote * @param array $details * @return void */ private function updateQuoteAddress(Quote $quote, array $details) { if (!$quote->getIsVirtual()) { $this->updateShippingAddress($quote, $details); } $this->updateBillingAddress($quote, $details); }
/** * Retrieve payment method and assign additional template values * * @return $this * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ 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(); }
/** * @param \Magento\Quote\Model\Quote $quote * @param array $details * @return $this * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function populateQuoteAddress($quote, $details) { // import shipping address $exportedShippingAddress = isset($details['shippingAddress']) ? $details['shippingAddress'] : null; if (!$quote->getIsVirtual()) { $shippingAddress = $quote->getShippingAddress(); if ($exportedShippingAddress) { $this->importAddressData($shippingAddress, $exportedShippingAddress); } // PayPal doesn't provide detailed shipping info: prefix, suffix $shippingAddress->setLastname($details['lastName']); $shippingAddress->setFirstname($details['firstName']); $shippingAddress->setEmail($details['email']); $shippingAddress->setCollectShippingRates(true); } $exportedBillingAddress = isset($details['billingAddress']) ? $details['billingAddress'] : null; $billingAddress = $quote->getBillingAddress(); if ($exportedBillingAddress) { $this->importBillingAddressData($billingAddress, $exportedBillingAddress); $billingAddress->setFirstname($details['firstName']); $billingAddress->setLastname($details['lastName']); $billingAddress->setEmail($details['email']); } elseif ($billingAddress->getEmail() == null) { $this->importAddressData($billingAddress, $exportedShippingAddress); $billingAddress->setFirstname($details['firstName']); $billingAddress->setLastname($details['lastName']); $billingAddress->setEmail($details['email']); } return $this; }
/** * 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->getValue('requireBillingAddress') && !$this->_quote->getBillingAddress()->getEmail()) { $this->_quote->getBillingAddress()->setSameAsBilling(1); } } }
/** * Make sure addresses will be saved without validation errors * * @param Quote $quote * @return void */ protected function disabledQuoteAddressValidation(Quote $quote) { $billingAddress = $quote->getBillingAddress(); $billingAddress->setShouldIgnoreValidation(true); if (!$quote->getIsVirtual()) { $shippingAddress = $quote->getShippingAddress(); $shippingAddress->setShouldIgnoreValidation(true); if (!$billingAddress->getEmail()) { $billingAddress->setSameAsBilling(1); } } }
/** * Set shipping options to api * @param \Magento\Paypal\Model\Cart $cart * @param \Magento\Quote\Model\Quote\Address|null $address * @return void */ private function setShippingOptions(PaypalCart $cart, Address $address = null) { // for included tax always disable line items (related to paypal amount rounding problem) $this->_api->setIsLineItemsEnabled($this->_config->getValue(PaypalConfig::TRANSFER_CART_LINE_ITEMS)); // add shipping options if needed and line items are available $cartItems = $cart->getAllItems(); if ($this->_config->getValue(PaypalConfig::TRANSFER_CART_LINE_ITEMS) && $this->_config->getValue(PaypalConfig::TRANSFER_SHIPPING_OPTIONS) && !empty($cartItems)) { if (!$this->_quote->getIsVirtual()) { $options = $this->_prepareShippingOptions($address, true); if ($options) { $this->_api->setShippingOptionsCallbackUrl($this->_coreUrl->getUrl('*/*/shippingOptionsCallback', ['quote_id' => $this->_quote->getId()]))->setShippingOptions($options); } } } }
/** * Execute operation * * @param string $shippingMethod * @param Quote $quote * @return void * @throws \InvalidArgumentException */ public function execute($shippingMethod, Quote $quote) { if (empty($shippingMethod)) { throw new \InvalidArgumentException('The "shippingMethod" field does not exists.'); } if (!$quote->getIsVirtual()) { $shippingAddress = $quote->getShippingAddress(); if ($shippingMethod !== $shippingAddress->getShippingMethod()) { $this->disabledQuoteAddressValidation($quote); $shippingAddress->setShippingMethod($shippingMethod); $shippingAddress->setCollectShippingRates(true); $quote->collectTotals(); $this->quoteRepository->save($quote); } } }
/** * {@inheritdoc} */ public function getTaxContainer() { return $this->_salesModel->getIsVirtual() ? $this->_salesModel->getBillingAddress() : $this->_salesModel->getShippingAddress(); }