Пример #1
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\Service\V1\CustomerAddressServiceInterface $addressService */
     $addressService = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\CustomerAddressServiceInterface');
     $customerAddressData = $addressService->getDefaultBillingAddress($this->_customer->getId());
     $address->setSameAsBilling(0)->setCustomerAddressData($customerAddressData)->save();
     $this->assertEquals(0, $this->_quote->getBillingAddress()->getSameAsBilling());
 }
Пример #2
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);
         }
     }
 }
Пример #3
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');
     }
 }
Пример #4
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;
 }
Пример #5
0
 /**
  * Check whether payment method is applicable to quote
  * @param PaymentMethodChecksInterface $paymentMethod
  * @param Quote $quote
  * @return bool
  */
 public function isApplicable(PaymentMethodChecksInterface $paymentMethod, Quote $quote)
 {
     return $paymentMethod->canUseForCountry($quote->getBillingAddress()->getCountry());
 }
Пример #6
0
 /**
  * Return quote billing address
  *
  * @return \Magento\Sales\Model\Quote\Address
  */
 public function getBillingAddress()
 {
     return $this->_quote->getBillingAddress();
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function getTaxContainer()
 {
     return $this->_salesModel->getIsVirtual() ? $this->_salesModel->getBillingAddress() : $this->_salesModel->getShippingAddress();
 }
Пример #8
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;
 }