Skip to content

Commit 2cc846e

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1613 from magento-engcom/2.2-develop-prs
Public Pull Requests #11591 [Backport 2.2-develop] #11586 Fix duplicated crontab 2>&1 expression by @adrian-martinez-interactiv4 #11561 Magento sets ISO invalid language code by @crissanclick #11553 [2.2 Backport] ProductRepository sku cache is corrupted when cacheLimit is reached by @heldchen #11439 [Backport 2.2-develop] #11328 : app:config:dump adds extra space every time in multiline array value by @adrian-martinez-interactiv4 #11510 Add interaction to admin:user:create command by @cmuench #11522 [Backport 2.2-develop] Fix Filter Customer Report Review by @osrecio #11499 Ensure database is cleared/Magento reinstalled when TESTS_CLEANUP is enabled by @joshuaswarren #11385 Fix #10856: Sync billing with shipping address on Admin Order Page by @joni-jones #11317 [Backport 2.2-develop] Send email to subscribers only when are new by @osrecio
2 parents 4d26093 + c18524a commit 2cc846e

File tree

20 files changed

+427
-104
lines changed

20 files changed

+427
-104
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private function cacheProduct($cacheKey, \Magento\Catalog\Api\Data\ProductInterf
312312
if ($this->cacheLimit && count($this->instances) > $this->cacheLimit) {
313313
$offset = round($this->cacheLimit / -2);
314314
$this->instancesById = array_slice($this->instancesById, $offset, null, true);
315-
$this->instances = array_slice($this->instances, $offset);
315+
$this->instances = array_slice($this->instances, $offset, null, true);
316316
}
317317
}
318318

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ public function subscribe($email)
395395
{
396396
$this->loadByEmail($email);
397397

398+
if ($this->getId() && $this->getStatus() == self::STATUS_SUBSCRIBED) {
399+
return $this->getStatus();
400+
}
401+
398402
if (!$this->getId()) {
399403
$this->setSubscriberConfirmCode($this->randomSequence());
400404
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,8 @@ public function validateMinimumAmount()
11701170
*/
11711171
public function getAppliedTaxes()
11721172
{
1173-
return $this->serializer->unserialize($this->getData('applied_taxes'));
1173+
$taxes = $this->getData('applied_taxes');
1174+
return $taxes ? $this->serializer->unserialize($taxes) : [];
11741175
}
11751176

11761177
/**

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Magento\Quote\Test\Unit\Model\Quote;
1010

1111
use Magento\Directory\Model\Currency;
12-
use \Magento\Quote\Model\Quote\Address;
12+
use Magento\Quote\Model\Quote\Address;
1313
use Magento\Quote\Model\Quote\Address\Rate;
1414
use Magento\Quote\Model\ResourceModel\Quote\Address\Rate\CollectionFactory as RateCollectionFactory;
1515
use Magento\Quote\Model\ResourceModel\Quote\Address\Rate\Collection as RatesCollection;
@@ -28,6 +28,7 @@
2828
use Magento\Store\Api\Data\StoreInterface;
2929
use Magento\Store\Api\Data\WebsiteInterface;
3030
use Magento\Quote\Model\Quote\Address\RateResult\AbstractResult;
31+
use Magento\Framework\Serialize\Serializer\Json;
3132

3233
/**
3334
* Test class for sales quote address model
@@ -117,7 +118,7 @@ protected function setUp()
117118
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
118119

119120
$this->scopeConfig = $this->createMock(\Magento\Framework\App\Config::class);
120-
$this->serializer = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
121+
$this->serializer = new Json();
121122

122123
$this->requestFactory = $this->getMockBuilder(RateRequestFactory::class)
123124
->disableOriginalConstructor()
@@ -273,20 +274,17 @@ public function testValidateMiniumumAmountNegative()
273274
public function testSetAndGetAppliedTaxes()
274275
{
275276
$data = ['data'];
276-
$result = json_encode($data);
277-
278-
$this->serializer->expects($this->once())
279-
->method('serialize')
280-
->with($data)
281-
->willReturn($result);
282-
283-
$this->serializer->expects($this->once())
284-
->method('unserialize')
285-
->with($result)
286-
->willReturn($data);
277+
self::assertInstanceOf(Address::class, $this->address->setAppliedTaxes($data));
278+
self::assertEquals($data, $this->address->getAppliedTaxes());
279+
}
287280

288-
$this->assertInstanceOf(\Magento\Quote\Model\Quote\Address::class, $this->address->setAppliedTaxes($data));
289-
$this->assertEquals($data, $this->address->getAppliedTaxes());
281+
/**
282+
* Checks a case, when applied taxes are not provided.
283+
*/
284+
public function testGetAppliedTaxesWithEmptyValue()
285+
{
286+
$this->address->setData('applied_taxes', null);
287+
self::assertEquals([], $this->address->getAppliedTaxes());
290288
}
291289

292290
/**

app/code/Magento/Reports/Model/ResourceModel/Review/Customer/Collection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ protected function _joinCustomers()
110110
*/
111111
public function getSelectCountSql()
112112
{
113-
$countSelect = clone $this->_select;
113+
$countSelect = clone $this->getSelect();
114114
$countSelect->reset(\Magento\Framework\DB\Select::ORDER);
115115
$countSelect->reset(\Magento\Framework\DB\Select::GROUP);
116116
$countSelect->reset(\Magento\Framework\DB\Select::HAVING);
117117
$countSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
118118
$countSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
119119
$countSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
120+
$countSelect->reset(\Magento\Framework\DB\Select::WHERE);
120121

121122
$countSelect->columns(new \Zend_Db_Expr('COUNT(DISTINCT detail.customer_id)'));
122123

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use Magento\Customer\Api\AddressMetadataInterface;
1212
use Magento\Customer\Model\Metadata\Form as CustomerForm;
13+
use Magento\Framework\App\ObjectManager;
14+
use Magento\Quote\Model\Quote\Address;
1315
use Magento\Quote\Model\Quote\Item;
1416

1517
/**
@@ -323,7 +325,7 @@ public function __construct(
323325
$this->dataObjectHelper = $dataObjectHelper;
324326
$this->orderManagement = $orderManagement;
325327
$this->quoteFactory = $quoteFactory;
326-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
328+
$this->serializer = $serializer ?: ObjectManager::getInstance()
327329
->get(\Magento\Framework\Serialize\Serializer\Json::class);
328330
parent::__construct($data);
329331
}
@@ -1449,32 +1451,36 @@ public function getBillingAddress()
14491451
*/
14501452
public function setBillingAddress($address)
14511453
{
1452-
if (is_array($address)) {
1453-
$billingAddress = $this->_objectManager->create(
1454-
\Magento\Quote\Model\Quote\Address::class
1455-
)->setData(
1456-
$address
1457-
)->setAddressType(
1458-
\Magento\Quote\Model\Quote\Address::TYPE_BILLING
1459-
);
1460-
$this->_setQuoteAddress($billingAddress, $address);
1461-
/**
1462-
* save_in_address_book is not a valid attribute and is filtered out by _setQuoteAddress,
1463-
* that is why it should be added after _setQuoteAddress call
1464-
*/
1465-
$saveInAddressBook = (int)(!empty($address['save_in_address_book']));
1466-
$billingAddress->setData('save_in_address_book', $saveInAddressBook);
1467-
1468-
if (!$this->getQuote()->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
1469-
$shippingAddress = clone $billingAddress;
1470-
$shippingAddress->setSameAsBilling(true);
1471-
$shippingAddress->setSaveInAddressBook(false);
1472-
$address['save_in_address_book'] = 0;
1473-
$this->setShippingAddress($address);
1474-
}
1454+
if (!is_array($address)) {
1455+
return $this;
1456+
}
1457+
1458+
$billingAddress = $this->_objectManager->create(Address::class)
1459+
->setData($address)
1460+
->setAddressType(Address::TYPE_BILLING);
1461+
1462+
$this->_setQuoteAddress($billingAddress, $address);
1463+
1464+
/**
1465+
* save_in_address_book is not a valid attribute and is filtered out by _setQuoteAddress,
1466+
* that is why it should be added after _setQuoteAddress call
1467+
*/
1468+
$saveInAddressBook = (int)(!empty($address['save_in_address_book']));
1469+
$billingAddress->setData('save_in_address_book', $saveInAddressBook);
1470+
1471+
$quote = $this->getQuote();
1472+
if (!$quote->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
1473+
$address['save_in_address_book'] = 0;
1474+
$this->setShippingAddress($address);
1475+
}
14751476

1476-
$this->getQuote()->setBillingAddress($billingAddress);
1477+
// not assigned billing address should be saved as new
1478+
// but if quote already has the billing address it won't be overridden
1479+
if (empty($billingAddress->getCustomerAddressId())) {
1480+
$billingAddress->setCustomerAddressId(null);
1481+
$quote->getBillingAddress()->setCustomerAddressId(null);
14771482
}
1483+
$quote->setBillingAddress($billingAddress);
14781484

14791485
return $this;
14801486
}
@@ -1775,6 +1781,7 @@ public function _prepareCustomer()
17751781
$address = $this->getShippingAddress()->setCustomerId($this->getQuote()->getCustomer()->getId());
17761782
$this->setShippingAddress($address);
17771783
}
1784+
$this->getBillingAddress()->setCustomerId($customer->getId());
17781785
$this->getQuote()->updateCustomerData($this->getQuote()->getCustomer());
17791786

17801787
$customer = $this->getQuote()->getCustomer();

app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ define([
157157
}
158158
if(this.addresses[id]){
159159
this.fillAddressFields(container, this.addresses[id]);
160+
160161
}
161162
else{
162163
this.fillAddressFields(container, {});
@@ -190,43 +191,53 @@ define([
190191
}
191192
},
192193

193-
changeAddressField : function(event){
194-
var field = Event.element(event);
195-
var re = /[^\[]*\[([^\]]*)_address\]\[([^\]]*)\](\[(\d)\])?/;
196-
var matchRes = field.name.match(re);
194+
/**
195+
* Triggers on each form's element changes.
196+
*
197+
* @param {Object} event
198+
*/
199+
changeAddressField: function (event) {
200+
var field = Event.element(event),
201+
re = /[^\[]*\[([^\]]*)_address\]\[([^\]]*)\](\[(\d)\])?/,
202+
matchRes = field.name.match(re),
203+
type,
204+
name,
205+
data;
197206

198207
if (!matchRes) {
199208
return;
200209
}
201210

202-
var type = matchRes[1];
203-
var name = matchRes[2];
204-
var data;
211+
type = matchRes[1];
212+
name = matchRes[2];
205213

206-
if(this.isBillingField(field.id)){
207-
data = this.serializeData(this.billingAddressContainer)
208-
}
209-
else{
210-
data = this.serializeData(this.shippingAddressContainer)
214+
if (this.isBillingField(field.id)) {
215+
data = this.serializeData(this.billingAddressContainer);
216+
} else {
217+
data = this.serializeData(this.shippingAddressContainer);
211218
}
212219
data = data.toObject();
213220

214-
if( (type == 'billing' && this.shippingAsBilling)
215-
|| (type == 'shipping' && !this.shippingAsBilling) ) {
221+
if (type === 'billing' && this.shippingAsBilling || type === 'shipping' && !this.shippingAsBilling) {
216222
data['reset_shipping'] = true;
217223
}
218224

219-
data['order['+type+'_address][customer_address_id]'] = $('order-'+type+'_address_customer_address_id').value;
225+
data['order[' + type + '_address][customer_address_id]'] = null;
226+
data['shipping_as_billing'] = jQuery('[name="shipping_same_as_billing"]').is(':checked') ? 1 : 0;
227+
228+
if (name === 'customer_address_id') {
229+
data['order[' + type + '_address][customer_address_id]'] =
230+
$('order-' + type + '_address_customer_address_id').value;
231+
}
220232

221233
if (data['reset_shipping']) {
222234
this.resetShippingMethod(data);
223235
} else {
224236
this.saveData(data);
225-
if (name == 'country_id' || name == 'customer_address_id') {
237+
238+
if (name === 'country_id' || name === 'customer_address_id') {
226239
this.loadArea(['shipping_method', 'billing_method', 'totals', 'items'], true, data);
227240
}
228-
// added for reloading of default sender and default recipient for giftmessages
229-
//this.loadArea(['giftmessage'], true, data);
230241
}
231242
},
232243

dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ public function run()
2626
/**
2727
* {@inheritdoc}
2828
*/
29-
public function install()
29+
public function install($cleanup)
3030
{
31+
if ($cleanup) {
32+
$this->cleanup();
33+
}
34+
3135
$installOptions = $this->getInstallConfig();
3236

3337
/* Install application */

dev/tests/api-functional/framework/bootstrap.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@
5858
);
5959

6060
if (defined('TESTS_MAGENTO_INSTALLATION') && TESTS_MAGENTO_INSTALLATION === 'enabled') {
61-
if (defined('TESTS_CLEANUP') && TESTS_CLEANUP === 'enabled') {
62-
$application->cleanup();
63-
}
64-
$application->install();
61+
$cleanup = (defined('TESTS_CLEANUP') && TESTS_CLEANUP === 'enabled');
62+
$application->install($cleanup);
6563
}
6664

6765
$bootstrap = new \Magento\TestFramework\Bootstrap(

dev/tests/integration/framework/Magento/TestFramework/Application.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,11 @@ public function cleanup()
435435
/**
436436
* Install an application
437437
*
438+
* @param bool $cleanup
438439
* @return void
439440
* @throws \Magento\Framework\Exception\LocalizedException
440441
*/
441-
public function install()
442+
public function install($cleanup)
442443
{
443444
$dirs = \Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS;
444445
$this->_ensureDirExists($this->installDir);
@@ -453,8 +454,9 @@ public function install()
453454
$installParams = $this->getInstallCliParams();
454455

455456
// performance optimization: restore DB from last good dump to make installation on top of it (much faster)
457+
// do not restore from the database if the cleanup option is set to ensure we have a clean DB to test on
456458
$db = $this->getDbInstance();
457-
if ($db->isDbDumpExists()) {
459+
if ($db->isDbDumpExists() && !$cleanup) {
458460
$db->restoreFromDbDump();
459461
}
460462

dev/tests/integration/framework/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
$application->cleanup();
7575
}
7676
if (!$application->isInstalled()) {
77-
$application->install();
77+
$application->install($settings->getAsBoolean('TESTS_CLEANUP'));
7878
}
7979
$application->initialize([]);
8080

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Reports\Model\ResourceModel\Review\Customer;
7+
8+
/**
9+
* @magentoAppArea adminhtml
10+
*/
11+
class CollectionTest extends \PHPUnit\Framework\TestCase
12+
{
13+
/**
14+
* @var \Magento\Reports\Model\ResourceModel\Review\Customer\Collection
15+
*/
16+
private $collection;
17+
18+
protected function setUp()
19+
{
20+
$this->collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
21+
\Magento\Reports\Model\ResourceModel\Review\Customer\Collection::class
22+
);
23+
}
24+
25+
/**
26+
* This tests covers issue described in:
27+
* https://github.com/magento/magento2/issues/10301
28+
*
29+
* @magentoDataFixture Magento/Review/_files/customer_review.php
30+
*/
31+
public function testSelectCountSql()
32+
{
33+
$this->collection->addFieldToFilter('customer_name', ['like' => '%john%']);
34+
$this->assertEquals(1, $this->collection->getSize());
35+
}
36+
}

0 commit comments

Comments
 (0)