本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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;
}