Custom Attribute Values Hold
This commit is contained in:
parent
7be4faa69f
commit
0a44367a8e
|
|
@ -370,6 +370,8 @@ class Product extends Model implements ProductContract
|
|||
*/
|
||||
public function getCustomAttributeValue($attribute)
|
||||
{
|
||||
static $loadedAttributeValue = [];
|
||||
|
||||
if (! $attribute) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -377,6 +379,10 @@ class Product extends Model implements ProductContract
|
|||
$locale = core()->checkRequestedLocaleCodeInRequestedChannel();
|
||||
$channel = core()->getRequestedChannelCode();
|
||||
|
||||
if (array_key_exists($this->id, $loadedAttributeValue)) {
|
||||
return $loadedAttributeValue[$this->id];
|
||||
}
|
||||
|
||||
if ($attribute->value_per_channel) {
|
||||
if ($attribute->value_per_locale) {
|
||||
$attributeValue = $this->attribute_values()->where('channel', $channel)->where('locale', $locale)->where('attribute_id', $attribute->id)->first();
|
||||
|
|
@ -391,7 +397,7 @@ class Product extends Model implements ProductContract
|
|||
}
|
||||
}
|
||||
|
||||
return $attributeValue[ProductAttributeValue::$attributeTypeFields[$attribute->type]] ?? null;
|
||||
return $loadedAttributeValue[$this->id] = $attributeValue[ProductAttributeValue::$attributeTypeFields[$attribute->type]] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue