Skip to content

Commit 8eebafc

Browse files
authored
Merge pull request #3182 from magento-tsg-csl3/2.2-develop-pr2
[TSG-CSL3] Backporting 2.2 (pr2)
2 parents ea1ace7 + c3262d1 commit 8eebafc

File tree

12 files changed

+311
-67
lines changed

12 files changed

+311
-67
lines changed

app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ public function addAttributeToFilter($attribute, $condition = null, $joinType =
374374

375375
if (!empty($conditionSql)) {
376376
$this->getSelect()->where($conditionSql, null, \Magento\Framework\DB\Select::TYPE_CONDITION);
377+
$this->invalidateSize();
377378
} else {
378379
throw new \Magento\Framework\Exception\LocalizedException(
379380
__('Invalid attribute identifier for filter (%1)', get_class($attribute))
@@ -1668,4 +1669,16 @@ public function removeAllFieldsFromSelect()
16681669
{
16691670
return $this->removeAttributeToSelect();
16701671
}
1672+
1673+
/**
1674+
* Invalidates "Total Records Count".
1675+
* Invalidates saved "Total Records Count" attribute with last counting,
1676+
* so a next calling of method getSize() will query new total records count.
1677+
*
1678+
* @return void
1679+
*/
1680+
private function invalidateSize()
1681+
{
1682+
$this->_totalRecords = null;
1683+
}
16711684
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,7 @@ public function addAddress(\Magento\Quote\Api\Data\AddressInterface $address)
13131313
*/
13141314
public function setBillingAddress(\Magento\Quote\Api\Data\AddressInterface $address = null)
13151315
{
1316-
$old = $this->getBillingAddress();
1317-
1316+
$old = $this->getAddressesCollection()->getItemById($address->getId()) ?? $this->getBillingAddress();
13181317
if (!empty($old)) {
13191318
$old->addData($address->getData());
13201319
} else {
@@ -1334,7 +1333,7 @@ public function setShippingAddress(\Magento\Quote\Api\Data\AddressInterface $add
13341333
if ($this->getIsMultiShipping()) {
13351334
$this->addAddress($address->setAddressType(Address::TYPE_SHIPPING));
13361335
} else {
1337-
$old = $this->getShippingAddress();
1336+
$old = $this->getAddressesCollection()->getItemById($address->getId()) ?? $this->getShippingAddress();
13381337
if (!empty($old)) {
13391338
$old->addData($address->getData());
13401339
} else {

app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ protected function _assignProducts()
230230
);
231231
$this->skipStockStatusFilter($productCollection);
232232
$productCollection->addOptionsToResult()->addStoreFilter()->addUrlRewrite();
233-
$this->addTierPriceData($productCollection);
234233

235234
$this->_eventManager->dispatch(
236235
'prepare_catalog_product_collection_prices',
@@ -301,21 +300,6 @@ private function skipStockStatusFilter(ProductCollection $productCollection)
301300
$productCollection->setFlag('has_stock_status_filter', true);
302301
}
303302

304-
/**
305-
* Add tier prices to product collection.
306-
*
307-
* @param ProductCollection $productCollection
308-
* @return void
309-
*/
310-
private function addTierPriceData(ProductCollection $productCollection)
311-
{
312-
if (empty($this->_quote)) {
313-
$productCollection->addTierPriceData();
314-
} else {
315-
$productCollection->addTierPriceDataByGroupId($this->_quote->getCustomerGroupId());
316-
}
317-
}
318-
319303
/**
320304
* Find and remove quote items with non existing products
321305
*

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ define([
4848
if (typeof controlButtonArea != 'undefined') {
4949
var buttons = controlButtonArea.childElements();
5050
for (var i = 0; i < buttons.length; i++) {
51-
if (buttons[i].innerHTML.include(button.label)) {
51+
if (buttons[i].innerHTML.include(button.getLabel())) {
5252
return;
5353
}
5454
}
@@ -1431,6 +1431,10 @@ define([
14311431
node.update('<span>' + this._label + '</span>');
14321432
content[position] = node;
14331433
Element.insert(element, content);
1434+
},
1435+
1436+
getLabel: function(){
1437+
return this._label;
14341438
}
14351439
};
14361440

app/code/Magento/SalesRule/Model/Rule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ public function acquireCoupon($saveNewlyCreated = true, $saveAttemptCount = 10)
501501
$this->getUsesPerCustomer() ? $this->getUsesPerCustomer() : null
502502
)->setExpirationDate(
503503
$this->getToDate()
504+
)->setType(
505+
\Magento\SalesRule\Api\Data\CouponInterface::TYPE_GENERATED
504506
);
505507

506508
$couponCode = self::getCouponCodeGenerator()->generateCode();

app/code/Magento/Store/Model/Store.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -901,23 +901,17 @@ public function setCurrentCurrencyCode($code)
901901
*/
902902
public function getCurrentCurrencyCode()
903903
{
904+
$availableCurrencyCodes = \array_values($this->getAvailableCurrencyCodes(true));
904905
// try to get currently set code among allowed
905-
$code = $this->_httpContext->getValue(Context::CONTEXT_CURRENCY);
906-
$code = $code === null ? $this->_getSession()->getCurrencyCode() : $code;
907-
if (empty($code)) {
906+
$code = $this->_httpContext->getValue(Context::CONTEXT_CURRENCY) ?? $this->_getSession()->getCurrencyCode();
907+
if (empty($code) || !\in_array($code, $availableCurrencyCodes)) {
908908
$code = $this->getDefaultCurrencyCode();
909-
}
910-
if (in_array($code, $this->getAvailableCurrencyCodes(true))) {
911-
return $code;
909+
if (!\in_array($code, $availableCurrencyCodes) && !empty($availableCurrencyCodes)) {
910+
$code = $availableCurrencyCodes[0];
911+
}
912912
}
913913

914-
// take first one of allowed codes
915-
$codes = array_values($this->getAvailableCurrencyCodes(true));
916-
if (empty($codes)) {
917-
// return default code, if no codes specified at all
918-
return $this->getDefaultCurrencyCode();
919-
}
920-
return array_shift($codes);
914+
return $code;
921915
}
922916

923917
/**

app/code/Magento/Store/Test/Unit/Model/StoreTest.php

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\Framework\App\Config\ReinitableConfigInterface;
1212
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\Session\SessionManagerInterface;
1314
use Magento\Store\Model\ScopeInterface;
1415
use Magento\Store\Model\Store;
1516

@@ -40,6 +41,16 @@ class StoreTest extends \PHPUnit\Framework\TestCase
4041
*/
4142
protected $filesystemMock;
4243

44+
/**
45+
* @var ReinitableConfigInterface|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $configMock;
48+
49+
/**
50+
* @var SessionManagerInterface|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $sessionMock;
53+
4354
/**
4455
* @var \Magento\Framework\Url\ModifierInterface|\PHPUnit_Framework_MockObject_MockObject
4556
*/
@@ -60,12 +71,22 @@ protected function setUp()
6071
'isSecure',
6172
'getServer',
6273
]);
74+
6375
$this->filesystemMock = $this->getMockBuilder(\Magento\Framework\Filesystem::class)
6476
->disableOriginalConstructor()
6577
->getMock();
78+
$this->configMock = $this->getMockBuilder(ReinitableConfigInterface::class)
79+
->getMock();
80+
$this->sessionMock = $this->getMockBuilder(SessionManagerInterface::class)
81+
->setMethods(['getCurrencyCode'])
82+
->getMockForAbstractClass();
6683
$this->store = $this->objectManagerHelper->getObject(
6784
\Magento\Store\Model\Store::class,
68-
['filesystem' => $this->filesystemMock]
85+
[
86+
'filesystem' => $this->filesystemMock,
87+
'config' => $this->configMock,
88+
'session' => $this->sessionMock,
89+
]
6990
);
7091

7192
$this->urlModifierMock = $this->createMock(\Magento\Framework\Url\ModifierInterface::class);
@@ -671,4 +692,78 @@ private function setUrlModifier(\Magento\Store\Model\Store $model)
671692
$property->setAccessible(true);
672693
$property->setValue($model, $this->urlModifierMock);
673694
}
695+
696+
/**
697+
* @param array $availableCodes
698+
* @param string $currencyCode
699+
* @param string $defaultCode
700+
* @param string $expectedCode
701+
* @return void
702+
* @dataProvider currencyCodeDataProvider
703+
*/
704+
public function testGetCurrentCurrencyCode(
705+
array $availableCodes,
706+
string $currencyCode,
707+
string $defaultCode,
708+
string $expectedCode
709+
) {
710+
$this->store->setData('available_currency_codes', $availableCodes);
711+
$this->sessionMock->method('getCurrencyCode')
712+
->willReturn($currencyCode);
713+
$this->configMock->method('getValue')
714+
->with(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT)
715+
->willReturn($defaultCode);
716+
717+
$code = $this->store->getCurrentCurrencyCode();
718+
$this->assertEquals($expectedCode, $code);
719+
}
720+
721+
/**
722+
* @return array
723+
*/
724+
public function currencyCodeDataProvider(): array
725+
{
726+
return [
727+
[
728+
[
729+
'USD',
730+
],
731+
'USD',
732+
'USD',
733+
'USD',
734+
],
735+
[
736+
[
737+
'USD',
738+
'EUR',
739+
],
740+
'EUR',
741+
'USD',
742+
'EUR',
743+
],
744+
[
745+
[
746+
'EUR',
747+
'USD',
748+
],
749+
'GBP',
750+
'USD',
751+
'USD',
752+
],
753+
[
754+
[
755+
'USD',
756+
],
757+
'GBP',
758+
'EUR',
759+
'USD',
760+
],
761+
[
762+
[],
763+
'GBP',
764+
'EUR',
765+
'EUR',
766+
],
767+
];
768+
}
674769
}

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,15 @@ public function testJoinTable()
187187

188188
self::assertContains($expected, str_replace(PHP_EOL, '', $sql));
189189
}
190+
191+
/**
192+
* @magentoDataFixture Magento/Catalog/Model/ResourceModel/_files/few_simple_products.php
193+
* @magentoDbIsolation enabled
194+
*/
195+
public function testAddAttributeToFilterAffectsGetSize()
196+
{
197+
$this->assertEquals(10, $this->collection->getSize());
198+
$this->collection->addAttributeToFilter('sku', 'Product1');
199+
$this->assertEquals(1, $this->collection->getSize());
200+
}
190201
}
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+
declare(strict_types=1);
7+
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\Catalog\Model\ProductFactory;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
12+
/** @var Magento\Framework\ObjectManagerInterface $objcetManager */
13+
$objectManager = Bootstrap::getObjectManager();
14+
15+
/** @var ProductFactory $productFactory */
16+
$productFactory = $objectManager->create(ProductFactory::class);
17+
18+
/** @var ProductRepositoryInterface $productRepository */
19+
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
20+
21+
// Create 10 products (with change this variable, don't forget to change the same in rollback)
22+
$productsAmount = 10;
23+
24+
for ($i = 1; $i <= $productsAmount; $i++) {
25+
$productArray = [
26+
'data' => [
27+
'name' => "Product{$i}",
28+
'sku' => "Product{$i}",
29+
'price' => 100,
30+
'attribute_set_id' => 4,
31+
'website_ids' => [1]
32+
]
33+
];
34+
35+
$productRepository->save($productFactory->create($productArray));
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
12+
/** @var ProductRepositoryInterface $productRepository */
13+
$productRepository = Bootstrap::getObjectManager()
14+
->get(ProductRepositoryInterface::class);
15+
16+
/**
17+
* Delete 10 products
18+
*/
19+
$productsAmount = 10;
20+
21+
try {
22+
for ($i = 1; $i <= $productsAmount; $i++) {
23+
/** @var \Magento\Catalog\Api\Data\ProductInterface $product */
24+
$product = $productRepository->get("Product{$i}", false, null, true);
25+
$productRepository->delete($product);
26+
}
27+
} catch (NoSuchEntityException $e) {
28+
}

0 commit comments

Comments
 (0)