Skip to content

Commit

Permalink
Merge pull request #3779 from craftcms/bugfix/nested-element-variant-…
Browse files Browse the repository at this point in the history
…getter

Use `allVariants` as the attribute that manages variants on Products
  • Loading branch information
lukeholder authored Dec 3, 2024
2 parents 5a25d30 + 09054df commit 9943fc0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/elements/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,18 @@ public function getVariants(bool $includeDisabled = false): VariantCollection
return $this->_variants->filter(fn(Variant $variant) => $includeDisabled || ($variant->getStatus() === self::STATUS_ENABLED));
}

/**
* @return VariantCollection
* @throws InvalidConfigException
* @internal Do not use. Temporary method until we get a nested element manager provider in core.
*
* TODO: Remove this once we have a nested element manager provider interface in core.
*/
public function getAllVariants(): VariantCollection
{
return $this->getVariants(true);
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -1187,9 +1199,9 @@ public function getVariantManager(): NestedElementManager
/** @phpstan-ignore-next-line */
fn(Product $product) => self::createVariantQuery($product),
[
'attribute' => 'variants',
'attribute' => 'allVariants', // TODO: can change this back to 'variants' once we have a nested element manager provider in core.
'propagationMethod' => $this->getType()->propagationMethod,
'valueGetter' => fn(Product $product) => $product->getVariants(true),
'valueSetter' => fn($variants) => $this->setVariants($variants), // TODO: can change this back to 'variants' once we have a nested element manager provider in core.
],
);
}
Expand Down

0 comments on commit 9943fc0

Please sign in to comment.