/** * @param \Magento\Quote\Model\Quote $quote * @return \Magento\Quote\Model\Quote */ public function prepareQuoteForNewCustomer(\Magento\Quote\Model\Quote $quote) { $billing = $quote->getBillingAddress(); $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress(); $billing->setDefaultBilling(true); if ($shipping && !$shipping->getSameAsBilling()) { $shipping->setDefaultShipping(true); $address = $shipping->exportCustomerAddress(); $shipping->setCustomerAddressData($address); } elseif ($shipping) { $billing->setDefaultShipping(true); } $address = $shipping->exportCustomerAddress(); $billing->setCustomerAddressData($address); foreach (['customer_dob', 'customer_taxvat', 'customer_gender'] as $attribute) { if ($quote->getData($attribute) && !$billing->getData($attribute)) { $billing->setData($attribute, $quote->getData($attribute)); } } $customer = $this->customerFactory->create(); $this->dataObjectHelper->populateWithArray($customer, $this->copyObject->getDataFromFieldset('checkout_onepage_billing', 'to_customer', $billing), '\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $customer->setEmail($quote->getCustomerEmail()); $customer->setPrefix($quote->getCustomerPrefix()); $customer->setFirstname($quote->getCustomerFirstname()); $customer->setMiddlename($quote->getCustomerMiddlename()); $customer->setLastname($quote->getCustomerLastname()); $customer->setSuffix($quote->getCustomerSuffix()); $quote->setCustomer($customer); $quote->addCustomerAddress($billing->exportCustomerAddress()); if ($shipping->hasCustomerAddress()) { $quote->addCustomerAddress($shipping->exportCustomerAddress()); } return $quote; }
/** * Ensure that quote has customer data specified in customer fixture. * * @param \Magento\Quote\Model\Quote $quote */ protected function _validateCustomerDataInQuote($quote) { $customerIdFromFixture = 1; $customerEmailFromFixture = '*****@*****.**'; $customerFirstNameFromFixture = 'John'; $this->assertEquals($customerEmailFromFixture, $quote->getCustomerEmail(), 'Customer email was not set to Quote correctly.'); $this->assertEquals($customerIdFromFixture, $quote->getCustomerId(), 'Customer ID was not set to Quote correctly.'); $this->assertEquals($customerFirstNameFromFixture, $quote->getCustomerFirstname(), 'Customer first name was not set to Quote correctly.'); }
/** * 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; }
/** * 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')); }
/** * Returns desription of customer - will be displayed in Wirecard backend * * @param Quote $quote * * @return string */ protected function getUserDescription($quote) { return sprintf('%s %s %s', $quote->getCustomerEmail(), $quote->getCustomerFirstname(), $quote->getCustomerLastname()); }