예제 #1
1
 private function getProductTaxRate()
 {
     /** @var $taxCalculator \Magento\Tax\Model\Calculation */
     $taxCalculator = $this->calculation;
     $request = $taxCalculator->getRateRequest($this->quote->getShippingAddress(), $this->quote->getBillingAddress(), $this->quote->getCustomerTaxClassId(), $this->quote->getStore());
     $request->setProductClassId($this->getProduct()->getTaxClassId());
     return $taxCalculator->getRate($request);
 }
예제 #2
1
 /**
  * Get payment country
  *
  * @param Quote $quote
  * @return int
  */
 public function getCountry(Quote $quote)
 {
     $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
     return $address ? $address->getCountry() : $this->directoryHelper->getDefaultCountry();
 }
예제 #3
0
 /**
  * same_as_billing must be equal 0 if billing address is being saved
  *
  * @param bool $unsetId
  * @dataProvider unsetAddressIdDataProvider
  */
 public function testSameAsBillingForBillingAddress($unsetId)
 {
     $this->_quote->setCustomer($this->_customer);
     $address = $this->_quote->getBillingAddress();
     if ($unsetId) {
         $address->setId(null);
     }
     /** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */
     $addressRepository = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\AddressRepositoryInterface');
     $customerAddressData = $addressRepository->getById($this->_customer->getDefaultBilling());
     $address->setSameAsBilling(0)->setCustomerAddressData($customerAddressData)->save();
     $this->assertEquals(0, $this->_quote->getBillingAddress()->getSameAsBilling());
 }
예제 #4
0
파일: Checkout.php 프로젝트: nja78/magento2
 /**
  * @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;
 }
 /**
  * Populate customer model
  *
  * @param Quote $quote
  * @return void
  */
 public function populateCustomerInfo(QuoteEntity $quote)
 {
     $customer = $quote->getCustomer();
     if (!$customer->getId()) {
         $customer = $this->accountManagement->createAccountWithPasswordHash($customer, $quote->getPasswordHash());
         $quote->setCustomer($customer);
     } else {
         $this->customerRepository->save($customer);
     }
     if (!$quote->getBillingAddress()->getId() && $customer->getDefaultBilling()) {
         $quote->getBillingAddress()->importCustomerAddressData($this->customerAddressRepository->getById($customer->getDefaultBilling()));
         $quote->getBillingAddress()->setCustomerAddressId($customer->getDefaultBilling());
     }
     if (!$quote->getShippingAddress()->getSameAsBilling() && !$quote->getBillingAddress()->getId() && $customer->getDefaultShipping()) {
         $quote->getShippingAddress()->importCustomerAddressData($this->customerAddressRepository->getById($customer->getDefaultShipping()));
         $quote->getShippingAddress()->setCustomerAddressId($customer->getDefaultShipping());
     }
 }
예제 #6
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->getValue('requireBillingAddress') && !$this->_quote->getBillingAddress()->getEmail()) {
             $this->_quote->getBillingAddress()->setSameAsBilling(1);
         }
     }
 }
예제 #7
0
 /**
  * Validate quote before submit
  *
  * @param Quote $quote
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function validateBeforeSubmit(QuoteEntity $quote)
 {
     if (!$quote->isVirtual()) {
         if ($quote->getShippingAddress()->validate() !== true) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Please check the shipping address information. %1', implode(' ', $quote->getShippingAddress()->validate())));
         }
         $method = $quote->getShippingAddress()->getShippingMethod();
         $rate = $quote->getShippingAddress()->getShippingRateByCode($method);
         if (!$quote->isVirtual() && (!$method || !$rate)) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Please specify a shipping method.'));
         }
     }
     if ($quote->getBillingAddress()->validate() !== true) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please check the billing address information. %1', implode(' ', $quote->getBillingAddress()->validate())));
     }
     if (!$quote->getPayment()->getMethod()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please select a valid payment method.'));
     }
     return $this;
 }
 /**
  * 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);
         }
     }
 }
예제 #9
0
 private function initializeAddresses()
 {
     $billingAddress = $this->quote->getBillingAddress();
     $billingAddress->addData($this->proxyOrder->getBillingAddressData());
     $billingAddress->setStreet($billingAddress->getStreet());
     $billingAddress->setLimitCarrier('m2eproshipping');
     $billingAddress->setShippingMethod('m2eproshipping_m2eproshipping');
     $billingAddress->setCollectShippingRates(true);
     $billingAddress->setShouldIgnoreValidation($this->proxyOrder->shouldIgnoreBillingAddressValidation());
     // ---------------------------------------
     $shippingAddress = $this->quote->getShippingAddress();
     $shippingAddress->setSameAsBilling(0);
     // maybe just set same as billing?
     $shippingAddress->addData($this->proxyOrder->getAddressData());
     $shippingAddress->setStreet($shippingAddress->getStreet());
     $shippingAddress->setLimitCarrier('m2eproshipping');
     $shippingAddress->setShippingMethod('m2eproshipping_m2eproshipping');
     $shippingAddress->setCollectShippingRates(true);
     // ---------------------------------------
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function getTaxContainer()
 {
     return $this->_salesModel->getIsVirtual() ? $this->_salesModel->getBillingAddress() : $this->_salesModel->getShippingAddress();
 }
예제 #11
0
 /**
  * Return quote billing address
  *
  * @return \Magento\Quote\Model\Quote\Address
  */
 public function getBillingAddress()
 {
     return $this->_quote->getBillingAddress();
 }
예제 #12
0
 /**
  * Update billing address
  *
  * @param Quote $quote
  * @param array $details
  * @return void
  */
 private function updateBillingAddress(Quote $quote, array $details)
 {
     $billingAddress = $quote->getBillingAddress();
     if ($this->config->isRequiredBillingAddress()) {
         $this->updateAddressData($billingAddress, $details['billingAddress']);
     } else {
         $this->updateAddressData($billingAddress, $details['shippingAddress']);
     }
     $billingAddress->setFirstname($details['firstName']);
     $billingAddress->setLastname($details['lastName']);
     $billingAddress->setEmail($details['email']);
 }
예제 #13
0
 /**
  * Prepare quote for customer order submit
  *
  * @param Quote $quote
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _prepareCustomerQuote($quote)
 {
     /** @var Quote $quote */
     $billing = $quote->getBillingAddress();
     $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
     $customer = $this->customerRepository->getById($quote->getCustomerId());
     $hasDefaultBilling = (bool) $customer->getDefaultBilling();
     $hasDefaultShipping = (bool) $customer->getDefaultShipping();
     if ($shipping && !$shipping->getSameAsBilling() && (!$shipping->getCustomerId() || $shipping->getSaveInAddressBook())) {
         $shippingAddress = $shipping->exportCustomerAddress();
         if (!$hasDefaultShipping) {
             //Make provided address as default shipping address
             $shippingAddress->setIsDefaultShipping(true);
             $hasDefaultShipping = true;
         }
         $quote->addCustomerAddress($shippingAddress);
         $shipping->setCustomerAddressData($shippingAddress);
     }
     if (!$billing->getCustomerId() || $billing->getSaveInAddressBook()) {
         $billingAddress = $billing->exportCustomerAddress();
         if (!$hasDefaultBilling) {
             //Make provided address as default shipping address
             if (!$hasDefaultShipping) {
                 //Make provided address as default shipping address
                 $billingAddress->setIsDefaultShipping(true);
             }
             $billingAddress->setIsDefaultBilling(true);
         }
         $quote->addCustomerAddress($billingAddress);
         $billing->setCustomerAddressData($billingAddress);
     }
     if ($shipping && !$shipping->getCustomerId() && !$hasDefaultBilling) {
         $shipping->setIsDefaultBilling(true);
     }
 }
 /**
  * Sets the gift message to item or quote.
  *
  * @param \Magento\Quote\Model\Quote $quote The quote.
  * @param string $type The type.
  * @param \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage The gift message.
  * @param null|int $entityId The entity ID.
  * @return void
  * @throws \Magento\Framework\Exception\CouldNotSaveException The specified gift message is not available.
  * @throws \Magento\Framework\Exception\State\InvalidTransitionException The billing or shipping address is not set.
  */
 public function setMessage(\Magento\Quote\Model\Quote $quote, $type, $giftMessage, $entityId = null)
 {
     if ($quote->getBillingAddress()->getCountryId() === null) {
         throw new InvalidTransitionException(__('Billing address is not set'));
     }
     // check if shipping address is set
     if ($quote->getShippingAddress()->getCountryId() === null) {
         throw new InvalidTransitionException(__('Shipping address is not set'));
     }
     $message[$type][$entityId] = ['from' => $giftMessage->getSender(), 'to' => $giftMessage->getRecipient(), 'message' => $giftMessage->getMessage()];
     try {
         $this->add($message, $quote);
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not add gift message to shopping cart'));
     }
 }
 /**
  * Prepare quote for guest checkout order submit
  *
  * @param Quote $quote
  * @return void
  */
 private function prepareGuestQuote(Quote $quote)
 {
     $quote->setCustomerId(null)->setCustomerEmail($quote->getBillingAddress()->getEmail())->setCustomerIsGuest(true)->setCustomerGroupId(Group::NOT_LOGGED_IN_ID);
 }
예제 #16
0
파일: Quote.php 프로젝트: nja78/magento2
 /**
  * @param \Magento\Quote\Model\Quote $quote
  * @param int|null $customerId
  * @return \Magento\Quote\Model\Quote
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function prepareRegisteredCustomerQuote(\Magento\Quote\Model\Quote $quote, $customerId)
 {
     $billing = $quote->getBillingAddress();
     $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
     $customer = $this->customerRepository->getById($customerId);
     $isBillingAddressDefaultBilling = !$customer->getDefaultBilling();
     $isBillingAddressDefaultShipping = false;
     $isShippingAddressDefaultShipping = false;
     if ($shipping && !$customer->getDefaultShipping()) {
         $isShippingAddressDefaultShipping = true;
     } elseif (!$customer->getDefaultShipping()) {
         $isBillingAddressDefaultShipping = true;
     }
     if ($shipping && $shipping->getTelephone() && !$shipping->getSameAsBilling() && (!$shipping->getCustomerId() || $shipping->getSaveInAddressBook() || !$customer->getDefaultShipping())) {
         $address = $shipping->exportCustomerAddress();
         $address->setIsDefaultShipping($isShippingAddressDefaultShipping);
         $quote->addCustomerAddress($address);
     }
     if ($billing && $billing->getTelephone() && (!$customer->getDefaultBilling() || $billing->getSaveInAddressBook())) {
         $address = $billing->exportCustomerAddress();
         $address->setIsDefaultBilling($isBillingAddressDefaultBilling);
         $address->setIsDefaultShipping($isBillingAddressDefaultShipping);
         $quote->addCustomerAddress($address);
     }
     return $quote;
 }
예제 #17
0
 /**
  * calculate quote checksum, it's verified after the return from the payment page
  * detect fraud attempts (cart modifications during checkout)
  *
  * @param \Magento\Quote\Model\Quote $quote
  *
  * @return string
  */
 public function calculateQuoteChecksum($quote)
 {
     $data = round($quote->getGrandTotal(), $this->getPrecision()) . $quote->getBaseCurrencyCode() . $quote->getCustomerEmail();
     foreach ($quote->getAllVisibleItems() as $item) {
         /** @var \Magento\Quote\Model\Quote\Item $item */
         $data .= $item->getSku();
         $data .= round($item->getRowTotal(), $this->getPrecision());
         $data .= round($item->getTaxAmount(), $this->getPrecision());
     }
     $address = $quote->getBillingAddress();
     $data .= $address->getName() . $address->getCompany() . $address->getCity() . $address->getPostcode() . $address->getCountryId() . $address->getCountry() . $address->getRegion() . $address->getStreetLine(1) . $address->getStreetLine(2);
     $address = $quote->getShippingAddress();
     $data .= $address->getName() . $address->getCompany() . $address->getCity() . $address->getPostcode() . $address->getCountryId() . $address->getCountry() . $address->getRegion() . $address->getStreetLine(1) . $address->getStreetLine(2);
     return hash_hmac('sha512', $data, $this->getConfigData('basicdata/secret'));
 }
예제 #18
0
 /**
  * Send email id payment was failed
  *
  * @param \Magento\Quote\Model\Quote $checkout
  * @param string $message
  * @param string $checkoutType
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 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 = [];
     if ($copyTo && $copyMethod == 'bcc') {
         $bcc = $copyTo;
     }
     $_receiver = $this->scopeConfig->getValue('checkout/payment_failed/receiver', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
     $sendTo = [['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[] = ['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\Quote\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(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()])->setTemplateVars(['reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => $this->_localeDate->formatDateTime(new \DateTime(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::MEDIUM), '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;
 }
예제 #19
0
 /**
  * compare billing shipping address
  *
  * @param Quote $quote
  *
  * @return bool
  */
 protected function compareAddresses($quote)
 {
     $billingAddress = $quote->getBillingAddress();
     $shippingAddress = $quote->getShippingAddress();
     if (!$shippingAddress->getSameAsBilling()) {
         if ($billingAddress->getCustomerAddressId() == null || $billingAddress->getCustomerAddressId() != $shippingAddress->getCustomerAddressId()) {
             if ($billingAddress->getName() != $shippingAddress->getName() || $billingAddress->getCompany() != $shippingAddress->getCompany() || $billingAddress->getCity() != $shippingAddress->getCity() || $billingAddress->getPostcode() != $shippingAddress->getPostcode() || $billingAddress->getCountryId() != $shippingAddress->getCountryId() || $billingAddress->getTelephone() != $shippingAddress->getTelephone() || $billingAddress->getFax() != $shippingAddress->getFax() || $billingAddress->getCountry() != $shippingAddress->getCountry() || $billingAddress->getRegion() != $shippingAddress->getRegion() || $billingAddress->getStreetLine(1) != $shippingAddress->getStreetLine(1) || $billingAddress->getStreetLine(2) != $shippingAddress->getStreetLine(2)) {
                 return false;
             }
         }
     }
     return true;
 }
예제 #20
0
 /**
  * Check whether payment method is applicable to quote
  * @param MethodInterface $paymentMethod
  * @param Quote $quote
  * @return bool
  */
 public function isApplicable(MethodInterface $paymentMethod, Quote $quote)
 {
     return $paymentMethod->canUseForCountry($quote->getBillingAddress()->getCountry());
 }
예제 #21
0
 /**
  * Prepare quote for testing assignCustomerWithAddressChange method.
  *
  * Customer with two addresses created. First address is default billing, second is default shipping.
  *
  * @param \Magento\Quote\Model\Quote $quote
  * @return \Magento\Customer\Api\Data\CustomerInterface
  */
 protected function _prepareQuoteForTestAssignCustomerWithAddressChange($quote)
 {
     $objectManager = Bootstrap::getObjectManager();
     /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
     $customerRepository = $objectManager->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $fixtureCustomerId = 1;
     /** @var \Magento\Customer\Model\Customer $customer */
     $customer = $objectManager->create('Magento\\Customer\\Model\\Customer');
     $fixtureSecondAddressId = 2;
     $customer->load($fixtureCustomerId)->setDefaultShipping($fixtureSecondAddressId)->save();
     $customerData = $customerRepository->getById($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;
 }