Skip to content

Commit

Permalink
Merge pull request #108 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[South + B2B + MPI] Bugfixes
  • Loading branch information
slavvka committed Nov 3, 2015
2 parents 1326cf1 + db06aa2 commit 16dc76d
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 591 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ define(
var address = null;
if (quote.shippingAddress() && billingAddress.getCacheKey() == quote.shippingAddress().getCacheKey()) {
address = $.extend({}, billingAddress);
address.save_in_address_book = false;
address.saveInAddressBook = false;
if (quote.shippingAddress().saveInAddressBook || quote.shippingAddress().save_in_address_book) {
address.saveInAddressBook = true;
quote.shippingAddress().saveInAddressBook = false;
}
} else {
address = billingAddress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
define(
[
'ko',
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/resource-url-manager',
'mage/storage',
Expand All @@ -16,6 +17,7 @@ define(
],
function (
ko,
$,
quote,
resourceUrlManager,
storage,
Expand All @@ -27,7 +29,12 @@ define(
'use strict';
return {
saveShippingInformation: function() {
var billingAddress = quote.billingAddress() || quote.shippingAddress();
var billingAddress = quote.billingAddress();
if (!billingAddress) {
billingAddress = $.extend({}, quote.shippingAddress());
quote.billingAddress(billingAddress);
quote.shippingAddress().sameAsBilling = 1;
}
var payload = {
addressInformation: {
shipping_address: quote.shippingAddress(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public function showCustomerInfo()
[
'customer' => $this->getTable('customer_entity')
],
'main_table.customer_id = customer.entity_id'
'main_table.customer_id = customer.entity_id',
['firstname', 'lastname']
);
return $this;
}
Expand Down
111 changes: 22 additions & 89 deletions app/code/Magento/Paypal/Model/Express/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Magento\Customer\Api\Data\CustomerInterface as CustomerDataObject;
use Magento\Customer\Model\AccountManagement;
use Magento\Paypal\Model\Config as PaypalConfig;
use Magento\Paypal\Model\Express\Checkout\Quote as PaypalQuote;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Quote\Model\Quote\Address;
use Magento\Framework\DataObject;
Expand Down Expand Up @@ -254,11 +253,6 @@ class Checkout
*/
protected $orderSender;

/**
* @var PaypalQuote
*/
protected $paypalQuote;

/**
* @var \Magento\Quote\Api\CartRepositoryInterface
*/
Expand Down Expand Up @@ -296,7 +290,6 @@ class Checkout
* @param \Magento\Framework\Message\ManagerInterface $messageManager
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
* @param AccountManagement $accountManagement
* @param PaypalQuote $paypalQuote
* @param OrderSender $orderSender
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
* @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector
Expand Down Expand Up @@ -326,7 +319,6 @@ public function __construct(
\Magento\Framework\Message\ManagerInterface $messageManager,
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
AccountManagement $accountManagement,
PaypalQuote $paypalQuote,
OrderSender $orderSender,
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
\Magento\Quote\Model\Quote\TotalsCollector $totalsCollector,
Expand All @@ -353,7 +345,6 @@ public function __construct(
$this->_messageManager = $messageManager;
$this->orderSender = $orderSender;
$this->_accountManagement = $accountManagement;
$this->paypalQuote = $paypalQuote;
$this->quoteRepository = $quoteRepository;
$this->totalsCollector = $totalsCollector;
$this->_customerSession = isset($params['session'])
Expand Down Expand Up @@ -620,7 +611,7 @@ public function returnFromPaypal($token)
->callGetExpressCheckoutDetails();
$quote = $this->_quote;

$this->_ignoreAddressValidation();
$this->ignoreAddressValidation();

// import shipping address
$exportedShippingAddress = $this->_api->getExportedShippingAddress();
Expand Down Expand Up @@ -708,7 +699,7 @@ public function prepareOrderReview($token = null)
$this->_quote->setMayEditShippingMethod(
'' == $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD)
);
$this->_ignoreAddressValidation();
$this->ignoreAddressValidation();
$this->_quote->collectTotals();
$this->quoteRepository->save($this->_quote);
}
Expand Down Expand Up @@ -763,7 +754,7 @@ public function updateShippingMethod($methodCode)
$shippingAddress = $this->_quote->getShippingAddress();
if (!$this->_quote->getIsVirtual() && $shippingAddress) {
if ($methodCode != $shippingAddress->getShippingMethod()) {
$this->_ignoreAddressValidation();
$this->ignoreAddressValidation();
$shippingAddress->setShippingMethod($methodCode)->setCollectShippingRates(true);
$this->_quote->collectTotals();
$this->quoteRepository->save($this->_quote);
Expand All @@ -786,31 +777,14 @@ public function place($token, $shippingMethodCode = null)
$this->updateShippingMethod($shippingMethodCode);
}

$isNewCustomer = false;
switch ($this->getCheckoutMethod()) {
case \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST:
$this->_prepareGuestQuote();
break;
case \Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER:
$this->_prepareNewCustomerQuote();
$isNewCustomer = true;
break;
default:
$this->_prepareCustomerQuote();
break;
if ($this->getCheckoutMethod() == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) {
$this->prepareGuestQuote();
}

$this->_ignoreAddressValidation();
$this->ignoreAddressValidation();
$this->_quote->collectTotals();
$order = $this->quoteManagement->submit($this->_quote);

if ($isNewCustomer) {
try {
$this->_involveNewCustomer();
} catch (\Exception $e) {
$this->_logger->critical($e);
}
}
if (!$order) {
return;
}
Expand Down Expand Up @@ -843,7 +817,7 @@ public function place($token, $shippingMethodCode = null)
*
* @return void
*/
private function _ignoreAddressValidation()
private function ignoreAddressValidation()
{
$this->_quote->getBillingAddress()->setShouldIgnoreValidation(true);
if (!$this->_quote->getIsVirtual()) {
Expand Down Expand Up @@ -1109,62 +1083,6 @@ protected function _matchShippingMethodCode(Address $address, $selectedCode)
return '';
}

/**
* Prepare quote for guest checkout order submit
*
* @return $this
*/
protected function _prepareGuestQuote()
{
$quote = $this->_quote;
$quote->setCustomerId(null)
->setCustomerEmail($quote->getBillingAddress()->getEmail())
->setCustomerIsGuest(true)
->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
return $this;
}

/**
* Prepare quote for customer registration and customer order submit
* and restore magento customer data from quote
*
* @return void
*/
protected function _prepareNewCustomerQuote()
{
$this->paypalQuote->prepareQuoteForNewCustomer($this->_quote);
}

/**
* Prepare quote for customer order submit
*
* @return void
*/
protected function _prepareCustomerQuote()
{
$this->paypalQuote->prepareRegisteredCustomerQuote($this->_quote, $this->_customerSession->getCustomerId());
}

/**
* Involve new customer to system
*
* @return $this
*/
protected function _involveNewCustomer()
{
$customer = $this->_quote->getCustomer();
$confirmationStatus = $this->_accountManagement->getConfirmationStatus($customer->getId());
if ($confirmationStatus === AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED) {
$this->_messageManager->addSuccess(
__('Thank you for registering with Main Website Store.')
);
} else {
$this->getCustomerSession()->regenerateId();
$this->getCustomerSession()->loginById($customer->getId());
}
return $this;
}

/**
* Create payment redirect url
* @param bool|null $button
Expand Down Expand Up @@ -1218,4 +1136,19 @@ private function setShippingOptions(PaypalCart $cart, Address $address = null)
}
}
}

/**
* Prepare quote for guest checkout order submit
*
* @return $this
*/
protected function prepareGuestQuote()
{
$quote = $this->_quote;
$quote->setCustomerId(null)
->setCustomerEmail($quote->getBillingAddress()->getEmail())
->setCustomerIsGuest(true)
->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID);
return $this;
}
}
Loading

0 comments on commit 16dc76d

Please sign in to comment.