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

[5.3] Streamline update purchasable stock level #3801

Merged
merged 12 commits into from
Dec 11, 2024

Conversation

nfourtythree
Copy link
Contributor

@nfourtythree nfourtythree commented Dec 5, 2024

Description

To help when developers are programmatically creating variants or updating stock on a variant, this PR adds some helpful service methods.

WIth this, there is now a more streamlined way to update a variant's stock.

$variant = Variant::find()->one();
$quantity = 10;

// Simple call
Plugin::getInstance()->getInventory()->updatePurchasableInventoryLevel($variant, $quantity);

// If you want to `adjust` rather than `set` you can do that as follows
Plugin::getInstance()->getInventory()->updatePurchasableInventoryLevel($variant, $quantity, ['updateAction' => InventoryUpdateQuantityType::ADJUST]);

@nfourtythree nfourtythree self-assigned this Dec 5, 2024
@nfourtythree nfourtythree requested a review from a team as a code owner December 5, 2024 15:06
Copy link

linear bot commented Dec 5, 2024

@nfourtythree nfourtythree merged commit c8105c9 into 5.3 Dec 11, 2024
8 checks passed
@nfourtythree nfourtythree deleted the feature/com-271-improve-purchasable-stock-updating branch December 11, 2024 09:23
@lukeholder lukeholder mentioned this pull request Dec 11, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant