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); }
/** * 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(); }
public function _populateQuoteShippingMethod(\Magento\Quote\Model\Quote $quote) { /** @var \Magento\Quote\Model\Quote\Address $addr */ $addr = $quote->getShippingAddress(); $addr->setShippingMethod(self::METHOD_SHIPPING); $addr->setCollectShippingRates(true); $addr->collectShippingRates(); }
/** * 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; }
/** * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php */ public function testSetMethod() { $this->quote->load('test_order_1', 'reserved_order_id'); $serviceInfo = $this->getServiceInfo(); $cartId = $this->quote->getId(); /** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ $quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Quote\\Model\\QuoteIdMaskFactory')->create(); $quoteIdMask->load($cartId, 'quote_id'); //Use masked cart Id $cartId = $quoteIdMask->getMaskedId(); $shippingAddress = $this->quote->getShippingAddress(); $shippingAddress->setCollectShippingRates(true); $shippingAddress->collectTotals()->save(); $requestData = ['cartId' => $cartId, 'carrierCode' => 'flatrate', 'methodCode' => 'flatrate']; $result = $this->_webApiCall($serviceInfo, $requestData); $this->assertEquals(true, $result); }
/** * 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()); } }
/** * 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); } /** @var \Magento\Customer\Api\AddressRepositoryInterface $addressRepository */ $addressRepository = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\AddressRepositoryInterface'); $shippingAddress->setSameAsBilling(0)->setCustomerAddressData($addressRepository->getById($this->_customer->getDefaultBilling()))->save(); }
/** * 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); } } }
/** * 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); } } }
/** * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php */ public function testGetMethodForMyCart() { $this->_markTestAsRestOnly(); $this->quote->load('test_order_1', 'reserved_order_id'); /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */ $customerTokenService = $this->objectManager->create('Magento\\Integration\\Api\\CustomerTokenServiceInterface'); $token = $customerTokenService->createCustomerAccessToken('*****@*****.**', 'password'); /** @var \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagementService */ $shippingAddress = $this->quote->getShippingAddress(); $shippingAddress->setCollectShippingRates(true); $shippingAddress->collectTotals()->save(); $serviceInfo = ['rest' => ['resourcePath' => '/V1/carts/mine/selected-shipping-method', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, 'token' => $token]]; $result = $this->_webApiCall($serviceInfo, []); $this->assertEquals('flatrate', $result[ShippingMethodInterface::KEY_CARRIER_CODE]); $this->assertEquals('flatrate', $result[ShippingMethodInterface::KEY_METHOD_CODE]); }
/** * 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); } } }
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); // --------------------------------------- }
/** * Get list of available shipping methods * @param \Magento\Quote\Model\Quote $quote * @param array $addressData * @return \Magento\Quote\Api\Data\ShippingMethodInterface[] */ private function getShippingMethods(Quote $quote, array $addressData) { $output = []; $shippingAddress = $quote->getShippingAddress(); $shippingAddress->addData($addressData); $shippingAddress->setCollectShippingRates(true); $this->totalsCollector->collectAddressTotals($quote, $shippingAddress); $shippingRates = $shippingAddress->getGroupedAllShippingRates(); foreach ($shippingRates as $carrierRates) { foreach ($carrierRates as $rate) { $output[] = $this->converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode()); } } return $output; }
/** * 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; }
/** * Update shipping address * (PayPal doesn't provide detailed shipping info: prefix, suffix) * * @param Quote $quote * @param array $details * @return void */ private function updateShippingAddress(Quote $quote, array $details) { $shippingAddress = $quote->getShippingAddress(); $shippingAddress->setLastname($details['lastName']); $shippingAddress->setFirstname($details['firstName']); $shippingAddress->setEmail($details['email']); $shippingAddress->setCollectShippingRates(true); $this->updateAddressData($shippingAddress, $details['shippingAddress']); }
/** * Get estimated rates * * @param Quote $quote * @param int $country * @param string $postcode * @param int $regionId * @param string $region * @return \Magento\Quote\Api\Data\ShippingMethodInterface[] An array of shipping methods. */ protected function getEstimatedRates(\Magento\Quote\Model\Quote $quote, $country, $postcode, $regionId, $region) { $output = []; $shippingAddress = $quote->getShippingAddress(); $shippingAddress->setCountryId($country); $shippingAddress->setPostcode($postcode); $shippingAddress->setRegionId($regionId); $shippingAddress->setRegion($region); $shippingAddress->setCollectShippingRates(true); $shippingAddress->collectTotals(); $shippingRates = $shippingAddress->getGroupedAllShippingRates(); foreach ($shippingRates as $carrierRates) { foreach ($carrierRates as $rate) { $output[] = $this->converter->modelToDataObject($rate, $quote->getQuoteCurrencyCode()); } } return $output; }
/** * 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 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; }
/** * Prepare Quote * * @param \Magento\Quote\Model\Quote $quote */ protected function _prepareQuote($quote) { /** @var $rate \Magento\Quote\Model\Quote\Address\Rate */ $rate = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Quote\\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); }
/** * @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; }
/** * 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')); }
/** * Get payment country * * @param Quote $quote * @return int */ public function getCountry(Quote $quote) { return $quote->isVirtual() ? $this->directoryHelper->getDefaultCountry() : $quote->getShippingAddress()->getCountry(); }
/** * {@inheritdoc} */ public function getTaxContainer() { return $this->_salesModel->getIsVirtual() ? $this->_salesModel->getBillingAddress() : $this->_salesModel->getShippingAddress(); }
/** * 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; }