Refresh Method Added

This commit is contained in:
devansh bawari 2021-07-20 14:54:22 +05:30
parent a15ac86319
commit 643384eade
2 changed files with 28 additions and 7 deletions

View File

@ -43,6 +43,13 @@ class Product extends Model implements ProductContract
*/
protected $typeInstance;
/**
* Loaded attribute values.
*
* @var $loadedAttributeValues
*/
public static $loadedAttributeValues = [];
/**
* The "booted" method of the model.
*
@ -65,6 +72,16 @@ class Product extends Model implements ProductContract
});
}
/**
* Refresh the loaded attribute values.
*
* @return void
*/
public function refreshloadedAttributeValues()
{
self::$loadedAttributeValues = [];
}
/**
* Get the product attribute family that owns the product.
*/
@ -370,9 +387,7 @@ class Product extends Model implements ProductContract
*/
public function getCustomAttributeValue($attribute)
{
static $loadedAttributeValue = [];
if (!$attribute) {
if (! $attribute) {
return;
}
@ -380,10 +395,10 @@ class Product extends Model implements ProductContract
$channel = core()->getRequestedChannelCode();
if (
array_key_exists($this->id, $loadedAttributeValue)
&& array_key_exists($attribute->id, $loadedAttributeValue[$this->id])
array_key_exists($this->id, self::$loadedAttributeValues)
&& array_key_exists($attribute->id, self::$loadedAttributeValues[$this->id])
) {
return $loadedAttributeValue[$this->id][$attribute->id];
return self::$loadedAttributeValues[$this->id][$attribute->id];
}
if ($attribute->value_per_channel) {
@ -400,7 +415,7 @@ class Product extends Model implements ProductContract
}
}
return $loadedAttributeValue[$this->id][$attribute->id] = $attributeValue[ProductAttributeValue::$attributeTypeFields[$attribute->type]] ?? null;
return self::$loadedAttributeValues[$this->id][$attribute->id] = $attributeValue[ProductAttributeValue::$attributeTypeFields[$attribute->type]] ?? null;
}
/**

View File

@ -80,6 +80,8 @@ class CartCest
])
->update(['boolean_value' => 0]);
$this->simpleProduct2->refreshloadedAttributeValues();
Event::dispatch('catalog.product.update.after', $this->simpleProduct2->refresh());
$I->assertFalse(cart()->hasError());
@ -107,6 +109,8 @@ class CartCest
])
->update(['boolean_value' => 0]);
$this->simpleProduct2->refreshloadedAttributeValues();
Event::dispatch('catalog.product.update.after', $this->downloadableProduct2->refresh());
$I->comment('add dP1 to cart, dP2 should be removed now');
@ -128,6 +132,8 @@ class CartCest
])
->update(['boolean_value' => 0]);
$this->simpleProduct2->refreshloadedAttributeValues();
Event::dispatch('catalog.product.update.after', $this->virtualProduct2->refresh());
$I->comment('change quantity of vP1, vP2 should be removed now');