Problem/Motivation
Interface with the Commerce AvailabilityManager service that implements AvailabilityManagerInterface
<?php
commerce.availability_manager:
class: Drupal\commerce\AvailabilityManager
tags:
- { name: service_collector, tag: commerce.availability_checker, call: addChecker }
?>
This service allows adding instances of AvailabilityCheckerInterface using addChecker.
The service then provides a method to check availability check(PurchasableEntityInterface $entity, $quantity = 1)
Proposed resolution
StockAvailabilityChecker - implements AvailabilityCheckerInterface so can be added to the AvailabilityManager however we have the following points to consider:
1) The StockAvailabilityChecker itself has dependency injection for the EntityStockCheckInterface
2) Should we override the AvailabilityManager to make sure only stock can check if installed? - probably not.
3) The plan is to support more then one instance of EntityStockCheckInterface (probably configured by product type).
We have two options:
a) add one checker - StockAvailabilityChecker acts as a factory for EntityStockCheckInterface determined by the type of the PurchasableEntityInterface passed in.
b) create a AvailabilityCheckerInterface instance for each EntityStockCheckInterface and add those to the AvailabilityManager. Each of those will need to check the PurchasableEntityInterface to find out if it needs to run its own check.
Remaining tasks
implement StockAvailabilityChecker.create stock services interface & implement AlwaysInStockService.- implement Commerce Stock Storage sub module.
- implement the availability_manager in commerce
- UI and code to determine the stock services tot use
Comment | File | Size | Author |
---|---|---|---|
#5 | intrface_with-2709939-5.patch | 924 bytes | Sut3kh |
Comments
Comment #2
guy_schneerson CreditAttribution: guy_schneerson commented#2710763: Create StockManager service implanted the StockAvailabilityChecker & AvailabilityCheckerInterface
The StockAvailabilityChecker is a commerce.availability_checker service
It uses the StockManager is a service_collector that collects commerce.stock_service
A commerce.stock_service holds a Stock checker a stock updater & stock configuration.
A always_in_stock_service a commerce.stock_service - was added and will now be triggered by calling the commerce availability manager:
All that is left is to
Comment #3
guy_schneerson CreditAttribution: guy_schneerson commentedComment #5
Sut3kh CreditAttribution: Sut3kh as a volunteer commentedNot sure if you want this here or as a separate issue but with the latest Drupal Commerce this throws:
It seems that #2803221: Create context value object for price resolvers and availability checkers has added '$context' to handle checks to retrospective order changes i.e. if the price was date based.
I can't see that time, customer or store are factors in the stock check so I have worked under the assumption they aren't, however this is literally my first foray into d8 commerce & commerce_stock (this patch is at least just to allow me to get it up and running!) so input is more than welcome :)
Comment #7
guy_schneerson CreditAttribution: guy_schneerson commentedThanks @Sut3kh that's a super useful patch and explanation.
Your patch does exactly what was needed. Not sure yet how we will use the $context and I suspect the AvailabilityManager will have to go through a few other changes. It currently stops a user from adding out of stock items but the add to cart function is not aware of that so you will get the "product added" msg. @steveoliver from the linked issue is also helping on the project so will probably be able to help.
Ideally this would have been a separate bug with a link to this issue but no big deal, main thing is you fixed it :)
Comment #8
steveoliver CreditAttribution: steveoliver at Circatree commentedI believe the StockAvailabilityChecker works as expected now.
Comment #9
steveoliver CreditAttribution: steveoliver at Circatree commented