Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use allVariants as the attribute that manages variants on Products #3779

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading