当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::getMediaGallery方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Product::getMediaGallery方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getMediaGallery方法的具体用法?PHP Product::getMediaGallery怎么用?PHP Product::getMediaGallery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\Product的用法示例。


在下文中一共展示了Product::getMediaGallery方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSetMediaGalleryEntries

 public function testSetMediaGalleryEntries()
 {
     $expectedResult = ['images' => [['value_id' => 1, 'file' => 'file1.jpg', 'label' => 'label_text', 'position' => 4, 'disabled' => false, 'types' => ['image'], 'content' => ['data' => [ImageContentInterface::NAME => 'product_image', ImageContentInterface::TYPE => 'image/jpg', ImageContentInterface::BASE64_ENCODED_DATA => 'content_data']], 'media_type' => 'image']]];
     $entryMock = $this->getMockBuilder('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface')->setMethods(['getId', 'getFile', 'getLabel', 'getPosition', 'isDisabled', 'types', 'getContent', 'getMediaType'])->getMockForAbstractClass();
     $result = ['value_id' => 1, 'file' => 'file1.jpg', 'label' => 'label_text', 'position' => 4, 'disabled' => false, 'types' => ['image'], 'content' => ['data' => [ImageContentInterface::NAME => 'product_image', ImageContentInterface::TYPE => 'image/jpg', ImageContentInterface::BASE64_ENCODED_DATA => 'content_data']], 'media_type' => 'image'];
     $this->converterMock->expects($this->once())->method('convertFrom')->with($entryMock)->willReturn($result);
     $this->model->setMediaGalleryEntries([$entryMock]);
     $this->assertEquals($expectedResult, $this->model->getMediaGallery());
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:9,代码来源:ProductTest.php

示例2: testSetMediaGalleryEntries

 public function testSetMediaGalleryEntries()
 {
     $expectedResult = ['images' => [["value_id" => 1, 'file' => 'file1.jpg', 'label' => 'label_text', 'position' => 4, 'disabled' => false, 'types' => ['image'], 'content' => ['entry_data' => 'content_data', 'mime_type' => 'image/jpg', 'name' => 'product_image']]]];
     $contentMock = $this->getMockBuilder('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryContentInterface')->setMethods(['getEntryData', 'getMimeType', 'getName'])->getMockForAbstractClass();
     $contentMock->expects($this->once())->method('getEntryData')->willReturn($expectedResult['images'][0]['content']['entry_data']);
     $contentMock->expects($this->once())->method('getMimeType')->willReturn($expectedResult['images'][0]['content']['mime_type']);
     $contentMock->expects($this->once())->method('getName')->willReturn($expectedResult['images'][0]['content']['name']);
     $entryMock = $this->getMockBuilder('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface')->setMethods(['getId', 'getFile', 'getLabel', 'getPosition', 'isDisabled', 'types', 'getContent'])->getMockForAbstractClass();
     $entryMock->expects($this->once())->method('getId')->willReturn($expectedResult['images'][0]['value_id']);
     $entryMock->expects($this->once())->method('getFile')->willReturn($expectedResult['images'][0]['file']);
     $entryMock->expects($this->once())->method('getLabel')->willReturn($expectedResult['images'][0]['label']);
     $entryMock->expects($this->once())->method('getPosition')->willReturn($expectedResult['images'][0]['position']);
     $entryMock->expects($this->once())->method('isDisabled')->willReturn($expectedResult['images'][0]['disabled']);
     $entryMock->expects($this->once())->method('getTypes')->willReturn($expectedResult['images'][0]['types']);
     $entryMock->expects($this->once())->method('getContent')->willReturn($contentMock);
     $this->model->setMediaGalleryEntries([$entryMock]);
     $this->assertEquals($expectedResult, $this->model->getMediaGallery());
 }
开发者ID:opexsw,项目名称:magento2,代码行数:18,代码来源:ProductTest.php

示例3: testSetMediaGalleryEntries

 public function testSetMediaGalleryEntries()
 {
     $expectedResult = ['images' => [["value_id" => 1, 'file' => 'file1.jpg', 'label' => 'label_text', 'position' => 4, 'disabled' => false, 'types' => ['image'], 'content' => ['data' => [ImageContentInterface::NAME => 'product_image', ImageContentInterface::TYPE => 'image/jpg', ImageContentInterface::BASE64_ENCODED_DATA => 'content_data']]]]];
     $contentMock = $this->getMockBuilder('\\Magento\\Framework\\Api\\Data\\ImageContentInterface')->setMethods(['getBase64EncodedData', 'getType', 'getName'])->disableOriginalConstructor()->getMockForAbstractClass();
     $contentMock->expects($this->once())->method('getBase64EncodedData')->willReturn($expectedResult['images'][0]['content']['data']['base64_encoded_data']);
     $contentMock->expects($this->once())->method('getType')->willReturn($expectedResult['images'][0]['content']['data']['type']);
     $contentMock->expects($this->once())->method('getName')->willReturn($expectedResult['images'][0]['content']['data']['name']);
     $entryMock = $this->getMockBuilder('\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface')->setMethods(['getId', 'getFile', 'getLabel', 'getPosition', 'isDisabled', 'types', 'getContent'])->getMockForAbstractClass();
     $entryMock->expects($this->once())->method('getId')->willReturn($expectedResult['images'][0]['value_id']);
     $entryMock->expects($this->once())->method('getFile')->willReturn($expectedResult['images'][0]['file']);
     $entryMock->expects($this->once())->method('getLabel')->willReturn($expectedResult['images'][0]['label']);
     $entryMock->expects($this->once())->method('getPosition')->willReturn($expectedResult['images'][0]['position']);
     $entryMock->expects($this->once())->method('isDisabled')->willReturn($expectedResult['images'][0]['disabled']);
     $entryMock->expects($this->once())->method('getTypes')->willReturn($expectedResult['images'][0]['types']);
     $entryMock->expects($this->once())->method('getContent')->willReturn($contentMock);
     $this->model->setMediaGalleryEntries([$entryMock]);
     $this->assertEquals($expectedResult, $this->model->getMediaGallery());
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:18,代码来源:ProductTest.php

示例4: processMediaGallery

 /**
  * @param \Magento\Catalog\Model\Product $product
  * @param array $productData
  *
  * @return array
  */
 public function processMediaGallery($product, $productData)
 {
     if (!empty($productData['image'])) {
         $image = $productData['image'];
         if (!isset($productData['media_gallery']['images'])) {
             $productData['media_gallery']['images'] = [];
         }
         if (false === array_search($image, array_column($productData['media_gallery']['images'], 'file'))) {
             $productData['small_image'] = $productData['thumbnail'] = $image;
             $productData['media_gallery']['images'][] = ['position' => 1, 'file' => $image, 'disabled' => 0, 'label' => ''];
         }
     }
     if ($product->getMediaGallery('images') && !empty($productData['media_gallery']['images'])) {
         $gallery = array_map(function ($image) {
             $image['removed'] = 1;
             return $image;
         }, $product->getMediaGallery('images'));
         $gallery = array_merge($productData['media_gallery']['images'], $gallery);
         $productData['media_gallery']['images'] = $gallery;
     }
     return $productData;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:28,代码来源:VariationHandler.php


注:本文中的Magento\Catalog\Model\Product::getMediaGallery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。