diff --git a/packages/Webkul/Product/src/Models/Product.php b/packages/Webkul/Product/src/Models/Product.php index 30c5ffef4..1a0653961 100755 --- a/packages/Webkul/Product/src/Models/Product.php +++ b/packages/Webkul/Product/src/Models/Product.php @@ -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; } /**