Exemplo n.º 1
0
 /**
  * @param Product $entity
  * @param array $arguments
  * @return object
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entity, $arguments = [])
 {
     $value = [];
     $value['images'] = [];
     $mediaEntries = $this->resourceModel->loadProductGalleryByAttributeId($entity, $this->getAttribute()->getAttributeId());
     $this->addMediaDataToProduct($entity, $mediaEntries);
     return $entity;
 }
Exemplo n.º 2
0
 /**
  * @param string $entityType
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Model\Product
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $product)
 {
     $value = [];
     $value['images'] = [];
     $localAttributes = ['label', 'position', 'disabled'];
     $mediaEntries = $this->resourceModel->loadProductGalleryByAttributeId($product, $this->getAttribute()->getAttributeId());
     foreach ($mediaEntries as $mediaEntry) {
         foreach ($localAttributes as $localAttribute) {
             if ($mediaEntry[$localAttribute] === null) {
                 $mediaEntry[$localAttribute] = $this->findDefaultValue($localAttribute, $mediaEntry);
             }
         }
         $value['images'][] = $mediaEntry;
     }
     $product->setData($this->getAttribute()->getAttributeCode(), $value);
     return $product;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function loadProductGalleryByAttributeId($product, $attributeId)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'loadProductGalleryByAttributeId');
     if (!$pluginInfo) {
         return parent::loadProductGalleryByAttributeId($product, $attributeId);
     } else {
         return $this->___callPlugins('loadProductGalleryByAttributeId', func_get_args(), $pluginInfo);
     }
 }
Exemplo n.º 4
0
 /**
  * Get all product images
  *
  * @param \Magento\Framework\DataObject $product
  * @param int $storeId
  * @return array
  */
 protected function _getAllProductImages($product, $storeId)
 {
     $product->setStoreId($storeId);
     $gallery = $this->mediaGalleryResourceModel->loadProductGalleryByAttributeId($product, $this->mediaGalleryReadHandler->getAttribute()->getId());
     $imagesCollection = [];
     if ($gallery) {
         $productMediaPath = $this->_getMediaConfig()->getBaseMediaUrlAddition();
         foreach ($gallery as $image) {
             $imagesCollection[] = new \Magento\Framework\DataObject(['url' => $productMediaPath . $image['file'], 'caption' => $image['label'] ? $image['label'] : $image['label_default']]);
         }
     }
     return $imagesCollection;
 }