Skip to content

Commit ff3138e

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into BUGS
2 parents ed44e7f + 383362a commit ff3138e

File tree

45 files changed

+466
-252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+466
-252
lines changed

app/code/Magento/Backend/Model/Session/Quote.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,16 @@ public function __construct(
150150
*/
151151
public function getQuote()
152152
{
153-
$cartManagement = $this->getCartManagement();
154-
155153
if ($this->_quote === null) {
154+
$this->_quote = $this->quoteFactory->create();
156155
if ($this->getStoreId()) {
157156
if (!$this->getQuoteId()) {
158-
$this->setQuoteId($cartManagement->createEmptyCart());
159-
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
160157
$this->_quote->setCustomerGroupId($this->groupManagement->getDefaultGroup()->getId());
161-
$this->_quote->setIsActive(false);
158+
$this->_quote->setStoreId($this->getStoreId());
159+
160+
$this->quoteRepository->save($this->_quote);
161+
$this->setQuoteId($this->_quote->getId());
162+
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
162163
} else {
163164
$this->_quote = $this->quoteRepository->get($this->getQuoteId(), [$this->getStoreId()]);
164165
$this->_quote->setStoreId($this->getStoreId());
@@ -167,6 +168,7 @@ public function getQuote()
167168
if ($this->getCustomerId() && $this->getCustomerId() != $this->_quote->getCustomerId()) {
168169
$customer = $this->customerRepository->getById($this->getCustomerId());
169170
$this->_quote->assignCustomer($customer);
171+
$this->quoteRepository->save($this->_quote);
170172
}
171173
}
172174
$this->_quote->setIgnoreOldQty(true);
@@ -176,18 +178,6 @@ public function getQuote()
176178
return $this->_quote;
177179
}
178180

179-
/**
180-
* @return CartManagementInterface
181-
* @deprecated
182-
*/
183-
private function getCartManagement()
184-
{
185-
if ($this->cartManagement === null) {
186-
$this->cartManagement = ObjectManager::getInstance()->get(CartManagementInterface::class);
187-
}
188-
return $this->cartManagement;
189-
}
190-
191181
/**
192182
* Retrieve store model object
193183
*

app/code/Magento/Backend/Test/Unit/Model/Session/QuoteTest.php

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class QuoteTest extends \PHPUnit_Framework_TestCase
3333
protected $cookieManagerMock;
3434

3535
/**
36-
* @var \Magento\Framework\Session\StorageInterface|\PHPUnit_Framework_MockObject_MockObject
36+
* @var \Magento\Framework\Session\StorageInterface
3737
*/
38-
protected $storageMock;
38+
protected $storage;
3939

4040
/**
4141
* @var \Magento\Framework\Session\ValidatorInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -166,12 +166,7 @@ protected function setUp()
166166
'',
167167
false
168168
);
169-
$this->storageMock = $this->getMockForAbstractClass(
170-
'Magento\Framework\Session\StorageInterface',
171-
[],
172-
'',
173-
false
174-
);
169+
$this->storage = new \Magento\Framework\Session\Storage();
175170
$this->cookieManagerMock = $this->getMock('Magento\Framework\Stdlib\CookieManagerInterface');
176171
$this->cookieMetadataFactoryMock = $this->getMock(
177172
'Magento\Framework\Stdlib\Cookie\CookieMetadataFactory',
@@ -219,7 +214,7 @@ protected function setUp()
219214
'sessionConfig' => $this->sessionConfigMock,
220215
'saveHandler' => $this->saveHandlerMock,
221216
'validator' => $this->validatorMock,
222-
'storage' => $this->storageMock,
217+
'storage' => $this->storage,
223218
'cookieManager' => $this->cookieManagerMock,
224219
'cookieMetadataFactory' => $this->cookieMetadataFactoryMock,
225220
'appState' => $appStateMock,
@@ -249,20 +244,72 @@ public function testGetQuoteWithoutQuoteId()
249244
$customerId = 66;
250245
$customerGroupId = 77;
251246

252-
$this->cartManagementMock->expects($this->once())->method('createEmptyCart')->willReturn($quoteId);
253-
254247
$this->quote->expects($this->any())
255248
->method('getQuoteId')
256249
->will($this->returnValue(null));
257250
$this->quote->expects($this->any())
258251
->method('setQuoteId')
259252
->with($quoteId);
253+
$cartInterfaceMock = $this->getMock(
254+
'\Magento\Quote\Api\Data\CartInterface',
255+
[
256+
'getId',
257+
'setId',
258+
'getCreatedAt',
259+
'setCreatedAt',
260+
'getUpdatedAt',
261+
'setUpdatedAt',
262+
'getConvertedAt',
263+
'setConvertedAt',
264+
'getIsActive',
265+
'setIsActive',
266+
'getIsVirtual',
267+
'getItems',
268+
'setItems',
269+
'getItemsCount',
270+
'setItemsCount',
271+
'getItemsQty',
272+
'setItemsQty',
273+
'getCustomer',
274+
'setCustomer',
275+
'getBillingAddress',
276+
'setBillingAddress',
277+
'getReservedOrderId',
278+
'setReservedOrderId',
279+
'getOrigOrderId',
280+
'setOrigOrderId',
281+
'getCurrency',
282+
'setCurrency',
283+
'getCustomerIsGuest',
284+
'setCustomerIsGuest',
285+
'getCustomerNote',
286+
'setCustomerNote',
287+
'getCustomerNoteNotify',
288+
'setCustomerNoteNotify',
289+
'getCustomerTaxClassId',
290+
'setCustomerTaxClassId',
291+
'getStoreId',
292+
'setStoreId',
293+
'getExtensionAttributes',
294+
'setExtensionAttributes',
295+
'setIgnoreOldQty',
296+
'setIsSuperMode',
297+
'setCustomerGroupId'
298+
]
299+
);
300+
$this->quoteFactoryMock->expects($this->once())
301+
->method('create')
302+
->willReturn($cartInterfaceMock);
260303
$this->quote->expects($this->any())
261304
->method('getStoreId')
262305
->will($this->returnValue($storeId));
263306
$this->quote->expects($this->any())
264307
->method('getCustomerId')
265308
->will($this->returnValue($customerId));
309+
$cartInterfaceMock->expects($this->atLeastOnce())
310+
->method('getId')
311+
->willReturn($quoteId);
312+
266313

267314
$defaultGroup = $this->getMockBuilder('Magento\Customer\Api\Data\GroupInterface')
268315
->getMock();
@@ -297,14 +344,10 @@ public function testGetQuoteWithoutQuoteId()
297344
false
298345
);
299346
$this->quoteRepositoryMock->expects($this->once())->method('get')->willReturn($quoteMock);
300-
$quoteMock->expects($this->once())
347+
$cartInterfaceMock->expects($this->once())
301348
->method('setCustomerGroupId')
302349
->with($customerGroupId)
303350
->will($this->returnSelf());
304-
$quoteMock->expects($this->once())
305-
->method('setIsActive')
306-
->with(false)
307-
->will($this->returnSelf());
308351
$quoteMock->expects($this->once())
309352
->method('assignCustomer')
310353
->with($dataCustomerMock);

app/code/Magento/Checkout/view/frontend/layout/default.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
</item>
5757
</argument>
5858
</arguments>
59+
<container name="minicart.addons" label="Mini-cart promotion block"/>
5960
</block>
6061
</referenceContainer>
6162
</body>

app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<div id="minicart-content-wrapper" data-bind="scope: 'minicart_content'">
4040
<!-- ko template: getTemplate() --><!-- /ko -->
4141
</div>
42+
<?php echo $block->getChildHtml('minicart.addons'); ?>
4243
</div>
4344
<?php endif ?>
4445
<script>

app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ define(
116116
},
117117

118118
addressToEstimationAddress: function (address) {
119-
var estimatedAddressData = {
120-
country_id: address.countryId,
121-
region: address.region,
122-
region_id: address.regionId,
123-
postcode: address.postcode
124-
};
125-
return this.formAddressDataToQuoteAddress(estimatedAddressData);
119+
var self = this;
120+
var estimatedAddressData = {};
121+
122+
$.each(address, function (key) {
123+
estimatedAddressData[self.toUnderscore(key)] = address[key];
124+
});
125+
return this.formAddressDataToQuoteAddress(estimatedAddressData);
126126
}
127127
};
128128
}

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ define(
2929
var checkoutConfig = window.checkoutConfig,
3030
validators = [],
3131
observedElements = [],
32-
postcodeElement = null;
32+
postcodeElement = null,
33+
postcodeElementName = 'postcode';
3334

3435
return {
3536
validateAddressTimeout: 0,
@@ -50,7 +51,7 @@ define(
5051
* @return {Boolean}
5152
*/
5253
validateAddressData: function (address) {
53-
return validators.some(function(validator) {
54+
return validators.some(function (validator) {
5455
return validator.validate(address);
5556
});
5657
},
@@ -64,6 +65,11 @@ define(
6465
var self = this,
6566
elements = shippingRatesValidationRules.getObservableFields();
6667

68+
if ($.inArray(postcodeElementName, elements) === -1) {
69+
// Add postcode field to observables if not exist for zip code validation support
70+
elements.push(postcodeElementName);
71+
}
72+
6773
$.each(elements, function (index, field) {
6874
uiRegistry.async(formPath + '.' + field)(self.doElementBinding.bind(self));
6975
});
@@ -80,12 +86,12 @@ define(
8086
var observableFields = shippingRatesValidationRules.getObservableFields();
8187

8288
if (element && (observableFields.indexOf(element.index) !== -1 || force)) {
83-
if (element.index !== 'postcode') {
89+
if (element.index !== postcodeElementName) {
8490
this.bindHandler(element, delay);
8591
}
8692
}
8793

88-
if (element.index === 'postcode') {
94+
if (element.index === postcodeElementName) {
8995
this.bindHandler(element, delay);
9096
postcodeElement = element;
9197
}

app/code/Magento/Checkout/view/frontend/web/js/proceed-to-checkout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ define([
1818

1919
event.preventDefault();
2020

21-
if (!customer().firstname && !cart().isGuestCheckoutAllowed) {
21+
if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
2222
authenticationPopup.showModal();
2323

2424
return false;

app/code/Magento/Checkout/view/frontend/web/js/sidebar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ define([
5454
var cart = customerData.get('cart'),
5555
customer = customerData.get('customer');
5656

57-
if (!customer().firstname && !cart().isGuestCheckoutAllowed) {
57+
if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {
5858
// set URL for redirect on successful login/registration. It's postprocessed on backend.
5959
$.cookie('login_redirect', this.options.url.checkout);
6060
if (this.options.url.isRedirectRequired) {

app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ define(
159159
if (customer.isLoggedIn() && !this.customerHasAddresses) {
160160
this.saveInAddressBook(1);
161161
}
162-
addressData.save_in_address_book = this.saveInAddressBook();
162+
addressData.save_in_address_book = this.saveInAddressBook() ? 1 : 0;
163163
newBillingAddress = createBillingAddress(addressData);
164164

165165
// New address must be selected as a billing address

app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ define(
183183

184184
if (!this.source.get('params.invalid')) {
185185
addressData = this.source.get('shippingAddress');
186-
addressData.save_in_address_book = this.saveInAddressBook;
186+
// if user clicked the checkbox, its value is true or false. Need to convert.
187+
addressData.save_in_address_book = this.saveInAddressBook ? 1 : 0;
187188

188189
// New address must be selected as a shipping address
189190
newShippingAddress = createShippingAddress(addressData);

0 commit comments

Comments
 (0)