Skip to content

Commit a89acbb

Browse files
committed
Merge pull request #519 from magento-folks/bugfix
[Folks] Bugfix
2 parents f732a63 + e9fe699 commit a89acbb

File tree

14 files changed

+196
-31
lines changed

14 files changed

+196
-31
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
*/
55
/*jshint browser:true jquery:true*/
66
/*global alert*/
7-
define([], function() {
7+
define([], function () {
88
/**
9-
* @param addressData
9+
* @param {Object} addressData
1010
* Returns new address object
1111
*/
1212
return function (addressData) {
1313
var identifier = Date.now();
14+
1415
return {
1516
email: addressData.email,
1617
countryId: (addressData.country_id) ? addressData.country_id : window.checkoutConfig.defaultCountryId,
17-
regionId: (addressData.region && addressData.region.region_id)
18-
? addressData.region.region_id
18+
regionId: (addressData.region && addressData.region.region_id) ?
19+
addressData.region.region_id
1920
: window.checkoutConfig.defaultRegionId,
2021
regionCode: (addressData.region) ? addressData.region.region_code : null,
2122
region: (addressData.region) ? addressData.region.region : null,
@@ -33,25 +34,26 @@ define([], function() {
3334
suffix: addressData.suffix,
3435
vatId: addressData.vat_id,
3536
saveInAddressBook: addressData.save_in_address_book,
36-
isDefaultShipping: function() {
37+
customAttributes: addressData.custom_attributes,
38+
isDefaultShipping: function () {
3739
return addressData.default_shipping;
3840
},
39-
isDefaultBilling: function() {
41+
isDefaultBilling: function () {
4042
return addressData.default_billing;
4143
},
42-
getType: function() {
44+
getType: function () {
4345
return 'new-customer-address';
4446
},
45-
getKey: function() {
47+
getKey: function () {
4648
return this.getType();
4749
},
48-
getCacheKey: function() {
50+
getCacheKey: function () {
4951
return this.getType() + identifier;
5052
},
51-
isEditable: function() {
53+
isEditable: function () {
5254
return true;
5355
},
54-
canUseForBilling: function() {
56+
canUseForBilling: function () {
5557
return true;
5658
}
5759
}

app/code/Magento/Checkout/view/frontend/web/js/model/quote.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ define(
4444
return totals;
4545
},
4646
setTotals: function(totalsData) {
47-
if (_.isObject(totalsData.extension_attributes)) {
47+
if (_.isObject(totalsData) && _.isObject(totalsData.extension_attributes)) {
4848
_.each(totalsData.extension_attributes, function(element, index) {
4949
totalsData[index] = element;
5050
});

app/code/Magento/Customer/Model/Address.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ class Address extends \Magento\Customer\Model\Address\AbstractAddress
4747
*/
4848
protected $indexerRegistry;
4949

50+
/**
51+
* @var \Magento\Customer\Model\Address\CustomAttributeListInterface
52+
*/
53+
private $attributeList;
54+
5055
/**
5156
* @param \Magento\Framework\Model\Context $context
5257
* @param \Magento\Framework\Registry $registry
@@ -347,4 +352,27 @@ public function reindex()
347352
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
348353
$indexer->reindexRow($this->getCustomerId());
349354
}
355+
356+
/**
357+
* {@inheritdoc}
358+
*/
359+
protected function getCustomAttributesCodes()
360+
{
361+
return array_keys($this->getAttributeList()->getAttributes());
362+
}
363+
364+
/**
365+
* Get new AttributeList dependency for application code.
366+
* @return \Magento\Customer\Model\Address\CustomAttributeListInterface
367+
* @deprecated
368+
*/
369+
private function getAttributeList()
370+
{
371+
if (!$this->attributeList) {
372+
$this->attributeList = \Magento\Framework\App\ObjectManager::getInstance()->get(
373+
\Magento\Customer\Model\Address\CustomAttributeListInterface::class
374+
);
375+
}
376+
return $this->attributeList;
377+
}
350378
}

app/code/Magento/Customer/Model/Address/AbstractAddress.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public function setData($key, $value = null)
263263
{
264264
if (is_array($key)) {
265265
$key = $this->_implodeArrayField($key);
266-
} elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) {
266+
} elseif (is_array($value) && !empty($value) && $this->isAddressMultilineAttribute($key)) {
267267
$value = $this->_implodeArrayValues($value);
268268
}
269269
return parent::setData($key, $value);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model\Address;
7+
8+
class CustomAttributeList implements CustomAttributeListInterface
9+
{
10+
/**
11+
* {@inheritdoc}
12+
*/
13+
public function getAttributes()
14+
{
15+
return [];
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model\Address;
7+
8+
interface CustomAttributeListInterface
9+
{
10+
/**
11+
* Retrieve list of customer addresses custom attributes
12+
*
13+
* @return array
14+
*/
15+
public function getAttributes();
16+
}

app/code/Magento/Customer/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
type="Magento\Customer\Model\EmailNotification" />
5050
<preference for="Magento\Customer\Api\CustomerNameGenerationInterface"
5151
type="Magento\Customer\Helper\View" />
52+
<preference for="Magento\Customer\Model\Address\CustomAttributeListInterface"
53+
type="Magento\Customer\Model\Address\CustomAttributeList" />
5254
<type name="Magento\Customer\Model\Session">
5355
<arguments>
5456
<argument name="configShare" xsi:type="object">Magento\Customer\Model\Config\Share\Proxy</argument>

app/code/Magento/Customer/view/frontend/web/js/model/customer/address.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ define([], function() {
3232
vatId: addressData.vat_id,
3333
sameAsBilling: addressData.same_as_billing,
3434
saveInAddressBook: addressData.save_in_address_book,
35+
customAttributes: addressData.custom_attributes,
3536
isDefaultShipping: function() {
3637
return addressData.default_shipping;
3738
},

app/code/Magento/Quote/Model/Quote/Item/Compare.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ protected function getOptionValues($value)
2323
if (is_string($value) && is_array(@unserialize($value))) {
2424
$value = @unserialize($value);
2525
unset($value['qty'], $value['uenc']);
26+
$value = array_filter($value, function ($optionValue) {
27+
return !empty($optionValue);
28+
});
2629
}
2730
return $value;
2831
}

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Magento\Sales\Api\OrderManagementInterface as OrderManagement;
2222
use Magento\Store\Model\StoreManagerInterface;
2323
use Magento\Quote\Model\Quote\Address;
24+
use Magento\Framework\App\ObjectManager;
25+
use Magento\Quote\Model\QuoteIdMaskFactory;
2426

2527
/**
2628
* Class QuoteManagement
@@ -130,6 +132,11 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
130132
*/
131133
protected $quoteFactory;
132134

135+
/**
136+
* @var QuoteIdMaskFactory
137+
*/
138+
private $quoteIdMaskFactory;
139+
133140
/**
134141
* @param EventManager $eventManager
135142
* @param QuoteValidator $quoteValidator
@@ -262,6 +269,12 @@ public function assignCustomer($cartId, $customerId, $storeId)
262269

263270
$quote->setCustomer($customer);
264271
$quote->setCustomerIsGuest(0);
272+
$quoteIdMaskFactory = $this->getQuoteIdMaskFactory();
273+
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
274+
$quoteIdMask = $quoteIdMaskFactory->create()->load($cartId, 'quote_id');
275+
if ($quoteIdMask->getId()) {
276+
$quoteIdMask->delete();
277+
}
265278
$this->quoteRepository->save($quote);
266279
return true;
267280

@@ -547,4 +560,16 @@ protected function _prepareCustomerQuote($quote)
547560
$shipping->setIsDefaultBilling(true);
548561
}
549562
}
563+
564+
/**
565+
* @return QuoteIdMaskFactory
566+
* @deprecated
567+
*/
568+
private function getQuoteIdMaskFactory()
569+
{
570+
if (!$this->quoteIdMaskFactory) {
571+
$this->quoteIdMaskFactory = ObjectManager::getInstance()->get(QuoteIdMaskFactory::class);
572+
}
573+
return $this->quoteIdMaskFactory;
574+
}
550575
}

app/code/Magento/Quote/Test/Unit/Model/Quote/Item/CompareTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,31 @@ public function testCompareItemWithoutOptionWithCompared()
187187
->will($this->returnValue([]));
188188
$this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock));
189189
}
190+
191+
/**
192+
* Verify that compare ignores empty options.
193+
*/
194+
public function testCompareWithEmptyValues()
195+
{
196+
$this->itemMock->expects($this->any())
197+
->method('getProductId')
198+
->will($this->returnValue(1));
199+
$this->comparedMock->expects($this->any())
200+
->method('getProductId')
201+
->will($this->returnValue(1));
202+
203+
$this->itemMock->expects($this->once())->method('getOptions')->willReturn([
204+
$this->getOptionMock('option-1', serialize([
205+
'non-empty-option' => 'test',
206+
'empty_option' => ''
207+
]))
208+
]);
209+
$this->comparedMock->expects($this->once())->method('getOptions')->willReturn([
210+
$this->getOptionMock('option-1', serialize([
211+
'non-empty-option' => 'test'
212+
]))
213+
]);
214+
215+
$this->assertTrue($this->helper->compare($this->itemMock, $this->comparedMock));
216+
}
190217
}

app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase
124124
/**
125125
* @var \PHPUnit_Framework_MockObject_MockObject
126126
*/
127-
protected $quoteFactoryMock;
127+
private $quoteIdMock;
128128

129129
/**
130130
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -238,7 +238,6 @@ protected function setUp()
238238
);
239239

240240
$this->quoteFactoryMock = $this->getMock('\Magento\Quote\Model\QuoteFactory', ['create'], [], '', false);
241-
242241
$this->model = $objectManager->getObject(
243242
'\Magento\Quote\Model\QuoteManagement',
244243
[
@@ -264,6 +263,12 @@ protected function setUp()
264263
'quoteFactory' => $this->quoteFactoryMock
265264
]
266265
);
266+
267+
// Set the new dependency
268+
$this->quoteIdMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false);
269+
$quoteIdFactoryMock = $this->getMock(\Magento\Quote\Model\QuoteIdMaskFactory::class, ['create'], [], '', false);
270+
$this->setPropertyValue($this->model, 'quoteIdMaskFactory', $quoteIdFactoryMock);
271+
267272
}
268273

269274
public function testCreateEmptyCartAnonymous()
@@ -508,6 +513,13 @@ public function testAssignCustomer()
508513
$customerId = 455;
509514
$storeId = 5;
510515

516+
$this->getPropertyValue($this->model, 'quoteIdMaskFactory')
517+
->expects($this->once())
518+
->method('create')
519+
->willReturn($this->quoteIdMock);
520+
$this->quoteIdMock->expects($this->once())->method('load')->with($cartId, 'quote_id')->willReturnSelf();
521+
$this->quoteIdMock->expects($this->once())->method('getId')->willReturn(10);
522+
$this->quoteIdMock->expects($this->once())->method('delete');
511523
$quoteMock = $this->getMock(
512524
'\Magento\Quote\Model\Quote',
513525
['getCustomerId', 'setCustomer', 'setCustomerIsGuest'],
@@ -739,7 +751,7 @@ public function testPlaceOrderIfCustomerIsGuest()
739751
$this->checkoutSessionMock->expects($this->once())->method('setLastOrderId')->with($orderId);
740752
$this->checkoutSessionMock->expects($this->once())->method('setLastRealOrderId')->with($orderIncrementId);
741753
$this->checkoutSessionMock->expects($this->once())->method('setLastOrderStatus')->with($orderStatus);
742-
754+
743755
$this->assertEquals($orderId, $service->placeOrder($cartId));
744756
}
745757

@@ -935,7 +947,7 @@ protected function prepareOrderFactory(
935947
$order = $this->getMock(
936948
'Magento\Sales\Model\Order',
937949
['setShippingAddress', 'getAddressesCollection', 'getAddresses', 'getBillingAddress', 'addAddresses',
938-
'setBillingAddress', 'setAddresses', 'setPayment', 'setItems', 'setQuoteId'],
950+
'setBillingAddress', 'setAddresses', 'setPayment', 'setItems', 'setQuoteId'],
939951
[],
940952
'',
941953
false
@@ -979,4 +991,37 @@ public function testGetCartForCustomer()
979991
->willReturn($cartMock);
980992
$this->assertEquals($cartMock, $this->model->getCartForCustomer($customerId));
981993
}
994+
995+
/**
996+
* Get any object property value.
997+
*
998+
* @param $object
999+
* @param $property
1000+
* @return mixed
1001+
*/
1002+
protected function getPropertyValue($object, $property)
1003+
{
1004+
$reflection = new \ReflectionClass(get_class($object));
1005+
$reflectionProperty = $reflection->getProperty($property);
1006+
$reflectionProperty->setAccessible(true);
1007+
1008+
return $reflectionProperty->getValue($object);
1009+
}
1010+
1011+
/**
1012+
* Set object property value.
1013+
*
1014+
* @param $object
1015+
* @param $property
1016+
* @param $value
1017+
*/
1018+
protected function setPropertyValue(&$object, $property, $value)
1019+
{
1020+
$reflection = new \ReflectionClass(get_class($object));
1021+
$reflectionProperty = $reflection->getProperty($property);
1022+
$reflectionProperty->setAccessible(true);
1023+
$reflectionProperty->setValue($object, $value);
1024+
1025+
return $object;
1026+
}
9821027
}

0 commit comments

Comments
 (0)