本文整理汇总了PHP中Magento\Framework\Api\DataObjectHelper::getCustomAttributeValueByType方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectHelper::getCustomAttributeValueByType方法的具体用法?PHP DataObjectHelper::getCustomAttributeValueByType怎么用?PHP DataObjectHelper::getCustomAttributeValueByType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\DataObjectHelper
的用法示例。
在下文中一共展示了DataObjectHelper::getCustomAttributeValueByType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* {@inheritdoc}
*/
public function save(CustomAttributesDataInterface $dataObjectWithCustomAttributes, $entityType, CustomAttributesDataInterface $previousCustomerData = null)
{
//Get all Image related custom attributes
$imageDataObjects = $this->dataObjectHelper->getCustomAttributeValueByType($dataObjectWithCustomAttributes->getCustomAttributes(), '\\Magento\\Framework\\Api\\Data\\ImageContentInterface');
// Return if no images to process
if (empty($imageDataObjects)) {
return $dataObjectWithCustomAttributes;
}
// For every image, save it and replace it with corresponding Eav data object
/** @var $imageDataObject \Magento\Framework\Api\AttributeValue */
foreach ($imageDataObjects as $imageDataObject) {
/** @var $imageContent \Magento\Framework\Api\Data\ImageContentInterface */
$imageContent = $imageDataObject->getValue();
$filename = $this->processImageContent($entityType, $imageContent);
//Set filename from static media location into data object
$dataObjectWithCustomAttributes->setCustomAttribute($imageDataObject->getAttributeCode(), $filename);
//Delete previously saved image if it exists
if ($previousCustomerData) {
$previousImageAttribute = $previousCustomerData->getCustomAttribute($imageDataObject->getAttributeCode());
if ($previousImageAttribute) {
$previousImagePath = $previousImageAttribute->getValue();
if (!empty($previousImagePath)) {
@unlink($this->mediaDirectory->getAbsolutePath() . $entityType . $previousImagePath);
}
}
}
}
return $dataObjectWithCustomAttributes;
}