Custom Attribute Values Hold

This commit is contained in:
devansh bawari 2021-07-20 13:17:06 +05:30
parent 7be4faa69f
commit 0a44367a8e
1 changed files with 7 additions and 1 deletions

View File

@ -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;
}
/**