From 0a44367a8e4b7dbe064628bb94cce1b342c310c5 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Tue, 20 Jul 2021 13:17:06 +0530 Subject: [PATCH] Custom Attribute Values Hold --- packages/Webkul/Product/src/Models/Product.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; } /**