Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix webapi product custom attribute preprocessor execution #38657

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,12 @@ protected function convertCustomAttributeValue($customAttributesValueArray, $dat
$dataObjectClassName = ltrim($dataObjectClassName, '\\');

foreach ($customAttributesValueArray as $key => $customAttribute) {
$this->runCustomAttributePreprocessors($key, $customAttribute);
if (!is_array($customAttribute)) {
$customAttribute = [AttributeValue::ATTRIBUTE_CODE => $key, AttributeValue::VALUE => $customAttribute];
}
list($customAttributeCode, $customAttributeValue) = $this->processCustomAttribute($customAttribute);
$customAttributeCode = $this->processCustomAttributeCode($customAttribute);
$this->runCustomAttributePreprocessors($customAttributeCode, $customAttribute);
$customAttributeValue = $customAttribute[AttributeValue::VALUE];
$entityType = $this->serviceTypeToEntityTypeMap->getEntityType($dataObjectClassName);
if ($entityType) {
$type = $this->customAttributeTypeLocator->getType(
Expand Down Expand Up @@ -406,8 +407,8 @@ private function getAttributesPreprocessorsMap(): array
{
if (!$this->attributesPreprocessorsMap) {
foreach ($this->customAttributePreprocessors as $attributePreprocessor) {
foreach ($attributePreprocessor->getAffectedAttributes() as $attributeKey) {
$this->attributesPreprocessorsMap[$attributeKey][] = $attributePreprocessor;
foreach ($attributePreprocessor->getAffectedAttributes() as $attributeCode) {
$this->attributesPreprocessorsMap[$attributeCode][] = $attributePreprocessor;
}
}
}
Expand All @@ -418,17 +419,17 @@ private function getAttributesPreprocessorsMap(): array
/**
* Prepare attribute value by loaded attribute preprocessors
*
* @param mixed $key
* @param mixed $attributeCode
* @param mixed $customAttribute
*/
private function runCustomAttributePreprocessors($key, &$customAttribute)
private function runCustomAttributePreprocessors($attributeCode, &$customAttribute)
{
$preprocessorsMap = $this->getAttributesPreprocessorsMap();
if ($key && is_array($customAttribute) && array_key_exists($key, $preprocessorsMap)) {
$preprocessorsList = $preprocessorsMap[$key];
if ($attributeCode && is_array($customAttribute) && array_key_exists($attributeCode, $preprocessorsMap)) {
$preprocessorsList = $preprocessorsMap[$attributeCode];
foreach ($preprocessorsList as $attributePreprocessor) {
if ($attributePreprocessor->shouldBeProcessed($key, $customAttribute)) {
$attributePreprocessor->process($key, $customAttribute);
if ($attributePreprocessor->shouldBeProcessed($attributeCode, $customAttribute)) {
$attributePreprocessor->process($attributeCode, $customAttribute);
}
}
}
Expand All @@ -438,10 +439,10 @@ private function runCustomAttributePreprocessors($key, &$customAttribute)
* Derive the custom attribute code and value.
*
* @param string[] $customAttribute
* @return string[]
* @return string
* @throws SerializationException
*/
private function processCustomAttribute($customAttribute)
private function processCustomAttributeCode($customAttribute)
{
$camelCaseAttributeCodeKey = lcfirst(
SimpleDataObjectConverter::snakeCaseToUpperCamelCase(AttributeValue::ATTRIBUTE_CODE)
Expand Down Expand Up @@ -474,7 +475,7 @@ private function processCustomAttribute($customAttribute)
);
}

return [$customAttributeCode, $customAttribute[AttributeValue::VALUE]];
return $customAttributeCode;
}

/**
Expand Down