本文整理汇总了PHP中Magento\Catalog\Model\Product::getMediaAttributeValues方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getMediaAttributeValues方法的具体用法?PHP Product::getMediaAttributeValues怎么用?PHP Product::getMediaAttributeValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::getMediaAttributeValues方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetMediaAttributeValues
public function testGetMediaAttributeValues()
{
$this->setupMediaAttributes();
$this->model->setData('image', 'imageValue');
$this->model->setData('small_image', 'smallImageValue');
$expectedMediaAttributeValues = ['image' => 'imageValue', 'small_image' => 'smallImageValue'];
$this->assertEquals($expectedMediaAttributeValues, $this->model->getMediaAttributeValues());
}
示例2: testGetMediaAttributeValues
public function testGetMediaAttributeValues()
{
$this->mediaConfig->expects($this->once())->method('getMediaAttributeCodes')->willReturn(['image', 'small_image']);
$this->model->setData('image', 'imageValue');
$this->model->setData('small_image', 'smallImageValue');
$expectedMediaAttributeValues = ['image' => 'imageValue', 'small_image' => 'smallImageValue'];
$this->assertEquals($expectedMediaAttributeValues, $this->model->getMediaAttributeValues());
}
示例3: convertTo
/**
* @param Product $product
* @param array $rowData
* @return ProductAttributeMediaGalleryEntryInterface $entry
*/
public function convertTo(Product $product, array $rowData)
{
$image = $rowData;
$productImages = $product->getMediaAttributeValues();
if (!isset($image['types'])) {
$image['types'] = array_keys($productImages, $image['file']);
}
$entry = $this->mediaGalleryEntryFactory->create();
$this->dataObjectHelper->populateWithArray($entry, $image, '\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface');
if (isset($image['value_id'])) {
$entry->setId($image['value_id']);
}
return $entry;
}
示例4: getMediaAttributeValues
/**
* {@inheritdoc}
*/
public function getMediaAttributeValues()
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getMediaAttributeValues');
if (!$pluginInfo) {
return parent::getMediaAttributeValues();
} else {
return $this->___callPlugins('getMediaAttributeValues', func_get_args(), $pluginInfo);
}
}
示例5: getProductMediaGallery
/**
* 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 ModelProduct $product
* @return array
*/
public function getProductMediaGallery(ModelProduct $product)
{
if (!in_array($product->getData('image'), [null, self::EMPTY_IMAGE_VALUE], true)) {
$baseImage = $product->getData('image');
} else {
$productMediaAttributes = array_filter($product->getMediaAttributeValues(), function ($value) {
return $value !== self::EMPTY_IMAGE_VALUE && $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;
}
示例6: buildImageUrl
/**
* @param Product $product
* @param Store $store
* @return string|null
*/
protected function buildImageUrl(Product $product, Store $store)
{
$primary = $this->_dataHelper->getProductImageVersion($store);
$secondary = 'image';
// The "base" image.
$media = $product->getMediaAttributeValues();
$image = isset($media[$primary]) ? $media[$primary] : (isset($media[$secondary]) ? $media[$secondary] : null);
if (empty($image)) {
return null;
}
return $product->getMediaConfig()->getMediaUrl($image);
}