Skip to content

Commit 1a5ed8d

Browse files
committed
Merge branch 'EPAM-PR-7' of github.com:magento-epam/magento2ce into EPAM-PR-7-8-10
2 parents e7e2267 + 1800c95 commit 1a5ed8d

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Framework\DB\Adapter\ConnectionException;
2121
use Magento\Framework\DB\Adapter\DeadlockException;
2222
use Magento\Framework\DB\Adapter\LockWaitException;
23+
use Magento\Framework\EntityManager\Operation\Read\ReadExtensions;
2324
use Magento\Framework\Exception\CouldNotSaveException;
2425
use Magento\Framework\Exception\InputException;
2526
use Magento\Framework\Exception\LocalizedException;
@@ -29,6 +30,7 @@
2930
use Magento\Framework\Exception\ValidatorException;
3031

3132
/**
33+
* Product Repository.
3234
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3335
* @SuppressWarnings(PHPMD.TooManyFields)
3436
*/
@@ -154,6 +156,11 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
154156
*/
155157
private $serializer;
156158

159+
/**
160+
* @var ReadExtensions
161+
*/
162+
private $readExtensions;
163+
157164
/**
158165
* ProductRepository constructor.
159166
* @param ProductFactory $productFactory
@@ -179,6 +186,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
179186
* @param CollectionProcessorInterface $collectionProcessor [optional]
180187
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
181188
* @param int $cacheLimit [optional]
189+
* @param ReadExtensions|null $readExtensions
182190
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
183191
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
184192
*/
@@ -205,7 +213,8 @@ public function __construct(
205213
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $extensionAttributesJoinProcessor,
206214
CollectionProcessorInterface $collectionProcessor = null,
207215
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
208-
$cacheLimit = 1000
216+
$cacheLimit = 1000,
217+
ReadExtensions $readExtensions = null
209218
) {
210219
$this->productFactory = $productFactory;
211220
$this->collectionFactory = $collectionFactory;
@@ -228,10 +237,12 @@ public function __construct(
228237
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
229238
->get(\Magento\Framework\Serialize\Serializer\Json::class);
230239
$this->cacheLimit = (int)$cacheLimit;
240+
$this->readExtensions = $readExtensions ?: \Magento\Framework\App\ObjectManager::getInstance()
241+
->get(ReadExtensions::class);
231242
}
232243

233244
/**
234-
* {@inheritdoc}
245+
* @inheritdoc
235246
*/
236247
public function get($sku, $editMode = false, $storeId = null, $forceReload = false)
237248
{
@@ -261,7 +272,7 @@ public function get($sku, $editMode = false, $storeId = null, $forceReload = fal
261272
}
262273

263274
/**
264-
* {@inheritdoc}
275+
* @inheritdoc
265276
*/
266277
public function getById($productId, $editMode = false, $storeId = null, $forceReload = false)
267278
{
@@ -351,6 +362,8 @@ protected function initializeProductData(array $productData, $createNew)
351362
}
352363

353364
/**
365+
* Assign product to websites.
366+
*
354367
* @param \Magento\Catalog\Model\Product $product
355368
* @return void
356369
*/
@@ -366,6 +379,8 @@ private function assignProductToWebsites(\Magento\Catalog\Model\Product $product
366379
}
367380

368381
/**
382+
* Process new gallery media entry.
383+
*
369384
* @param ProductInterface $product
370385
* @param array $newEntry
371386
* @return $this
@@ -618,7 +633,7 @@ public function save(ProductInterface $product, $saveOptions = false)
618633
}
619634

620635
/**
621-
* {@inheritdoc}
636+
* @inheritdoc
622637
*/
623638
public function delete(ProductInterface $product)
624639
{
@@ -642,7 +657,7 @@ public function delete(ProductInterface $product)
642657
}
643658

644659
/**
645-
* {@inheritdoc}
660+
* @inheritdoc
646661
*/
647662
public function deleteById($sku)
648663
{
@@ -651,7 +666,7 @@ public function deleteById($sku)
651666
}
652667

653668
/**
654-
* {@inheritdoc}
669+
* @inheritdoc
655670
*/
656671
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
657672
{
@@ -668,6 +683,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
668683
$collection->load();
669684

670685
$collection->addCategoryIds();
686+
$this->addExtensionAttributes($collection);
671687
$searchResult = $this->searchResultsFactory->create();
672688
$searchResult->setSearchCriteria($searchCriteria);
673689
$searchResult->setItems($collection->getItems());
@@ -678,7 +694,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
678694
$this->getCacheKey(
679695
[
680696
false,
681-
$product->hasData(\Magento\Catalog\Model\Product::STORE_ID) ? $product->getStoreId() : null
697+
$product->getStoreId()
682698
]
683699
),
684700
$product
@@ -688,6 +704,20 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
688704
return $searchResult;
689705
}
690706

707+
/**
708+
* Add extension attributes to loaded items.
709+
*
710+
* @param Collection $collection
711+
* @return Collection
712+
*/
713+
private function addExtensionAttributes(Collection $collection) : Collection
714+
{
715+
foreach ($collection->getItems() as $item) {
716+
$this->readExtensions->execute($item);
717+
}
718+
return $collection;
719+
}
720+
691721
/**
692722
* Helper function that adds a FilterGroup to the collection.
693723
*
@@ -759,6 +789,8 @@ private function determineImageRoles(ProductInterface $product, array $images) :
759789
}
760790

761791
/**
792+
* Retrieve media gallery processor.
793+
*
762794
* @return Product\Gallery\Processor
763795
*/
764796
private function getMediaGalleryProcessor()

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
namespace Magento\Catalog\Api;
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\CatalogInventory\Api\Data\StockItemInterface;
1112
use Magento\Downloadable\Model\Link;
1213
use Magento\Store\Model\Store;
13-
use Magento\CatalogInventory\Api\Data\StockItemInterface;
1414
use Magento\Store\Model\Website;
1515
use Magento\Store\Model\WebsiteRepository;
1616
use Magento\TestFramework\Helper\Bootstrap;
@@ -20,8 +20,8 @@
2020
use Magento\Framework\Api\SearchCriteriaBuilder;
2121
use Magento\Framework\Api\SortOrder;
2222
use Magento\Framework\Api\SortOrderBuilder;
23-
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
2423
use Magento\Framework\Exception\NoSuchEntityException;
24+
use Magento\Framework\Webapi\Exception as HTTPExceptionCodes;
2525

2626
/**
2727
* @magentoAppIsolation enabled
@@ -871,6 +871,7 @@ public function testGetList()
871871
$this->assertTrue(count($response['items']) > 0);
872872

873873
$this->assertNotNull($response['items'][0]['sku']);
874+
$this->assertNotNull($response['items'][0][ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['website_ids']);
874875
$this->assertEquals('simple', $response['items'][0]['sku']);
875876

876877
$index = null;
@@ -968,6 +969,7 @@ public function testGetListWithFilteringByWebsite()
968969
$this->assertTrue(count($response['items']) == 1);
969970
$this->assertTrue(isset($response['items'][0]['sku']));
970971
$this->assertEquals('simple-2', $response['items'][0]['sku']);
972+
$this->assertNotNull($response['items'][0][ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['website_ids']);
971973
}
972974

973975
/**
@@ -1114,6 +1116,9 @@ public function testGetListWithMultipleFilterGroupsAndSortingAndPagination()
11141116
$this->assertEquals(3, $searchResult['total_count']);
11151117
$this->assertEquals(1, count($searchResult['items']));
11161118
$this->assertEquals('search_product_4', $searchResult['items'][0][ProductInterface::SKU]);
1119+
$this->assertNotNull(
1120+
$searchResult['items'][0][ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]['website_ids']
1121+
);
11171122
}
11181123

11191124
/**

dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
8+
use Magento\Catalog\Api\Data\ProductExtensionInterfaceFactory;
89

910
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize();
1011

@@ -19,10 +20,15 @@
1920
$tierPriceFactory = $objectManager->get(\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory::class);
2021
/** @var $tpExtensionAttributes */
2122
$tpExtensionAttributesFactory = $objectManager->get(ProductTierPriceExtensionFactory::class);
23+
/** @var $productExtensionAttributes */
24+
$productExtensionAttributesFactory = $objectManager->get(ProductExtensionInterfaceFactory::class);
2225

2326
$adminWebsite = $objectManager->get(\Magento\Store\Api\WebsiteRepositoryInterface::class)->get('admin');
2427
$tierPriceExtensionAttributes1 = $tpExtensionAttributesFactory->create()
2528
->setWebsiteId($adminWebsite->getId());
29+
$productExtensionAttributesWebsiteIds = $productExtensionAttributesFactory->create(
30+
['website_ids' => $adminWebsite->getId()]
31+
);
2632

2733
$tierPrices[] = $tierPriceFactory->create(
2834
[
@@ -82,6 +88,7 @@
8288
->setTaxClassId(0)
8389
->setTierPrices($tierPrices)
8490
->setDescription('Description with <b>html tag</b>')
91+
->setExtensionAttributes($productExtensionAttributesWebsiteIds)
8592
->setMetaTitle('meta title')
8693
->setMetaKeyword('meta keyword')
8794
->setMetaDescription('meta description')

setup/performance-toolkit/benchmark.jmx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ adminCategoryIdsList.add(vars.get("category_id"));</stringProp>
13651365
<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor: Extract product ids" enabled="true">
13661366
<stringProp name="RegexExtractor.useHeaders">false</stringProp>
13671367
<stringProp name="RegexExtractor.refname">configurable_product_ids</stringProp>
1368-
<stringProp name="RegexExtractor.regex">\"id\":(\d+),</stringProp>
1368+
<stringProp name="RegexExtractor.regex">\"id\":(\d+),\"sku\"</stringProp>
13691369
<stringProp name="RegexExtractor.template">$1$</stringProp>
13701370
<stringProp name="RegexExtractor.default"/>
13711371
<stringProp name="RegexExtractor.match_number">-1</stringProp>
@@ -1575,7 +1575,7 @@ productList.add(productMap);</stringProp>
15751575
<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor: Extract product ids" enabled="true">
15761576
<stringProp name="RegexExtractor.useHeaders">false</stringProp>
15771577
<stringProp name="RegexExtractor.refname">configurable_product_for_edit_ids</stringProp>
1578-
<stringProp name="RegexExtractor.regex">\"id\":(\d+),</stringProp>
1578+
<stringProp name="RegexExtractor.regex">\"id\":(\d+),\"sku\"</stringProp>
15791579
<stringProp name="RegexExtractor.template">$1$</stringProp>
15801580
<stringProp name="RegexExtractor.default"/>
15811581
<stringProp name="RegexExtractor.match_number">-1</stringProp>
@@ -1798,7 +1798,7 @@ editProductList.add(editProductMap);</stringProp>
17981798
<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor: Extract product ids" enabled="true">
17991799
<stringProp name="RegexExtractor.useHeaders">false</stringProp>
18001800
<stringProp name="RegexExtractor.refname">simple_product_for_edit_ids</stringProp>
1801-
<stringProp name="RegexExtractor.regex">\"id\":(\d+),</stringProp>
1801+
<stringProp name="RegexExtractor.regex">\"id\":(\d+),\"sku\"</stringProp>
18021802
<stringProp name="RegexExtractor.template">$1$</stringProp>
18031803
<stringProp name="RegexExtractor.default"/>
18041804
<stringProp name="RegexExtractor.match_number">-1</stringProp>
@@ -2014,7 +2014,7 @@ editProductList.add(editProductMap);</stringProp>
20142014
<RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="Regular Expression Extractor: Extract product ids" enabled="true">
20152015
<stringProp name="RegexExtractor.useHeaders">false</stringProp>
20162016
<stringProp name="RegexExtractor.refname">simple_product_ids</stringProp>
2017-
<stringProp name="RegexExtractor.regex">\"id\":(\d+),</stringProp>
2017+
<stringProp name="RegexExtractor.regex">\"id\":(\d+),\"sku\"</stringProp>
20182018
<stringProp name="RegexExtractor.template">$1$</stringProp>
20192019
<stringProp name="RegexExtractor.default"/>
20202020
<stringProp name="RegexExtractor.match_number">-1</stringProp>

0 commit comments

Comments
 (0)