本文整理匯總了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;
}