-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-70606: [Backport] - [GITHUB] Simple product videos display th…
…e thumbnail image rather than the embedded video player. #6360 - for 2.1
- Loading branch information
1 parent
ebb08a0
commit cd6c087
Showing
14 changed files
with
902 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/code/Magento/ConfigurableProduct/Block/Plugin/Product/Media/Gallery.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\ConfigurableProduct\Block\Plugin\Product\Media; | ||
|
||
use Magento\ConfigurableProduct\Model\Product\Type\Configurable; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
|
||
/** | ||
* Provides a serialized media gallery data for configurable product options. | ||
*/ | ||
class Gallery | ||
{ | ||
/** | ||
* @var Json | ||
*/ | ||
private $json; | ||
|
||
/** | ||
* @param Json $json | ||
*/ | ||
public function __construct( | ||
Json $json | ||
) { | ||
$this->json = $json; | ||
} | ||
|
||
/** | ||
* @param \Magento\Catalog\Block\Product\View\Gallery $subject | ||
* @param string $result | ||
* @return string | ||
*/ | ||
public function afterGetOptionsMediaGalleryDataJson( | ||
\Magento\Catalog\Block\Product\View\Gallery $subject, | ||
$result | ||
) { | ||
$result = $this->json->unserialize($result); | ||
$parentProduct = $subject->getProduct(); | ||
if ($parentProduct->getTypeId() == Configurable::TYPE_CODE) { | ||
/** @var Configurable $productType */ | ||
$productType = $parentProduct->getTypeInstance(); | ||
$products = $productType->getUsedProducts($parentProduct); | ||
/** @var Product $product */ | ||
foreach ($products as $product) { | ||
$key = $product->getId(); | ||
$result[$key] = $this->getProductGallery($product); | ||
} | ||
} | ||
return $this->json->serialize($result); | ||
} | ||
|
||
/** | ||
* @param Product $product | ||
* @return array | ||
*/ | ||
private function getProductGallery($product) | ||
{ | ||
$result = []; | ||
$images = $product->getMediaGalleryImages(); | ||
foreach ($images as $image) { | ||
$result[] = [ | ||
'mediaType' => $image->getMediaType(), | ||
'videoUrl' => $image->getVideoUrl(), | ||
'isBase' => $product->getImage() == $image->getFile(), | ||
]; | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.