Skip to content

Commit d414521

Browse files
ACPT-1181: reset mutable state after request
1 parent c766d6c commit d414521

File tree

115 files changed

+1430
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+1430
-316
lines changed

app/code/Magento/Authorization/Model/CompositeUserContext.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Authorization\Model;
88

99
use Magento\Framework\ObjectManager\Helper\Composite as CompositeHelper;
10+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1011

1112
/**
1213
* User context.
@@ -17,7 +18,7 @@
1718
* @api
1819
* @since 100.0.2
1920
*/
20-
class CompositeUserContext implements \Magento\Authorization\Model\UserContextInterface
21+
class CompositeUserContext implements \Magento\Authorization\Model\UserContextInterface, ResetAfterRequestInterface
2122
{
2223
/**
2324
* @var UserContextInterface[]
@@ -92,4 +93,12 @@ protected function getUserContext()
9293
}
9394
return $this->chosenUserContext;
9495
}
96+
97+
/**
98+
* @inheritDoc
99+
*/
100+
public function _resetState(): void
101+
{
102+
$this->chosenUserContext = null;
103+
}
95104
}

app/code/Magento/Bundle/Model/Plugin/Frontend/ProductIdentitiesExtender.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99

1010
use Magento\Bundle\Model\Product\Type as BundleType;
1111
use Magento\Catalog\Model\Product as CatalogProduct;
12+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1213

1314
/**
1415
* Add child identities to product identities on storefront.
1516
*/
16-
class ProductIdentitiesExtender
17+
class ProductIdentitiesExtender implements ResetAfterRequestInterface
1718
{
1819
/**
1920
* @var BundleType
@@ -68,4 +69,12 @@ private function getChildrenIds($entityId): array
6869

6970
return $this->cacheChildrenIds[$entityId];
7071
}
72+
73+
/**
74+
* @inheritDoc
75+
*/
76+
public function _resetState(): void
77+
{
78+
$this->cacheChildrenIds = [];
79+
}
7180
}

app/code/Magento/Bundle/Model/Plugin/ProductIdentitiesExtender.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99

1010
use Magento\Bundle\Model\Product\Type as BundleType;
1111
use Magento\Catalog\Model\Product as CatalogProduct;
12+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1213

1314
/**
1415
* Add parent identities to product identities.
1516
*/
16-
class ProductIdentitiesExtender
17+
class ProductIdentitiesExtender implements ResetAfterRequestInterface
1718
{
1819
/**
1920
* @var BundleType
@@ -68,4 +69,12 @@ private function getParentIdsByChild($entityId): array
6869

6970
return $this->cacheParentIdsByChild[$entityId];
7071
}
72+
73+
/**
74+
* @inheritDoc
75+
*/
76+
public function _resetState(): void
77+
{
78+
$this->cacheParentIdsByChild = [];
79+
}
7180
}

app/code/Magento/Bundle/Model/Product/SelectionProductsDisabledRequired.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\EntityManager\MetadataPool;
1111
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1212
use Magento\Bundle\Model\ResourceModel\Selection as BundleSelection;
13+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1314
use Magento\Store\Model\StoreManagerInterface;
1415
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
1516
use Magento\Catalog\Model\Product;
@@ -18,7 +19,7 @@
1819
/**
1920
* Class to return ids of options and child products when all products in required option are disabled in bundle product
2021
*/
21-
class SelectionProductsDisabledRequired
22+
class SelectionProductsDisabledRequired implements ResetAfterRequestInterface
2223
{
2324
/**
2425
* @var BundleSelection
@@ -161,4 +162,12 @@ private function getCacheKey(int $bundleId, int $websiteId): string
161162
{
162163
return $bundleId . '-' . $websiteId;
163164
}
165+
166+
/**
167+
* @inheritDoc
168+
*/
169+
public function _resetState(): void
170+
{
171+
$this->productsDisabledRequired = [];
172+
}
164173
}

app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Bundle\Pricing\Price\BundleSelectionFactory;
1313
use Magento\Bundle\Pricing\Price\BundleSelectionPrice;
1414
use Magento\Catalog\Model\Product;
15+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1516
use Magento\Framework\Pricing\Adjustment\Calculator as CalculatorBase;
1617
use Magento\Framework\Pricing\Amount\AmountFactory;
1718
use Magento\Framework\Pricing\Amount\AmountInterface;
@@ -25,7 +26,7 @@
2526
* Bundle price calculator
2627
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2728
*/
28-
class Calculator implements BundleCalculatorInterface
29+
class Calculator implements BundleCalculatorInterface, ResetAfterRequestInterface
2930
{
3031
/**
3132
* @var CalculatorBase
@@ -425,4 +426,12 @@ public function processOptions($option, $selectionPriceList, $searchMin = true)
425426
}
426427
return $result;
427428
}
429+
430+
/**
431+
* @inheritDoc
432+
*/
433+
public function _resetState(): void
434+
{
435+
$this->optionAmount = [];
436+
}
428437
}

app/code/Magento/Bundle/Pricing/Adjustment/DefaultSelectionPriceListProvider.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
use Magento\Catalog\Model\Product;
1212
use Magento\Bundle\Model\Product\Price;
1313
use Magento\Catalog\Helper\Data as CatalogData;
14+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1415
use Magento\Store\Model\StoreManagerInterface;
1516
use Magento\Store\Api\WebsiteRepositoryInterface;
1617

1718
/**
1819
* Provide lightweight implementation which uses price index
1920
*/
20-
class DefaultSelectionPriceListProvider implements SelectionPriceListProviderInterface
21+
class DefaultSelectionPriceListProvider implements SelectionPriceListProviderInterface, ResetAfterRequestInterface
2122
{
2223
/**
2324
* @var BundleSelectionFactory
@@ -245,4 +246,12 @@ private function getBundleOptions(Product $saleableItem)
245246
{
246247
return $saleableItem->getTypeInstance()->getOptionsCollection($saleableItem);
247248
}
249+
250+
/**
251+
* @inheritDoc
252+
*/
253+
public function _resetState(): void
254+
{
255+
$this->priceList = [];
256+
}
248257
}

app/code/Magento/Bundle/Pricing/Price/BundleOptions.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
namespace Magento\Bundle\Pricing\Price;
99

1010
use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface;
11+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1112
use Magento\Framework\Pricing\SaleableInterface;
1213
use Magento\Framework\Pricing\Amount\AmountInterface;
1314
use Magento\Catalog\Model\Product;
1415

1516
/**
1617
* Bundle option price calculation model.
1718
*/
18-
class BundleOptions
19+
class BundleOptions implements ResetAfterRequestInterface
1920
{
2021
/**
2122
* @var BundleCalculatorInterface
@@ -135,4 +136,12 @@ public function getOptionSelectionAmount(
135136

136137
return $this->optionSelectionAmountCache[$cacheKey];
137138
}
139+
140+
/**
141+
* @inheritDoc
142+
*/
143+
public function _resetState(): void
144+
{
145+
$this->optionSelectionAmountCache = [];
146+
}
138147
}

app/code/Magento/Bundle/Pricing/Price/BundleRegularPrice.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
namespace Magento\Bundle\Pricing\Price;
88

99
use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface;
10+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1011
use Magento\Framework\Pricing\Amount\AmountInterface;
1112
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
1213
use Magento\Bundle\Model\Product\Price;
1314

1415
/**
1516
* Bundle product regular price model
1617
*/
17-
class BundleRegularPrice extends \Magento\Catalog\Pricing\Price\RegularPrice implements RegularPriceInterface
18+
class BundleRegularPrice extends \Magento\Catalog\Pricing\Price\RegularPrice implements RegularPriceInterface, ResetAfterRequestInterface
1819
{
1920
/**
2021
* @var BundleCalculatorInterface
@@ -72,4 +73,13 @@ public function getMinimalPrice()
7273
{
7374
return $this->getAmount();
7475
}
76+
77+
/**
78+
* @inheritDoc
79+
*/
80+
public function _resetState(): void
81+
{
82+
$this->maximalPrice = null;
83+
$this->amount = [];
84+
}
7585
}

app/code/Magento/BundleGraphQl/Model/Resolver/BundleItemLinks.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,43 @@
77

88
namespace Magento\BundleGraphQl\Model\Resolver;
99

10-
use Magento\Framework\Exception\LocalizedException;
11-
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1210
use Magento\BundleGraphQl\Model\Resolver\Links\Collection;
11+
use Magento\BundleGraphQl\Model\Resolver\Links\CollectionFactory;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Framework\GraphQl\Config\Element\Field;
1415
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1516
use Magento\Framework\GraphQl\Query\ResolverInterface;
17+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1618

1719
/**
1820
* @inheritdoc
1921
*/
2022
class BundleItemLinks implements ResolverInterface
2123
{
2224
/**
23-
* @var Collection
25+
* @var CollectionFactory
2426
*/
25-
private $linkCollection;
27+
private CollectionFactory $linkCollectionFactory;
2628

2729
/**
2830
* @var ValueFactory
2931
*/
30-
private $valueFactory;
32+
private ValueFactory $valueFactory;
3133

3234
/**
33-
* @param Collection $linkCollection
35+
* @param Collection $linkCollection Deprecated. Use $linkCollectionFactory instead
3436
* @param ValueFactory $valueFactory
37+
* @param CollectionFactory|null $linkCollectionFactory
38+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3539
*/
3640
public function __construct(
3741
Collection $linkCollection,
38-
ValueFactory $valueFactory
42+
ValueFactory $valueFactory,
43+
CollectionFactory $linkCollectionFactory = null
3944
) {
40-
$this->linkCollection = $linkCollection;
45+
$this->linkCollectionFactory = $linkCollectionFactory
46+
?: ObjectManager::getInstance()->get(CollectionFactory::class);
4147
$this->valueFactory = $valueFactory;
4248
}
4349

@@ -49,12 +55,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4955
if (!isset($value['option_id']) || !isset($value['parent_id'])) {
5056
throw new LocalizedException(__('"option_id" and "parent_id" values should be specified'));
5157
}
52-
53-
$this->linkCollection->addIdFilters((int)$value['option_id'], (int)$value['parent_id']);
54-
$result = function () use ($value) {
55-
return $this->linkCollection->getLinksForOptionId((int)$value['option_id']);
58+
$linkCollection = $this->linkCollectionFactory->create();
59+
$linkCollection->addIdFilters((int)$value['option_id'], (int)$value['parent_id']);
60+
$result = function () use ($value, $linkCollection) {
61+
return $linkCollection->getLinksForOptionId((int)$value['option_id']);
5662
};
57-
5863
return $this->valueFactory->create($result);
5964
}
6065
}

app/code/Magento/BundleGraphQl/Model/Resolver/BundleItems.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,60 @@
77

88
namespace Magento\BundleGraphQl\Model\Resolver;
99

10-
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1110
use Magento\Bundle\Model\Product\Type;
1211
use Magento\BundleGraphQl\Model\Resolver\Options\Collection;
12+
use Magento\BundleGraphQl\Model\Resolver\Options\CollectionFactory;
1313
use Magento\Catalog\Api\Data\ProductInterface;
14+
use Magento\Framework\App\ObjectManager;
1415
use Magento\Framework\EntityManager\MetadataPool;
1516
use Magento\Framework\GraphQl\Config\Element\Field;
1617
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1718
use Magento\Framework\GraphQl\Query\ResolverInterface;
19+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1820

1921
/**
2022
* @inheritdoc
2123
*/
2224
class BundleItems implements ResolverInterface
2325
{
2426
/**
25-
* @var Collection
27+
* @var CollectionFactory
2628
*/
27-
private $bundleOptionCollection;
29+
private CollectionFactory $bundleOptionCollectionFactory;
2830

2931
/**
3032
* @var ValueFactory
3133
*/
32-
private $valueFactory;
34+
private ValueFactory $valueFactory;
3335

3436
/**
3537
* @var MetadataPool
3638
*/
37-
private $metadataPool;
39+
private MetadataPool $metadataPool;
3840

3941
/**
40-
* @param Collection $bundleOptionCollection
42+
* @param Collection $bundleOptionCollection Deprecated. Use $bundleOptionCollectionFactory
4143
* @param ValueFactory $valueFactory
4244
* @param MetadataPool $metadataPool
45+
* @param CollectionFactory|null $bundleOptionCollectionFactory
46+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4347
*/
4448
public function __construct(
4549
Collection $bundleOptionCollection,
4650
ValueFactory $valueFactory,
47-
MetadataPool $metadataPool
51+
MetadataPool $metadataPool,
52+
CollectionFactory $bundleOptionCollectionFactory = null
4853
) {
49-
$this->bundleOptionCollection = $bundleOptionCollection;
54+
$this->bundleOptionCollectionFactory = $bundleOptionCollectionFactory
55+
?: ObjectManager::getInstance()->get(CollectionFactory::class);
5056
$this->valueFactory = $valueFactory;
5157
$this->metadataPool = $metadataPool;
5258
}
5359

5460
/**
5561
* Fetch and format bundle option items.
5662
*
57-
* {@inheritDoc}
63+
* @inheritDoc
5864
*/
5965
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
6066
{
@@ -68,17 +74,15 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6874
};
6975
return $this->valueFactory->create($result);
7076
}
71-
72-
$this->bundleOptionCollection->addParentFilterData(
77+
$bundleOptionCollection = $this->bundleOptionCollectionFactory->create();
78+
$bundleOptionCollection->addParentFilterData(
7379
(int)$value[$linkField],
7480
(int)$value['entity_id'],
7581
$value[ProductInterface::SKU]
7682
);
77-
78-
$result = function () use ($value, $linkField) {
79-
return $this->bundleOptionCollection->getOptionsByParentId((int)$value[$linkField]);
83+
$result = function () use ($value, $linkField, $bundleOptionCollection) {
84+
return $bundleOptionCollection->getOptionsByParentId((int)$value[$linkField]);
8085
};
81-
8286
return $this->valueFactory->create($result);
8387
}
8488
}

0 commit comments

Comments
 (0)