Skip to content

Commit 38bc4bf

Browse files
author
Alexander Akimov
authored
Merge pull request #3400 from magento-tsg/2.2-develop-pr51
[TSG] Backporting for 2.2 (pr51) (2.2.8)
2 parents d65f99a + df6b49f commit 38bc4bf

File tree

18 files changed

+207
-13
lines changed

18 files changed

+207
-13
lines changed

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

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\DB\Adapter\ConnectionException;
1919
use Magento\Framework\DB\Adapter\DeadlockException;
2020
use Magento\Framework\DB\Adapter\LockWaitException;
21+
use Magento\Framework\EntityManager\Operation\Read\ReadExtensions;
2122
use Magento\Framework\Exception\CouldNotSaveException;
2223
use Magento\Framework\Exception\InputException;
2324
use Magento\Framework\Exception\LocalizedException;
@@ -26,6 +27,7 @@
2627
use Magento\Framework\Exception\ValidatorException;
2728

2829
/**
30+
* Product Repository.
2931
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3032
* @SuppressWarnings(PHPMD.TooManyFields)
3133
*/
@@ -155,6 +157,11 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
155157
*/
156158
private $serializer;
157159

160+
/**
161+
* @var ReadExtensions
162+
*/
163+
private $readExtensions;
164+
158165
/**
159166
* ProductRepository constructor.
160167
* @param ProductFactory $productFactory
@@ -180,6 +187,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
180187
* @param CollectionProcessorInterface $collectionProcessor [optional]
181188
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
182189
* @param int $cacheLimit [optional]
190+
* @param ReadExtensions|null $readExtensions
183191
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
184192
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
185193
*/
@@ -206,7 +214,8 @@ public function __construct(
206214
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor,
207215
CollectionProcessorInterface $collectionProcessor = null,
208216
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
209-
$cacheLimit = 1000
217+
$cacheLimit = 1000,
218+
ReadExtensions $readExtensions = null
210219
) {
211220
$this->productFactory = $productFactory;
212221
$this->collectionFactory = $collectionFactory;
@@ -229,10 +238,12 @@ public function __construct(
229238
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
230239
->get(\Magento\Framework\Serialize\Serializer\Json::class);
231240
$this->cacheLimit = (int)$cacheLimit;
241+
$this->readExtensions = $readExtensions ?: \Magento\Framework\App\ObjectManager::getInstance()
242+
->get(ReadExtensions::class);
232243
}
233244

234245
/**
235-
* {@inheritdoc}
246+
* @inheritdoc
236247
*/
237248
public function get($sku, $editMode = false, $storeId = null, $forceReload = false)
238249
{
@@ -249,11 +260,12 @@ public function get($sku, $editMode = false, $storeId = null, $forceReload = fal
249260
$this->cacheProduct($cacheKey, $product);
250261
$cachedProduct = $product;
251262
}
263+
252264
return $cachedProduct;
253265
}
254266

255267
/**
256-
* {@inheritdoc}
268+
* @inheritdoc
257269
*/
258270
public function getById($productId, $editMode = false, $storeId = null, $forceReload = false)
259271
{
@@ -272,6 +284,7 @@ public function getById($productId, $editMode = false, $storeId = null, $forceRe
272284
}
273285
$this->cacheProduct($cacheKey, $product);
274286
}
287+
275288
return $this->instancesById[$productId][$cacheKey];
276289
}
277290

@@ -292,6 +305,7 @@ protected function getCacheKey($data)
292305
}
293306
}
294307
$serializeData = $this->serializer->serialize($serializeData);
308+
295309
return sha1($serializeData);
296310
}
297311

@@ -349,6 +363,8 @@ protected function initializeProductData(array $productData, $createNew)
349363
}
350364

351365
/**
366+
* Assign product to websites.
367+
*
352368
* @param \Magento\Catalog\Model\Product $product
353369
* @return void
354370
*/
@@ -418,11 +434,12 @@ private function processLinks(ProductInterface $product, $newLinks)
418434
}
419435

420436
$product->setProductLinks($newLinks);
437+
421438
return $this;
422439
}
423440

424441
/**
425-
* {@inheritdoc}
442+
* @inheritdoc
426443
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
427444
* @SuppressWarnings(PHPMD.NPathComplexity)
428445
*/
@@ -494,7 +511,7 @@ public function save(ProductInterface $product, $saveOptions = false)
494511
}
495512

496513
/**
497-
* {@inheritdoc}
514+
* @inheritdoc
498515
*/
499516
public function delete(ProductInterface $product)
500517
{
@@ -513,20 +530,22 @@ public function delete(ProductInterface $product)
513530
}
514531
$this->removeProductFromLocalCache($sku);
515532
unset($this->instancesById[$productId]);
533+
516534
return true;
517535
}
518536

519537
/**
520-
* {@inheritdoc}
538+
* @inheritdoc
521539
*/
522540
public function deleteById($sku)
523541
{
524542
$product = $this->get($sku);
543+
525544
return $this->delete($product);
526545
}
527546

528547
/**
529-
* {@inheritdoc}
548+
* @inheritdoc
530549
*/
531550
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
532551
{
@@ -543,6 +562,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
543562
$collection->load();
544563

545564
$collection->addCategoryIds();
565+
$this->addExtensionAttributes($collection);
546566
$searchResult = $this->searchResultsFactory->create();
547567
$searchResult->setSearchCriteria($searchCriteria);
548568
$searchResult->setItems($collection->getItems());
@@ -553,7 +573,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
553573
$this->getCacheKey(
554574
[
555575
false,
556-
$product->hasData(\Magento\Catalog\Model\Product::STORE_ID) ? $product->getStoreId() : null
576+
$product->getStoreId()
557577
]
558578
),
559579
$product
@@ -563,6 +583,21 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
563583
return $searchResult;
564584
}
565585

586+
/**
587+
* Add extension attributes to loaded items.
588+
*
589+
* @param Collection $collection
590+
* @return Collection
591+
*/
592+
private function addExtensionAttributes(Collection $collection): Collection
593+
{
594+
foreach ($collection->getItems() as $item) {
595+
$this->readExtensions->execute($item);
596+
}
597+
598+
return $collection;
599+
}
600+
566601
/**
567602
* Helper function that adds a FilterGroup to the collection.
568603
*
@@ -608,6 +643,8 @@ public function cleanCache()
608643
}
609644

610645
/**
646+
* Retrieve media gallery processor.
647+
*
611648
* @return ProductRepository\MediaGalleryProcessor
612649
*/
613650
private function getMediaGalleryProcessor()
@@ -616,6 +653,7 @@ private function getMediaGalleryProcessor()
616653
$this->mediaGalleryProcessor = \Magento\Framework\App\ObjectManager::getInstance()
617654
->get(ProductRepository\MediaGalleryProcessor::class);
618655
}
656+
619657
return $this->mediaGalleryProcessor;
620658
}
621659

@@ -632,6 +670,7 @@ private function getCollectionProcessor()
632670
'Magento\Catalog\Model\Api\SearchCriteria\ProductCollectionProcessor'
633671
);
634672
}
673+
635674
return $this->collectionProcessor;
636675
}
637676

app/code/Magento/Catalog/etc/adminhtml/system.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@
8383
<backend_model>Magento\Catalog\Model\Indexer\Product\Flat\System\Config\Mode</backend_model>
8484
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
8585
</field>
86-
<field id="default_sort_by" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
86+
<field id="default_sort_by" translate="label comment" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
8787
<label>Product Listing Sort by</label>
88+
<comment>Applies to category pages</comment>
8889
<source_model>Magento\Catalog\Model\Config\Source\ListSort</source_model>
8990
</field>
9091
<field id="list_allow_all" translate="label comment" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ public function testGetList()
920920
$this->assertTrue(count($response['items']) > 0);
921921

922922
$this->assertNotNull($response['items'][0]['sku']);
923+
$this->assertNotNull($response['items'][0][ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['website_ids']);
923924
$this->assertEquals('simple', $response['items'][0]['sku']);
924925

925926
$index = null;
@@ -1018,6 +1019,7 @@ public function testGetListWithFilteringByWebsite()
10181019
$this->assertTrue(count($response['items']) == 1);
10191020
$this->assertTrue(isset($response['items'][0]['sku']));
10201021
$this->assertEquals('simple-2', $response['items'][0]['sku']);
1022+
$this->assertNotNull($response['items'][0][ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['website_ids']);
10211023
}
10221024

10231025
/**
@@ -1164,6 +1166,9 @@ public function testGetListWithMultipleFilterGroupsAndSortingAndPagination()
11641166
$this->assertEquals(3, $searchResult['total_count']);
11651167
$this->assertEquals(1, count($searchResult['items']));
11661168
$this->assertEquals('search_product_4', $searchResult['items'][0][ProductInterface::SKU]);
1169+
$this->assertNotNull(
1170+
$searchResult['items'][0][ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['website_ids']
1171+
);
11671172
}
11681173

11691174
/**

dev/tests/functional/tests/app/Magento/Bundle/Test/Constraint/AssertBundleProductOnConfigureCartPage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Bundle\Test\Fixture\BundleProduct;
1010
use Magento\Catalog\Test\Page\Product\CatalogProductView;
11+
use Magento\Checkout\Test\Constraint\Utils\CartPageLoadTrait;
1112
use Magento\Checkout\Test\Fixture\Cart;
1213
use Magento\Checkout\Test\Page\CheckoutCart;
1314
use Magento\Mtf\Constraint\AbstractAssertForm;
@@ -17,6 +18,8 @@
1718
*/
1819
class AssertBundleProductOnConfigureCartPage extends AbstractAssertForm
1920
{
21+
use CartPageLoadTrait;
22+
2023
/**
2124
* Check bundle product options correctly displayed on cart configuration page.
2225
*
@@ -28,6 +31,8 @@ class AssertBundleProductOnConfigureCartPage extends AbstractAssertForm
2831
public function processAssert(CheckoutCart $checkoutCart, Cart $cart, CatalogProductView $catalogProductView)
2932
{
3033
$checkoutCart->open();
34+
$this->waitForCartPageLoaded($checkoutCart);
35+
3136
$sourceProducts = $cart->getDataFieldConfig('items')['source'];
3237
$products = $sourceProducts->getProducts();
3338
foreach ($cart->getItems() as $key => $item) {

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ class Cart extends Block
113113
*/
114114
private $popupWindowContent = '#main';
115115

116+
/**
117+
* Locator for page with ajax loading state.
118+
*
119+
* @var string
120+
*/
121+
private $ajaxLoading = 'body.ajax-loading';
122+
116123
/**
117124
* Wait for PayPal page is loaded.
118125
*
@@ -295,4 +302,14 @@ public function waitForCheckoutButton()
295302
{
296303
$this->waitForElementVisible($this->inContextPaypalCheckoutButton);
297304
}
305+
306+
/**
307+
* Wait loading.
308+
*
309+
* @return void
310+
*/
311+
public function waitForLoader()
312+
{
313+
$this->waitForElementNotVisible($this->ajaxLoading);
314+
}
298315
}

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Shipping.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class Shipping extends Form
7272
*/
7373
protected $commonShippingPriceSelector = '.totals.shipping .price';
7474

75+
/**
76+
* Estimate shipping and tax form locator.
77+
*
78+
* @var string
79+
*/
80+
private $estimateShippingForm = '#shipping-zip-form';
81+
7582
/**
7683
* Open estimate shipping and tax form.
7784
*
@@ -250,4 +257,51 @@ public function waitForCommonShippingPriceBlock()
250257
{
251258
$this->waitForElementVisible($this->commonShippingPriceSelector, Locator::SELECTOR_CSS);
252259
}
260+
261+
/**
262+
* Wait until estimation form to appear.
263+
*
264+
* @return void
265+
*/
266+
public function waitForEstimateShippingAndTaxForm()
267+
{
268+
$browser = $this->browser;
269+
$selector = $this->estimateShippingForm;
270+
271+
$browser->waitUntil(
272+
function () use ($browser, $selector) {
273+
$element = $browser->find($selector);
274+
return $element->isPresent() ? true : null;
275+
}
276+
);
277+
}
278+
279+
/**
280+
* Wait for shipping method form.
281+
*
282+
* @return void
283+
*/
284+
public function waitForShippingMethodForm()
285+
{
286+
$browser = $this->browser;
287+
$selector = $this->shippingMethodForm;
288+
289+
$browser->waitUntil(
290+
function () use ($browser, $selector) {
291+
$element = $browser->find($selector);
292+
return $element->isPresent() ? true : null;
293+
}
294+
);
295+
}
296+
297+
/**
298+
* Wait for summary block to be loaded.
299+
*
300+
* @return void
301+
*/
302+
public function waitForSummaryBlock()
303+
{
304+
$this->waitForEstimateShippingAndTaxForm();
305+
$this->waitForShippingMethodForm();
306+
}
253307
}

dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,15 @@ public function waitForShippingPriceBlock()
264264
{
265265
$this->waitForElementVisible($this->shippingPriceBlockSelector, Locator::SELECTOR_CSS);
266266
}
267+
268+
/**
269+
* Wait for "Grand Total" row to appear.
270+
*
271+
* @return void
272+
*/
273+
public function waitForGrandTotal()
274+
{
275+
$this->waitForUpdatedTotals();
276+
$this->waitForElementVisible($this->grandTotal);
277+
}
267278
}

0 commit comments

Comments
 (0)