Skip to content

Trigger event to override inventory locations per order#4276

Open
yoannisj wants to merge 1 commit intocraftcms:5.xfrom
yoannisj:feature/4273-per-order-inventory-locations
Open

Trigger event to override inventory locations per order#4276
yoannisj wants to merge 1 commit intocraftcms:5.xfrom
yoannisj:feature/4273-per-order-inventory-locations

Conversation

@yoannisj
Copy link
Copy Markdown

Description

This PR adds the following changes in order to allow modules and plugins to select a subset of the store's inventory locations, when Craft-Commerce is accessing a given purchasable's stock. When this is done in the context of an order, then this selection can be made based on the order's details.

  • trigger a new event craft\commerce\services\InventoryLocations:: EVENT_REGISTER_INVENTORY_LOCATIONS_FOR_PURCHASABLE when accessing a given purchasable's stock, which allows modules and plugins to select a subset of the store’s inventory locations
  • expose the order details in the newly triggered event, when the purchasable's stock is accessed in the context of an order
  • add first argument $order to \craft\commerce\base\Purchasable::getStock()` to aggregate stock in order-specific inventory locations only
  • add first argument $order to \craft\commerce\base\Purchasable::hasStock()` to check for stock in order-specific inventory locations only
  • verify stock available in order-specific inventory locations when checking a purchasable’s availability

Related issues

The changes make it possible for modules or plugins to implement the use-cases described in #4273 and most use-cases from #4247 .

- trigger event when getting the inventory locations for given purchasable `craft\commerce\services\InventoryLocations:: EVENT_REGISTER_INVENTORY_LOCATIONS_FOR_PURCHASABLE ` which allows modules and plugins to select a subset of the store’s inventory locations based on the order details
- add first argument `$order` to \craft\commerce\base\Purchasable::getStock()` to aggregate stock in order-specific inventory locations only
- add first argument `$order` to \craft\commerce\base\Purchasable::hasStock()` to check for stock in order-specific inventory locations only
- verify stock available in order-specific inventory locations when checking a purchasable’s availability
@yoannisj yoannisj requested a review from a team as a code owner April 10, 2026 20:36
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