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
 public function testAfterExecuteNoVideo()
 {
     $mediaData = ['images' => [['value_id' => '7', 'file' => '/h/d/hd_image.jpg', 'media_type' => 'image', 'entity_id' => '1', 'label' => '', 'position' => '4', 'disabled' => '0', 'label_default' => null, 'position_default' => '4', 'disabled_default' => '0']], 'values' => []];
     $this->product->expects($this->once())->method('getData')->with('media_gallery')->willReturn($mediaData);
     $this->resourceModel->expects($this->never())->method('loadDataFromTableByValueId');
     $this->mediaGalleryReadHandler->expects($this->any())->method('getAttribute')->willReturn($this->attribute);
     $this->subject->afterExecute($this->mediaGalleryReadHandler, $this->product);
 }
Exemplo n.º 3
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testBeforeExecute()
 {
     $mediaData = ['images' => ['72mljfhmasfilp9cuq' => ['position' => '3', 'media_type' => 'external-video', 'file' => '/i/n/index111111.jpg', 'value_id' => '4', 'label' => '', 'disabled' => '0', 'removed' => '', 'video_provider' => 'youtube', 'video_url' => 'https://www.youtube.com/watch?v=abcdefghij', 'video_title' => 'Some second title', 'video_description' => 'Description second', 'video_metadata' => 'meta two', 'role' => ''], 'w596fi79hv1p6wj21u' => ['position' => '4', 'media_type' => 'external-video', 'video_provider' => '', 'file' => '/h/d/hd_image.jpg', 'value_id' => '7', 'label' => '', 'disabled' => '0', 'removed' => '', 'video_url' => '', 'video_title' => '', 'video_description' => '', 'video_metadata' => '', 'role' => ''], 'tcodwd7e0dirifr64j' => ['position' => '4', 'media_type' => 'external-video', 'video_provider' => '', 'file' => '/h/d/hd_image.jpg', 'value_id' => '', 'label' => '', 'disabled' => '0', 'removed' => '', 'video_url' => '', 'video_title' => '', 'video_description' => '', 'video_metadata' => '', 'role' => '', 'save_data_from' => '7', 'new_file' => '/i/n/index_4.jpg']]];
     $this->product->expects($this->any())->method('getData')->with('media_gallery')->willReturn($mediaData);
     $this->product->expects($this->any())->method('getStoreId')->willReturn(0);
     $resourceEntryResult = [['value_id' => '4', 'store_id' => 1, 'video_provider_default' => 'youtube', 'video_url_default' => 'https://www.youtube.com/watch?v=abcdefghij', 'video_title_default' => 'Some first title', 'video_description_default' => 'Description first', 'video_metadata_default' => 'meta one', 'video_provider' => 'youtube', 'video_url' => 'https://www.youtube.com/watch?v=abcdefghij', 'video_title' => 'Some first title', 'video_description' => 'Description first', 'video_metadata' => 'meta one'], ['value_id' => '7', 'store_id' => 1, 'video_provider_default' => 'youtube', 'video_url_default' => 'https://www.youtube.com/watch?v=ab123456', 'video_title_default' => 'Some second title', 'video_description_default' => 'Description second', 'video_metadata_default' => 'meta two', 'video_provider' => 'youtube', 'video_url' => 'https://www.youtube.com/watch?v=ab123456', 'video_title' => 'Some second title', 'video_description' => 'Description second', 'video_metadata' => '']];
     $this->resourceModel->expects($this->once())->method('loadDataFromTableByValueId')->willReturn($resourceEntryResult);
     $this->mediaGalleryCreateHandler->expects($this->any())->method('getAttribute')->willReturn($this->attribute);
     $this->subject->beforeExecute($this->mediaGalleryCreateHandler, 'Magento\\Catalog\\Api\\Data\\ProductInterface', $this->product);
 }
Exemplo n.º 4
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.º 5
0
 /**
  * @param \Magento\Catalog\Model\Product $product
  * @return $this
  */
 protected function duplicate($product)
 {
     $mediaGalleryData = $product->getData($this->getAttribute()->getAttributeCode());
     if (!isset($mediaGalleryData['images']) || !is_array($mediaGalleryData['images'])) {
         return $this;
     }
     $this->resourceModel->duplicate($this->getAttribute()->getAttributeId(), isset($mediaGalleryData['duplicate']) ? $mediaGalleryData['duplicate'] : [], $product->getOriginalId(), $product->getData($this->metadata->getLinkField()));
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Retrieve data for update attribute
  *
  * @param  \Magento\Catalog\Model\Product $object
  * @return array
  */
 public function getAffectedFields($object)
 {
     $data = [];
     $images = (array) $object->getData($this->getAttribute()->getName());
     $tableName = $this->resourceModel->getMainTable();
     foreach ($images['images'] as $value) {
         if (empty($value['value_id'])) {
             continue;
         }
         $data[$tableName][] = ['value_id' => $value['value_id'], 'attribute_id' => $this->getAttribute()->getAttributeId(), 'entity_id' => $object->getId()];
     }
     return $data;
 }
Exemplo n.º 7
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;
 }
 /**
  * @param Gallery $originalResourceModel
  * @param Select $select
  * @return Select
  */
 public function afterCreateBatchBaseSelect(Gallery $originalResourceModel, Select $select)
 {
     $select = $select->joinLeft(['value_video' => $originalResourceModel->getTable(InstallSchema::GALLERY_VALUE_VIDEO_TABLE)], implode(' AND ', ['value.value_id = value_video.value_id', 'value.store_id = value_video.store_id']), ['video_provider' => 'provider', 'video_url' => 'url', 'video_title' => 'title', 'video_description' => 'description', 'video_metadata' => 'metadata'])->joinLeft(['default_value_video' => $originalResourceModel->getTable(InstallSchema::GALLERY_VALUE_VIDEO_TABLE)], implode(' AND ', ['default_value.value_id = default_value_video.value_id', 'default_value.store_id = default_value_video.store_id']), ['video_provider_default' => 'provider', 'video_url_default' => 'url', 'video_title_default' => 'title', 'video_description_default' => 'description', 'video_metadata_default' => 'metadata']);
     return $select;
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function getValidationRulesBeforeSave()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getValidationRulesBeforeSave');
     if (!$pluginInfo) {
         return parent::getValidationRulesBeforeSave();
     } else {
         return $this->___callPlugins('getValidationRulesBeforeSave', func_get_args(), $pluginInfo);
     }
 }