Skip to content

Commit

Permalink
Clear product cache in test context rather than in Product updater se…
Browse files Browse the repository at this point in the history
…rvice
  • Loading branch information
jolelievre committed Dec 15, 2020
1 parent c9b30c7 commit 91dac20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/Adapter/Product/Update/ProductSupplierUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ public function resetDefaultSupplier(Product $product): void
$product->wholesale_price = '0';
$product->id_supplier = 0;

// Important for ps_facetedsearch module, without this it raises caching issues by invoking Product::priceCalculation()
Product::flushPriceCache();

$this->productRepository->partialUpdate(
$product,
['supplier_reference', 'wholesale_price', 'id_supplier'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use PHPUnit\Framework\Assert;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductNotFoundException;
use Product;
use RuntimeException;
use Tests\Integration\Behaviour\Features\Context\Util\CombinationDetails;
use Tests\Integration\Behaviour\Features\Context\Util\ProductCombinationFactory;
Expand Down Expand Up @@ -67,6 +68,11 @@ public function addCombinationsToProduct(string $productReference, TableNode $ta
foreach ($combinations as $combination) {
$this->getSharedStorage()->set($combination->reference, (int) $combination->id);
}

// Product class has a lot of cache that is set as soon as the product is created, including for prices
// which are cached for each combinations. Since it was cached when the combinations did not exist we need
// to clear it so that the newly created combinations' prices are correctly computed next time they are needed.
Product::resetStaticCache();
}

/**
Expand Down

0 comments on commit 91dac20

Please sign in to comment.