diff --git a/packages/Webkul/Product/src/Helpers/ConfigurableOption.php b/packages/Webkul/Product/src/Helpers/ConfigurableOption.php index 5b5eae71f..e6e53d8fc 100755 --- a/packages/Webkul/Product/src/Helpers/ConfigurableOption.php +++ b/packages/Webkul/Product/src/Helpers/ConfigurableOption.php @@ -5,6 +5,7 @@ namespace Webkul\Product\Helpers; use Webkul\Product\Models\Product; use Webkul\Product\Models\ProductAttributeValue; use Webkul\Product\Facades\ProductImage; +use Webkul\Product\Facades\ProductVideo; class ConfigurableOption extends AbstractProduct { @@ -50,6 +51,7 @@ class ConfigurableOption extends AbstractProduct ], 'variant_prices' => $this->getVariantPrices($product), 'variant_images' => $this->getVariantImages($product), + 'variant_videos' => $this->getVariantVideos($product), 'chooseText' => trans('shop::app.products.choose-option'), ]; @@ -211,4 +213,27 @@ class ConfigurableOption extends AbstractProduct return $images; } + + /** + * Get product videos for configurable variations + * + * @param \Webkul\Product\Contracts\Product|\Webkul\Product\Contracts\ProductFlat $product + * @return array + */ + protected function getVariantVideos($product) + { + $videos = []; + + foreach ($this->getAllowedProducts($product) as $variant) { + if ($variant instanceof \Webkul\Product\Models\ProductFlat) { + $variantId = $variant->product_id; + } else { + $variantId = $variant->id; + } + + $videos[$variantId] = ProductVideo::getVideos($variant); + } + + return $videos; + } } \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php index 3d2d8eb1f..55344f2b8 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view/configurable-options.blade.php @@ -304,7 +304,11 @@ }); if (this.simpleProduct) { - this.config.variant_images[this.simpleProduct].forEach(function(image) { + this.config.variant_images[this.simpleProduct].forEach(function(video) { + galleryImages.unshift(video) + }); + + this.config.variant_videos[this.simpleProduct].forEach(function(image) { galleryImages.unshift(image) }); } diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/view/configurable-options.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/view/configurable-options.blade.php index c8b13e5b0..48dc2e03c 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/view/configurable-options.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/view/configurable-options.blade.php @@ -318,6 +318,10 @@ }); if (this.simpleProduct) { + this.config.variant_images[this.simpleProduct].forEach(function(video) { + galleryImages.unshift(video) + }); + this.config.variant_images[this.simpleProduct].forEach(function(image) { galleryImages.unshift(image) });