Skip to content

Commit d4e666f

Browse files
author
Oleksii Korshenko
authored
Merge pull request magento#1711 from magento-engcom/2.2-develop-prs
Public Pull Requests magento#11952 11832: Create order (on Customer edit page) - not working from admin environment by @RomaKis magento#12141 Fix js error when disable/enable wysiwyg editor by @vovayatsyuk magento#12130 [Backport 2.2] MAGETWO-71697: Fix possible bug when saving address with empty street line magento#10582 by @vovayatsyuk magento#12173 8022: Uncaught Error: Call to a member function addItem() on array in app/code/Magento/Sales/Model/Order/Shipment.php(backport to 2.2) by @RomaKis magento#12001 11532: Duplicate Simple Product Throws Error: Undefined offset: 0 in SaveHandler.php on line 122 by @RomaKis magento#12077 10628: Color attribute swatches are not visible if sorting is enabled by @RomaKis magento#12035 Fix newsletter subscriptions between stores by @sbaixauli magento#11274 Fix magento#10477 Check cart rule subselect conditions against quote item children too by @marinagociu Fixed Public Issues magento#11832 Create order (on Customer edit page) - not working from admin environment magento#8022 Uncaught Error: Call to a member function addItem() on array in app/code/Magento/Sales/Model/Order/Shipment.php magento#11532 Duplicate Simple Product Throws Error: Undefined offset: 0 in SaveHandler.php on line 122 magento#10628 Color attribute swatches are not visible if sorting is enabled magento#10014 Newsletter subscriptions status not isolated between multi stores magento#10477 Cart price rule has failed if use dropdown attribute
2 parents 4967544 + a8e511e commit d4e666f

File tree

21 files changed

+303
-34
lines changed

21 files changed

+303
-34
lines changed

app/code/Magento/Catalog/Model/Category/Link/SaveHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ private function mergeCategoryLinks($newCategoryPositions, $oldCategoryPositions
119119

120120
if ($key === false) {
121121
$result[] = $newCategoryPosition;
122-
} elseif ($oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']) {
122+
} elseif (isset($oldCategoryPositions[$key])
123+
&& $oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']
124+
) {
123125
$result[] = $newCategoryPositions[$key];
124126
unset($oldCategoryPositions[$key]);
125127
}

app/code/Magento/Catalog/Model/ResourceModel/Config.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ public function getAttributesUsedForSortBy()
149149
['main_table' => $this->getTable('eav_attribute')]
150150
)->join(
151151
['additional_table' => $this->getTable('catalog_eav_attribute')],
152-
'main_table.attribute_id = additional_table.attribute_id',
153-
[]
152+
'main_table.attribute_id = additional_table.attribute_id'
154153
)->joinLeft(
155154
['al' => $this->getTable('eav_attribute_label')],
156155
'al.attribute_id = main_table.attribute_id AND al.store_id = ' . $this->getStoreId(),

app/code/Magento/Catalog/Test/Unit/Model/Category/Link/SaveHandlerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,21 @@ public function getCategoryDataProvider()
197197
],
198198
[], //affected category_ids
199199
],
200+
[
201+
[3], //model category_ids
202+
[
203+
['category_id' => 3, 'position' => 20],
204+
['category_id' => 4, 'position' => 30],
205+
], // dto category links
206+
[
207+
['category_id' => 3, 'position' => 10],
208+
],
209+
[
210+
['category_id' => 3, 'position' => 20],
211+
['category_id' => 4, 'position' => 30],
212+
],
213+
[3, 4], //affected category_ids
214+
],
200215
];
201216
}
202217

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Model\ResourceModel;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
11+
/**
12+
* Test for Magento\Catalog\Model\ResourceModel\Config
13+
*/
14+
class ConfigTest extends \PHPUnit\Framework\TestCase
15+
{
16+
/**
17+
* @var \Magento\Catalog\Model\ResourceModel\Config
18+
*/
19+
private $model;
20+
21+
/**
22+
* @var \PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $resource;
25+
26+
/**
27+
* @var \PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $storeManager;
30+
31+
/**
32+
* @var \PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $eavConfig;
35+
36+
protected function setUp()
37+
{
38+
$objectManager = new ObjectManager($this);
39+
40+
$this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
41+
$this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
42+
$this->eavConfig = $this->createMock(\Magento\Eav\Model\Config::class);
43+
44+
$this->model = $objectManager->getObject(
45+
\Magento\Catalog\Model\ResourceModel\Config::class,
46+
[
47+
'resource' => $this->resource,
48+
'storeManager' => $this->storeManager,
49+
'eavConfig' => $this->eavConfig,
50+
]
51+
);
52+
53+
parent::setUp();
54+
}
55+
56+
public function testGetAttributesUsedForSortBy()
57+
{
58+
$expression = 'someExpression';
59+
$storeId = 1;
60+
$entityTypeId = 4;
61+
62+
$connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
63+
$selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
64+
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
65+
$entityTypeMock = $this->createMock(\Magento\Eav\Model\Entity\Type::class);
66+
67+
$this->resource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connectionMock);
68+
69+
$connectionMock->expects($this->once())->method('getCheckSql')
70+
->with('al.value IS NULL', 'main_table.frontend_label', 'al.value')
71+
->willReturn($expression);
72+
$connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($selectMock);
73+
74+
$this->resource->expects($this->exactly(3))->method('getTableName')->withConsecutive(
75+
['eav_attribute'],
76+
['catalog_eav_attribute'],
77+
['eav_attribute_label']
78+
)->willReturnOnConsecutiveCalls('eav_attribute', 'catalog_eav_attribute', 'eav_attribute_label');
79+
80+
$this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
81+
$storeMock->expects($this->once())->method('getId')->willReturn($storeId);
82+
83+
$this->eavConfig->expects($this->once())->method('getEntityType')->willReturn($entityTypeMock);
84+
$entityTypeMock->expects($this->once())->method('getId')->willReturn($entityTypeId);
85+
86+
$selectMock->expects($this->once())->method('from')
87+
->with(['main_table' => 'eav_attribute'])->willReturn($selectMock);
88+
$selectMock->expects($this->once())->method('join')->with(
89+
['additional_table' => 'catalog_eav_attribute'],
90+
'main_table.attribute_id = additional_table.attribute_id'
91+
)->willReturn($selectMock);
92+
$selectMock->expects($this->once())->method('joinLeft')
93+
->with(
94+
['al' => 'eav_attribute_label'],
95+
'al.attribute_id = main_table.attribute_id AND al.store_id = ' . $storeId,
96+
['store_label' => $expression]
97+
)->willReturn($selectMock);
98+
$selectMock->expects($this->exactly(2))->method('where')->withConsecutive(
99+
['main_table.entity_type_id = ?', $entityTypeId],
100+
['additional_table.used_for_sort_by = ?', 1]
101+
)->willReturn($selectMock);
102+
103+
$connectionMock->expects($this->once())->method('fetchAll')->with($selectMock);
104+
105+
$this->model->getAttributesUsedForSortBy();
106+
}
107+
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function setData($key, $value = null)
269269
{
270270
if (is_array($key)) {
271271
$key = $this->_implodeArrayField($key);
272-
} elseif (is_array($value) && !empty($value) && $this->isAddressMultilineAttribute($key)) {
272+
} elseif (is_array($value) && $this->isAddressMultilineAttribute($key)) {
273273
$value = $this->_implodeArrayValues($value);
274274
}
275275
return parent::setData($key, $value);
@@ -309,7 +309,11 @@ protected function _implodeArrayField(array $data)
309309
*/
310310
protected function _implodeArrayValues($value)
311311
{
312-
if (is_array($value) && count($value)) {
312+
if (is_array($value)) {
313+
if (!count($value)) {
314+
return '';
315+
}
316+
313317
$isScalar = false;
314318
foreach ($value as $val) {
315319
if (is_scalar($val)) {

app/code/Magento/Customer/Test/Unit/Model/Address/AbstractAddressTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ public function testGetStreetFullAlwaysReturnsString($expectedResult, $street)
366366
$this->assertEquals($expectedResult, $this->model->getStreetFull());
367367
}
368368

369+
/**
370+
* @dataProvider getStreetFullDataProvider
371+
*/
372+
public function testSetDataStreetAlwaysConvertedToString($expectedResult, $street)
373+
{
374+
$this->model->setData('street', $street);
375+
$this->assertEquals($expectedResult, $this->model->getData('street'));
376+
}
377+
369378
/**
370379
* @return array
371380
*/

app/code/Magento/Newsletter/Model/ResourceModel/Subscriber.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,37 @@ public function loadByEmail($subscriberEmail)
118118
*/
119119
public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
120120
{
121-
$select = $this->connection->select()->from($this->getMainTable())->where('customer_id=:customer_id');
122-
123-
$result = $this->connection->fetchRow($select, ['customer_id' => $customer->getId()]);
121+
$select = $this->connection
122+
->select()
123+
->from($this->getMainTable())
124+
->where('customer_id=:customer_id and store_id=:store_id');
125+
126+
$result = $this->connection
127+
->fetchRow(
128+
$select,
129+
[
130+
'customer_id' => $customer->getId(),
131+
'store_id' => $customer->getStoreId()
132+
]
133+
);
124134

125135
if ($result) {
126136
return $result;
127137
}
128138

129-
$select = $this->connection->select()->from($this->getMainTable())->where('subscriber_email=:subscriber_email');
130-
131-
$result = $this->connection->fetchRow($select, ['subscriber_email' => $customer->getEmail()]);
139+
$select = $this->connection
140+
->select()
141+
->from($this->getMainTable())
142+
->where('subscriber_email=:subscriber_email and store_id=:store_id');
143+
144+
$result = $this->connection
145+
->fetchRow(
146+
$select,
147+
[
148+
'subscriber_email' => $customer->getEmail(),
149+
'store_id' => $customer->getStoreId()
150+
]
151+
);
132152

133153
if ($result) {
134154
return $result;

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ public function loadByCustomerId($customerId)
360360
{
361361
try {
362362
$customerData = $this->customerRepository->getById($customerId);
363+
$customerData->setStoreId($this->_storeManager->getStore()->getId());
363364
$data = $this->getResource()->loadByCustomerData($customerData);
364365
$this->addData($data);
365366
if (!empty($data) && $customerData->getId() && !$this->getCustomerId()) {

app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ public function testUpdateSubscription()
187187
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
188188
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
189189

190+
$storeModel = $this->getMockBuilder(\Magento\Store\Model\Store::class)
191+
->disableOriginalConstructor()
192+
->setMethods(['getId'])
193+
->getMock();
194+
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
195+
190196
$this->assertEquals($this->subscriber, $this->subscriber->updateSubscription($customerId));
191197
}
192198

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* Test class for sales quote address model
3535
*
3636
* @see \Magento\Quote\Model\Quote\Address
37+
* @SuppressWarnings(PHPMD.TooManyFields)
3738
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3839
*/
3940
class AddressTest extends \PHPUnit\Framework\TestCase
@@ -48,6 +49,11 @@ class AddressTest extends \PHPUnit\Framework\TestCase
4849
*/
4950
private $quote;
5051

52+
/**
53+
* @var \Magento\Quote\Model\Quote\Address\CustomAttributeListInterface | \PHPUnit_Framework_MockObject_MockObject
54+
*/
55+
private $attributeList;
56+
5157
/**
5258
* @var \Magento\Framework\App\Config | \PHPUnit_Framework_MockObject_MockObject
5359
*/
@@ -166,9 +172,13 @@ protected function setUp()
166172
->disableOriginalConstructor()
167173
->getMock();
168174

175+
$this->attributeList = $this->createMock(\Magento\Quote\Model\Quote\Address\CustomAttributeListInterface::class);
176+
$this->attributeList->method('getAttributes')->willReturn([]);
177+
169178
$this->address = $objectManager->getObject(
170179
\Magento\Quote\Model\Quote\Address::class,
171180
[
181+
'attributeList' => $this->attributeList,
172182
'scopeConfig' => $this->scopeConfig,
173183
'serializer' => $this->serializer,
174184
'storeManager' => $this->storeManager,

0 commit comments

Comments
 (0)