本文整理汇总了PHP中Magento\Catalog\Model\Product::getMediaAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getMediaAttributes方法的具体用法?PHP Product::getMediaAttributes怎么用?PHP Product::getMediaAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::getMediaAttributes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMediaAttributes
public function getMediaAttributes()
{
$expected = [];
$mediaAttributes = $this->setupMediaAttributes();
foreach ($mediaAttributes as $mediaAttribute) {
$expected[$mediaAttribute->getAttributeCode()] = $mediaAttribute;
}
$this->assertEquals($expected, $this->model->getMediaAttributes());
}
示例2: getMediaAttributes
/**
* {@inheritdoc}
*/
public function getMediaAttributes()
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'getMediaAttributes');
if (!$pluginInfo) {
return parent::getMediaAttributes();
} else {
return $this->___callPlugins('getMediaAttributes', func_get_args(), $pluginInfo);
}
}
示例3: testGetMediaAttributes
public function testGetMediaAttributes()
{
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product', ['data' => ['media_attributes' => 'test']]);
$this->assertEquals('test', $model->getMediaAttributes());
$attributes = $this->_model->getMediaAttributes();
$this->assertArrayHasKey('image', $attributes);
$this->assertArrayHasKey('small_image', $attributes);
$this->assertArrayHasKey('thumbnail', $attributes);
$this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', $attributes['image']);
}
示例4: setMediaAttribute
/**
* Set media attribute value
*
* @param \Magento\Catalog\Model\Product $product
* @param string|string[] $mediaAttribute
* @param string $value
* @return $this
*/
public function setMediaAttribute(\Magento\Catalog\Model\Product $product, $mediaAttribute, $value)
{
$mediaAttributeCodes = array_keys($product->getMediaAttributes());
if (is_array($mediaAttribute)) {
foreach ($mediaAttribute as $atttribute) {
if (in_array($atttribute, $mediaAttributeCodes)) {
$product->setData($atttribute, $value);
}
}
} elseif (in_array($mediaAttribute, $mediaAttributeCodes)) {
$product->setData($mediaAttribute, $value);
}
return $this;
}
示例5: beforeSave
/**
* @param Product $object
* @return Product
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function beforeSave($object)
{
$attrCode = $this->getAttribute()->getAttributeCode();
$value = $object->getData($attrCode);
if (!is_array($value) || !isset($value['images'])) {
return $object;
}
if (!is_array($value['images']) && strlen($value['images']) > 0) {
$value['images'] = $this->jsonHelper->jsonDecode($value['images']);
}
if (!is_array($value['images'])) {
$value['images'] = [];
}
$clearImages = [];
$newImages = [];
$existImages = [];
if ($object->getIsDuplicate() != true) {
foreach ($value['images'] as &$image) {
if (!empty($image['removed'])) {
$clearImages[] = $image['file'];
} elseif (empty($image['value_id'])) {
$newFile = $this->moveImageFromTmp($image['file']);
$image['new_file'] = $newFile;
$newImages[$image['file']] = $image;
$image['file'] = $newFile;
} else {
$existImages[$image['file']] = $image;
}
}
} else {
// For duplicating we need copy original images.
$duplicate = [];
foreach ($value['images'] as &$image) {
if (empty($image['value_id'])) {
continue;
}
$duplicate[$image['value_id']] = $this->copyImage($image['file']);
$image['new_file'] = $duplicate[$image['value_id']];
$newImages[$image['file']] = $image;
}
$value['duplicate'] = $duplicate;
}
foreach ($object->getMediaAttributes() as $mediaAttribute) {
$mediaAttrCode = $mediaAttribute->getAttributeCode();
$attrData = $object->getData($mediaAttrCode);
if (in_array($attrData, $clearImages)) {
$object->setData($mediaAttrCode, 'no_selection');
}
if (in_array($attrData, array_keys($newImages))) {
$object->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
$object->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
}
if (in_array($attrData, array_keys($existImages))) {
$object->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
}
}
$object->setData($attrCode, $value);
return $object;
}
示例6: execute
/**
* @param string $entityType
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function execute($entityType, $product)
{
$attrCode = $this->getAttribute()->getAttributeCode();
$value = $product->getData($attrCode);
if (!is_array($value) || !isset($value['images'])) {
return $product;
}
if (!is_array($value['images']) && strlen($value['images']) > 0) {
$value['images'] = $this->jsonHelper->jsonDecode($value['images']);
}
if (!is_array($value['images'])) {
$value['images'] = [];
}
$clearImages = [];
$newImages = [];
$existImages = [];
if ($product->getIsDuplicate() != true) {
foreach ($value['images'] as &$image) {
if (!empty($image['removed'])) {
$clearImages[] = $image['file'];
} elseif (empty($image['value_id'])) {
$newFile = $this->moveImageFromTmp($image['file']);
$image['new_file'] = $newFile;
$newImages[$image['file']] = $image;
$image['file'] = $newFile;
} else {
$existImages[$image['file']] = $image;
}
}
} else {
// For duplicating we need copy original images.
$duplicate = [];
foreach ($value['images'] as &$image) {
if (empty($image['value_id']) || !empty($image['removed'])) {
continue;
}
$duplicate[$image['value_id']] = $this->copyImage($image['file']);
$image['new_file'] = $duplicate[$image['value_id']];
$newImages[$image['file']] = $image;
}
$value['duplicate'] = $duplicate;
}
/* @var $mediaAttribute \Magento\Catalog\Api\Data\ProductAttributeInterface */
foreach ($product->getMediaAttributes() as $mediaAttribute) {
$mediaAttrCode = $mediaAttribute->getAttributeCode();
$attrData = $product->getData($mediaAttrCode);
if (in_array($attrData, $clearImages)) {
$product->setData($mediaAttrCode, 'no_selection');
}
if (in_array($attrData, array_keys($newImages))) {
$product->setData($mediaAttrCode, $newImages[$attrData]['new_file']);
$product->setData($mediaAttrCode . '_label', $newImages[$attrData]['label']);
}
if (in_array($attrData, array_keys($existImages))) {
$product->setData($mediaAttrCode . '_label', $existImages[$attrData]['label']);
}
$product->addAttributeUpdate($mediaAttrCode, $product->getData($mediaAttrCode), $product->getStoreId());
}
$product->setData($attrCode, $value);
if ($product->getIsDuplicate() == true) {
$this->duplicate($product);
return $product;
}
if (!is_array($value) || !isset($value['images']) || $product->isLockedAttribute($attrCode)) {
return $product;
}
$this->processDeletedImages($product, $value['images']);
$this->processNewAndExistingImages($product, $value['images']);
$product->setData($attrCode, $value);
return $product;
}
示例7: getMediaAttributeValues
/**
* Retrieve assoc array that contains media attribute values of the given product
*
* @param Product $product
* @return array
*/
protected function getMediaAttributeValues(Product $product)
{
$mediaAttributeCodes = array_keys($product->getMediaAttributes());
$mediaAttributeValues = array();
foreach ($mediaAttributeCodes as $attributeCode) {
$mediaAttributeValues[$attributeCode] = $product->getData($attributeCode);
}
return $mediaAttributeValues;
}