Skip to content

Commit 9943fc0

Browse files
authored
Merge pull request #3779 from craftcms/bugfix/nested-element-variant-getter
Use `allVariants` as the attribute that manages variants on Products
2 parents 5a25d30 + 09054df commit 9943fc0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/elements/Product.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,18 @@ public function getVariants(bool $includeDisabled = false): VariantCollection
10651065
return $this->_variants->filter(fn(Variant $variant) => $includeDisabled || ($variant->getStatus() === self::STATUS_ENABLED));
10661066
}
10671067

1068+
/**
1069+
* @return VariantCollection
1070+
* @throws InvalidConfigException
1071+
* @internal Do not use. Temporary method until we get a nested element manager provider in core.
1072+
*
1073+
* TODO: Remove this once we have a nested element manager provider interface in core.
1074+
*/
1075+
public function getAllVariants(): VariantCollection
1076+
{
1077+
return $this->getVariants(true);
1078+
}
1079+
10681080
/**
10691081
* @inheritdoc
10701082
*/
@@ -1187,9 +1199,9 @@ public function getVariantManager(): NestedElementManager
11871199
/** @phpstan-ignore-next-line */
11881200
fn(Product $product) => self::createVariantQuery($product),
11891201
[
1190-
'attribute' => 'variants',
1202+
'attribute' => 'allVariants', // TODO: can change this back to 'variants' once we have a nested element manager provider in core.
11911203
'propagationMethod' => $this->getType()->propagationMethod,
1192-
'valueGetter' => fn(Product $product) => $product->getVariants(true),
1204+
'valueSetter' => fn($variants) => $this->setVariants($variants), // TODO: can change this back to 'variants' once we have a nested element manager provider in core.
11931205
],
11941206
);
11951207
}

0 commit comments

Comments
 (0)