Esempio n. 1
0
 /**
  * Method getting full media gallery for current Product
  * Array structure: [
  *  ['image'] => 'http://url/pub/media/catalog/product/2/0/blabla.jpg',
  *  ['mediaGallery'] => [
  *      galleryImageId1 => simpleProductImage1.jpg,
  *      galleryImageId2 => simpleProductImage2.jpg,
  *      ...,
  *      ]
  * ]
  * @param Product $product
  * @return array
  */
 public function getProductMediaGallery(Product $product)
 {
     if (!in_array($product->getData('image'), [null, 'no_selection'], true)) {
         $baseImage = $product->getData('image');
     } else {
         $productMediaAttributes = array_filter($product->getMediaAttributeValues(), function ($value) {
             return $value !== 'no_selection' && $value !== null;
         });
         foreach ($productMediaAttributes as $attributeCode => $value) {
             if ($attributeCode !== 'swatch_image') {
                 $baseImage = (string) $value;
                 break;
             }
         }
     }
     if (empty($baseImage)) {
         return [];
     }
     $resultGallery = $this->getAllSizeImages($product, $baseImage);
     $resultGallery['gallery'] = $this->getGalleryImages($product);
     return $resultGallery;
 }
Esempio n. 2
0
 /**
  * Get all media for product
  *
  * @param Product $product
  * @return array|bool
  */
 protected function getProductMedia(Product $product)
 {
     return array_filter($product->getMediaAttributeValues(), function ($value) {
         return $value != 'no_selection' && $value !== null;
     });
 }