Skip to content

Commit 4a4e5e3

Browse files
committed
MAGETWO-54682: Fast load of product options
- MAGETWO-55756: Porting to 2.1
1 parent cd102ba commit 4a4e5e3

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

app/code/Magento/ProductVideo/Model/Plugin/Catalog/Product/Gallery/ReadHandler.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ public function afterExecute(
2727
$mediaGalleryReadHandler->getAttribute()
2828
);
2929

30-
if (!empty($mediaCollection)) {
31-
$ids = $this->collectVideoEntriesIds($mediaCollection);
32-
$videoDataCollection = $this->loadVideoDataById($ids, $product->getStoreId());
33-
$mediaEntriesDataCollection = $this->addVideoDataToMediaEntries($mediaCollection, $videoDataCollection);
34-
35-
$product->setData(
36-
$mediaGalleryReadHandler->getAttribute()->getAttributeCode(),
37-
$mediaEntriesDataCollection
38-
);
30+
if (empty($mediaCollection)) {
31+
return $product;
32+
}
33+
34+
$ids = $this->collectVideoEntriesIds($mediaCollection);
35+
36+
if (empty($ids)) {
37+
return $product;
3938
}
4039

40+
$videoDataCollection = $this->loadVideoDataById($ids, $product->getStoreId());
41+
$mediaEntriesDataCollection = $this->addVideoDataToMediaEntries($mediaCollection, $videoDataCollection);
42+
43+
$product->setData(
44+
$mediaGalleryReadHandler->getAttribute()->getAttributeCode(),
45+
$mediaEntriesDataCollection
46+
);
47+
4148
return $product;
4249
}
4350

@@ -49,7 +56,9 @@ protected function collectVideoEntriesIds(array $mediaCollection)
4956
{
5057
$ids = [];
5158
foreach ($mediaCollection as $item) {
52-
if ($item['media_type'] == ExternalVideoEntryConverter::MEDIA_TYPE_CODE) {
59+
if ($item['media_type'] == ExternalVideoEntryConverter::MEDIA_TYPE_CODE
60+
&& !array_key_exists('video_url', $item)
61+
) {
5362
$ids[] = $item['value_id'];
5463
}
5564
}

app/code/Magento/ProductVideo/Model/Plugin/ExternalVideoResourceBackend.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\ProductVideo\Model\Plugin;
77

88
use Magento\Catalog\Model\ResourceModel\Product\Gallery;
9-
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Media;
109
use Magento\Framework\DB\Select;
1110
use Magento\ProductVideo\Setup\InstallSchema;
1211

@@ -47,11 +46,11 @@ public function afterDuplicate(Gallery $originalResourceModel, array $valueIdMap
4746
}
4847

4948
/**
50-
* @param Media $originalResourceModel
49+
* @param Gallery $originalResourceModel
5150
* @param Select $select
5251
* @return Select
5352
*/
54-
public function afterCreateBatchBaseSelect(Media $originalResourceModel, Select $select)
53+
public function afterCreateBatchBaseSelect(Gallery $originalResourceModel, Select $select)
5554
{
5655
$select = $select->joinLeft(
5756
['value_video' => $originalResourceModel->getTable(InstallSchema::GALLERY_VALUE_VIDEO_TABLE)],

app/code/Magento/ProductVideo/Test/Unit/Model/Plugin/Catalog/Product/Gallery/ReadHandlerTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,12 @@ public function testAfterExecuteNoVideo()
200200
'values' => []
201201
];
202202

203-
$resourceEntryResult = [];
204-
205203
$this->product->expects($this->once())
206204
->method('getData')
207205
->with('media_gallery')
208206
->willReturn($mediaData);
209207

210-
$this->resourceModel->expects($this->once())
211-
->method('loadDataFromTableByValueId')
212-
->willReturn($resourceEntryResult);
208+
$this->resourceModel->expects($this->never())->method('loadDataFromTableByValueId');
213209

214210
$this->mediaGalleryReadHandler->expects($this->any())
215211
->method('getAttribute')

0 commit comments

Comments
 (0)