ãã®èšäºã§ã¯ãMagento 2ã®ãµãŒãã¹ã¬ã€ã€ãŒãšããšã³ãã£ãã£ã管çããããã®ãµãŒãã¹ïŒAPIïŒã«ã€ããŠèª¬æããŸãããããã¯ãå庫管çã·ã¹ãã ïŒã€ã³ãã³ããªïŒã®ãã¡ã€ã³ãšã³ãã£ãã£ã®èšèšãšå²ãåœãŠã«é¢ãã以åã®èšäºã§èª¬æããŸããã
ãµãŒãã¹å±€
Magento 2ãã©ãããã©ãŒã ã§å庫管çã·ã¹ãã ãèšè¿°ããŠãããããããã«å¿ããŠããã®ãã©ãããã©ãŒã ã®æ©èœãèæ ®ããŠã玹ä»ãããµãŒãã¹ã«ã€ããŠèª¬æããŸãã
Magento 2ã§ã¯ãã¢ãžã¥ãŒã«ã¬ãã«ïŒããŠã³ãã³ã³ããã¹ãå ïŒã§åŒ±ãæ¥ç¶ã®ååãå®è£ ããããã«ããµãŒãã¹ã¬ã€ã€ãŒãå°å ¥ãããŸãããããã¯ãã¯ã©ã€ã¢ã³ããšä»ã®ã·ã¹ãã ã¢ãžã¥ãŒã«ã®çžäºäœçšã«é¢ããŠåã¢ãžã¥ãŒã«ã§å©çšå¯èœãªæäœã®ã»ãããå®çŸ©ããŸãã
Magentoã®ãµãŒãã¹ã¬ã€ã€ãŒïŒãŸãã¯ãµãŒãã¹ã³ã³ãã©ã¯ãïŒã¯ ãã¢ãžã¥ãŒã«ã«å¯ŸããŠå®çŸ©ããããã®ã¢ãžã¥ãŒã«ã®Apiãã©ã«ããŒã«ããPHPã€ã³ã¿ãŒãã§ã€ã¹ã®ã»ããã§ãã ãµãŒãã¹ã³ã³ãã©ã¯ãã¯ãããŒã¿ã€ã³ã¿ãŒãã§ãŒã¹-ãã¡ã€ã³ãšã³ãã£ãã£ããŒã¿ãè¡šãDTOã€ã³ã¿ãŒãã§ãŒã¹ã§æ§æãããŠããŸãã ããã³ãµãŒãã¹ã€ã³ã¿ãŒãã§ã€ã¹-ã¯ã©ã€ã¢ã³ãïŒã³ã³ãããŒã©ãŒãREST / SOAP WebãµãŒãã¹ãä»ã®ã¢ãžã¥ãŒã«ã®PHPã³ãŒãïŒããåŒã³åºãããšãã§ããããžãã¹ããžãã¯ãžã®ã¢ã¯ã»ã¹ãæäŸããã€ã³ã¿ãŒãã§ã€ã¹ã
ã¢ãžã¥ãŒã«ã®ãã¹ãŠã®å€éšã¯ã©ã€ã¢ã³ãã¯ããµãŒãã¹å±€ã§èšè¿°ãããå¥çŽã®äžã§åäœãããšæ³å®ãããŠããããããµãŒãã¹å±€ã¯å®éã«ã¯FacadeãšããŠè¡šãããšãã§ããå®è£ ã®è©³çŽ°ãšããžãã¹ããžãã¯ã®è€éããé ããŸãã
ã客æ§ã¯ãæ確ã«å®çŸ©ãããAPIã«äŸåããããšã§ãã¢ãžã¥ãŒã«ãã»ãã³ãã£ãã¯ããŒãžã§ãã³ã°ã«åŸããããã·ã¹ãã ã®æ¬¡ã®ããŒãžã§ã³ãžã®ã¢ããã°ã¬ãŒãã容æã«ãªããŸãã
ã¢ãžã¥ãŒã«æ§ãšåé¢ãæ¹åããããã«ããµãŒãã¹ã³ã³ãã©ã¯ãããµãŒãã¹ããå¥ã®ã¢ãžã¥ãŒã«ã«å²ãåœãŠãããå ŽåããããŸãã ããšãã°ãInventoryã®å Žåã2ã€ã®ã¢ãžã¥ãŒã«ããããŸãã1ã€ã¯InventoryAPIãµãŒãã¹ã€ã³ã¿ãŒãã§ã€ã¹ã®ã»ããã宣èšãã2ã€ç®ã¯ãããã®ã€ã³ã¿ãŒãã§ã€ã¹ã®å®è£ ãæäŸããŸã-Inventoryã§ãã ãããã£ãŠãåºæ¬å®è£ ã眮ãæããããµãŒãããŒãã£ã®éçºè ã¯ãã³ãŒãå ã§ãã®å®è£ ã«çžãããªããªããŸãã ã·ã¹ãã å ã®ä»ã®ã¢ãžã¥ãŒã«ãäŸåããã€ã³ã¿ãŒãã§ã€ã¹ã§ããããã圌ãå¿ èŠãšããã®ã¯ã€ã³ã¿ãŒãã§ã€ã¹ã ãã§ãã
ãªããžããªã€ã³ã¿ãŒãã§ã€ã¹-ãªããžããª
ãªããžããªã¯ããšã³ãã£ãã£ã«äžé£ã®CRUDæäœãæäŸããã€ã³ã¿ãŒãã§ã€ã¹ã§ãã
å žåçãªãªããžããªã€ã³ã¿ãŒãã§ã€ã¹ã¯ã次ã®ã¡ãœããã®ã»ããã§æ§æãããŠããŸãã
public function save(\Magento\Module\Api\Data\DataInterface $entityData); public function get($entityId); public function delete(\Magento\Module\Api\Data\DataInterface $entityData); public function deleteById($entityId); public function getList(SearchCriteriaInterface $searchCriteria);
ã¡ãœããã®ã»ããã¯ãå®çŸ©æžã¿ã®ã»ãããšã¯ç°ãªãã»ãã³ãã£ã¯ã¹ãæã€ã¡ãœãããè¿œå ããããšã¯æšå¥šãããªããããããçãå ŽåããããŸãïŒç¹å®ã®æäœããã¡ã€ã³ãšã³ãã£ãã£ã«äžè¬çã§ãªãå Žåãåé€ãªã©ïŒã ãã®ãããªæ¹æ³ã¯ãå¥ã®ãµãŒãã¹ã«é 眮ããããšããå§ãããŸãã
ãªããžããªã¯ããšã³ãã£ãã£ã管çããããã®äžé£ã®ã¡ãœãããçµã¿åããããã¡ãµãŒããšèããããšãã§ããŸãã
Inventoryã¢ãžã¥ãŒã«ã®ã³ã³ããã¹ãã§ã¯ã Sourceãšã³ãã£ãã£ïŒè£œåãããç©ççãªå庫ãè¡šã責任ãè² ããšã³ãã£ãã£ïŒããã³SourceItem ïŒãšã³ãã£ãã£ãã³ãã«ãç¹å®ã®ç©çã¹ãã¬ãŒãžäžã®ç¹å®ã®è£œåïŒSKUïŒã®éãè¡šãïŒã®ãªããžããªã衚瀺ãããŸãã
/** * This is Facade for basic operations with Source * There is no delete method, as Source can't be deleted from the system because we want to keep Order information for all orders placed. Sources can be disabled instead. * * Used fully qualified namespaces in annotations for proper work of WebApi request parser * * @api */ interface SourceRepositoryInterface { /** * Save Source data * * @param \Magento\InventoryApi\Api\Data\SourceInterface $source * @return int * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function save(SourceInterface $source); /** * Get Source data by given sourceId. If you want to create plugin on get method, also you need to create separate * plugin on getList method, because entity loading way is different for these methods * * @param int $sourceId * @return \Magento\InventoryApi\Api\Data\SourceInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function get($sourceId); /** * Load Source data collection by given search criteria * * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return \Magento\InventoryApi\Api\Data\SourceSearchResultsInterface */ public function getList(SearchCriteriaInterface $searchCriteria = null); }
SourceRepositoryã®å Žåãdeleteã¡ãœããã¯ãããŸãããSourceãšã³ãã£ãã£ã«å¯Ÿããããžãã¹ãªãã¬ãŒã·ã§ã³ã¯ååšããªãããã§ãããªããªããçºæ³šããã泚æïŒååã®é éå ãå«ãïŒã«é¢é£ãããã¹ãŠã®æ å ±ãåžžã«ä¿åããå¿ èŠãããããã§ãã ãããã£ãŠãå°æ¥çã«ãã®ãããªããŒã¿ã倱ãããå¯èœæ§ãé²ãå¿ èŠããããŸãïŒé ä¿¡ãå®è¡ããããœãŒã¹ãåé€ããããšã«ããïŒã 代ããã«ãæäœã䜿çšãããŸã-ãœãŒã¹ãéã¢ã¯ãã£ãïŒç¡å¹ïŒãšããŠããŒã¯ããŸãã
/** * This is Facade for basic operations with SourceItem * * The method save is absent, due to different semantic (save multiple) * @see SourceItemSaveInterface * * There is no get method because SourceItem identifies by compound identifier (sku and source_id), * thus, it's needed to use getList() method * * Used fully qualified namespaces in annotations for proper work of WebApi request parser * * @api */ interface SourceItemRepositoryInterface { /** * Load Source Item data collection by given search criteria * * We need to have this method for direct work with Source Items, as Source Item contains * additional data like qty, status (can be searchable by additional field) * * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return \Magento\InventoryApi\Api\Data\SourceItemSearchResultsInterface */ public function getList(SearchCriteriaInterface $searchCriteria); /** * Delete Source Item data * * @param SourceItemInterface $sourceItem * @return void * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\CouldNotDeleteException */ public function delete(SourceItemInterface $sourceItem); }
ä¿åæäœã䜿çšããããã®äž»ãªã·ããªãªã¯ããªããžããªå ã®æšæºçãªä¿åèŠçŽãæ³å®ããŠããããã«ã1ã€ã®ãšã³ãã£ãã£ã§ã¯ãªãSourceItemã®ã»ããã§çºçããããã§ãã
ã·ã³ã¯ã®ã€ã³ããŒããŸãã¯å€éšERPãŸãã¯PIMã·ã¹ãã ãšã®åæäžã«çºçããå¯èœæ§ã®ããè€æ°ã®ä¿åã«ã€ããŠã¯ãåå¥ã®SourceItemSaveInterfaceã³ã³ãã©ã¯ããå°å ¥ãããåäžã®ãµãŒãã¹ã³ãŒã«å ã§è€æ°ã®SourceItemãã¢ãããã¯ã«ä¿åããæ©èœãæäŸããŸãã ãã®ãããªã³ã³ãã©ã¯ãã«ãããããŒã¿ããŒã¹ãžã®åäžã®ã¯ãšãªã䜿çšããŠæ¿å ¥æäœãåŠçã§ããåŠçãå€§å¹ ã«é«éåãããŸãã åäžã®ãšã³ãã£ãã£ã䜿çšããåºæ¬çãªä¿åæäœã¯ãå®éã«ã¯ãã®å ŽåãµãŒãããŒãã£ã®éçºè ãäž¡æ¹ã®ä¿åæäœïŒåäžããã³è€æ°ïŒããã©ã°ã€ã³ããå¿ èŠãããããããªããžããªã³ã³ãã©ã¯ãã«è¿œå ãããŸããã ãããã£ãŠã1ã€ã®æ¡åŒµãã€ã³ãã®ã«ã¹ã¿ãã€ãºãåžžã«æãŸããããã§ãã
è€æ°ã®ä¿åã³ãã³ãã³ã³ãã©ã¯ãã¯ã Magento \ InventoryApi \ Api \ SourceItemSaveInterfaceã®ããã«ãªããŸã
/** * Service method for source items save multiple * Performance efficient API, used for stock synchronization * * Used fully qualified namespaces in annotations for proper work of WebApi request parser * * @api */ interface SourceItemSaveInterface { /** * Save Multiple Source item data * * @param \Magento\InventoryApi\Api\Data\SourceItemInterface[] $sourceItems * @return void * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function execute(array $sourceItems); }
ãã®å®è£ ã§ããSourceItemSaveã¯ã SaveMultipleã¢ãã«ãªãœãŒã¹ã®ä¿åãå§ä»»ããŸãã
ãŸããSourceItemã¯ãªã³ã¯ããããšã³ãã£ãã£ã§ãããè€åèå¥åïŒSKUãšSourceIdïŒã«ãã£ãŠæ±ºå®ããããããSourceItemRepositoryã«ã¯getïŒïŒã¡ãœããã¯ãããŸããã
StockïŒãœãŒã¹ãšã³ãã£ãã£ã®ä»®æ³éçŽïŒã®ãªããžããªã¯æšæºã«èŠããŸãïŒ
interface StockRepositoryInterface { /** * Save Stock data * * @param \Magento\InventoryApi\Api\Data\StockInterface $stock * @return int * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function save(StockInterface $stock); /** * Get Stock data by given stockId. If you want to create plugin on get method, also you need to create separate * plugin on getList method, because entity loading way is different for these methods * * @param int $stockId * @return \Magento\InventoryApi\Api\Data\StockInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function get($stockId); /** * Find Stocks by given SearchCriteria * * @param \Magento\Framework\Api\SearchCriteriaInterface|null $searchCriteria * @return \Magento\InventoryApi\Api\Data\StockSearchResultsInterface */ public function getList(SearchCriteriaInterface $searchCriteria = null); /** * Delete the Stock data by stockId. If stock is not found do nothing * * @param int $stockId * @return void * @throws \Magento\Framework\Exception\CouldNotDeleteException */ public function deleteById($stockId); }
ãœãŒã¹ãšã¹ããã¯ããããã³ã°ããããã®ãµãŒãã¹
ã¯ã©ã€ã¢ã³ãAPIïŒããžãã¹ããžãã¯ã³ãŒãå ïŒã®ãã€ã©ãŒãã¬ãŒãã³ãŒãã®æ°ãæžããããã«ãã ã¯ã©ã€ã¢ã³ãã«ã§ããããšãäœããããªã ããšããã«ãŒã«ã«åŸã£ãŠãããŒã¿ã€ã³ã¿ãŒãã§ãŒã¹SourceStockLinkInterfaceãå°å ¥ããŸãã ã 代ããã«ãSourceãStockã«å²ãåœãŠãããã®äžé£ã®ãã¡ã€ã³ããŒã¹ã®ãµãŒãã¹ã³ãã³ããå°å ¥ããŸãã
ãã®çµæã3ã€ã®ã³ãã³ããååŸãããŸãã
interface AssignSourcesToStockInterface { /** * Assign list of source ids to stock * * @param int $stockId * @param int[] $sourceIds * @return void * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function execute(array $sourceIds, $stockId); } interface GetAssignedSourcesForStockInterface { /** * Get Sources assigned to Stock * * @param int $stockId * @return \Magento\InventoryApi\Api\Data\SourceInterface[] * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\LocalizedException */ public function execute($stockId); } interface UnassignSourceFromStockInterface { /** * Unassign source from stock * * @param int $sourceId * @param int $stockId * @return void * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\CouldNotDeleteException */ public function execute($sourceId, $stockId); }
API vs SPI
ãã®ãããžã§ã¯ãã®ãã¬ãŒã ã¯ãŒã¯å ã§ãæ¡åŒµæ©èœãæ¹åããã³ã³ããŒãã³ãã®æ¥ç¶æ§ãæžããããã«ã ãµãŒãã¹ãããã€ããŒã€ã³ã¿ãŒãã§ã€ã¹ ïŒSPIïŒããAPIïŒã¢ããªã±ãŒã·ã§ã³ããã°ã©ãã³ã°ã€ã³ã¿ãŒãã§ã€ã¹ïŒãæ瀺çã«åé¢ããããšã決å®ãããŸããã
- ãªããžããªã¯APIãšèŠãªãããšãã§ããããããªããžããªã€ã³ã¿ãŒãã§ãŒã¹ã®ã¡ãœããã¯ããžãã¹ããžãã¯ã®PHPã³ãŒãã§åŒã³åºããããšæ³å®ãããŠããŸãã
- ãªããžããªå®è£ ã¯ã©ã¹ãã¡ãœããããããã·ããåå¥ã®ã³ãã³ãã¯ã©ã¹ïŒGetãSaveãGetListãDeleteãªã©ïŒã¯ãçŸåšã®ã·ã¹ãã åäœãæ¡åŒµãŸãã¯çœ®æããããã«ãµãŒãããŒãã£ã®å®è£ ãæäŸã§ããSPIã€ã³ã¿ãŒãã§ã€ã¹ãšèŠãªãããšãã§ããŸãã
ãããã£ãŠãããšãã°ã Magento \ Inventory \ Model \ StockRepositoryãªããžããªã®å®è£ ã¯æ¬¡ã®ãšããã§ãã
/** * @inheritdoc */ class StockRepository implements StockRepositoryInterface { /** * @var SaveInterface */ private $commandSave; /** * @var GetInterface */ private $commandGet; /** * @var DeleteByIdInterface */ private $commandDeleteById; /** * @var GetListInterface */ private $commandGetList; /** * @param SaveInterface $commandSave * @param GetInterface $commandGet * @param DeleteByIdInterface $commandDeleteById * @param GetListInterface $commandGetList */ public function __construct( SaveInterface $commandSave, GetInterface $commandGet, DeleteByIdInterface $commandDeleteById, GetListInterface $commandGetList ) { $this->commandSave = $commandSave; $this->commandGet = $commandGet; $this->commandDeleteById = $commandDeleteById; $this->commandGetList = $commandGetList; } /** * @inheritdoc */ public function save(StockInterface $stock) { $this->commandSave->execute($stock); } /** * @inheritdoc */ public function get($stockId) { return $this->commandGet->execute($stockId); } /** * @inheritdoc */ public function deleteById($stockId) { $this->commandDeleteById->execute($stockId); } /** * @inheritdoc */ public function getList(SearchCriteriaInterface $searchCriteria = null) { return $this->commandGetList->execute($searchCriteria); } }
ã³ã³ã¹ãã©ã¯ã¿ãŒã¯ãæäŸãããåæäœã«å¯ŸããŠäžé£ã®ã³ãã³ãã€ã³ã¿ãŒãã§ã€ã¹ãåãå ¥ããŸãã ãããŠããªããžããªããã®ãããªãã¯ã¡ãœããã®åŒã³åºãäž-åŒã³åºãã¯é©åãªã³ãã³ãã«ãããã·ãããŸãã
SPIã³ãã³ãã€ã³ã¿ãŒãã§ã€ã¹ã¯æ¬¡ã®ãšããã§ãã
/** * Save Stock data command (Service Provider Interface - SPI) * * Separate command interface to which Repository proxies initial Save call, could be considered as SPI - Interfaces * so that you should extend and implement to customize current behaviour, but NOT expected to be used (called) in the code * of business logic directly * * @see \Magento\InventoryApi\Api\StockRepositoryInterface * @api */ interface SaveInterface { /** * Save Stock data * * @param StockInterface $stock * @return int * @throws CouldNotSaveException */ public function execute(StockInterface $stock); } /** * Get Stock by stockId command (Service Provider Interface - SPI) * * Separate command interface to which Repository proxies initial Get call, could be considered as SPI - Interfaces * that you should extend and implement to customize current behavior, but NOT expected to be used (called) in the code * of business logic directly * * @see \Magento\InventoryApi\Api\StockRepositoryInterface * @api */ interface GetInterface { /** * Get Stock data by given stockId * * @param int $stockId * @return StockInterface * @throws NoSuchEntityException */ public function execute($stockId); } /** * Delete Stock by stockId command (Service Provider Interface - SPI) * * Separate command interface to which Repository proxies initial Delete call, could be considered as SPI - Interfaces * that you should extend and implement to customize current behaviour, but NOT expected to be used (called) in the code * of business logic directly * * @see \Magento\InventoryApi\Api\StockRepositoryInterface * @api */ interface DeleteByIdInterface { /** * Delete the Stock data by stockId. If stock is not found do nothing * * @param int $stockId * @return void * @throws CouldNotDeleteException */ public function execute($stockId); } /** * Find Stocks by SearchCriteria command (Service Provider Interface - SPI) * * Separate command interface to which Repository proxies initial GetList call, could be considered as SPI - Interfaces * that you should extend and implement to customize current behaviour, but NOT expected to be used (called) in the code * of business logic directly * * @see \Magento\InventoryApi\Api\StockRepositoryInterface * @api */ interface GetListInterface { /** * Find Stocks by given SearchCriteria * * @param SearchCriteriaInterface|null $searchCriteria * @return StockSearchResultsInterface */ public function execute(SearchCriteriaInterface $searchCriteria = null); }
ãããã®ã³ãã³ãã¯ãã¢ãžã¥ãŒã«ã®SPIã€ã³ã¿ãŒãã§ãŒã¹ãè¡šããåå空éã®äžã«ãããŸãã
Magento\Inventory\Model\Stock\Command\*
ããŒã ã®å®è£ ã¯æ¬¡ã®ãšããã§ãïŒ Magento \ Inventory \ Model \ Stock \ Command \ * ïŒã ããšãã°ãã¹ããã¯ãä¿åããã³ãã³ãïŒ
/** * @inheritdoc */ class Save implements SaveInterface { /** * @var StockResourceModel */ private $stockResource; /** * @var LoggerInterface */ private $logger; /** * @param StockResourceModel $stockResource * @param LoggerInterface $logger */ public function __construct( StockResourceModel $stockResource, LoggerInterface $logger ) { $this->stockResource = $stockResource; $this->logger = $logger; } /** * @inheritdoc */ public function execute(StockInterface $stock) { try { $this->stockResource->save($stock); return $stock->getStockId(); } catch (\Exception $e) { $this->logger->error($e->getMessage()); throw new CouldNotSaveException(__('Could not save Stock'), $e); } } }
補åäºçŽã¡ã«ããºã
äºçŽãªããžã§ã¯ãã¯ã泚æã®äœæãšç¹å®ã®ç©ççãªå庫ã§ã®ååæ°ã®æžå°ã®éã«ã販売ããååã®çŸåšã®ã¬ãã«ãä¿æããããã«äœæãããŸãã
åã®ããŒãã§è©³ãã説æãããçºæ³šã®ããžãã¹ã·ããªãªã®å®è£ ã
åé·æ§ã®ããã®ããŒã¿ã€ã³ã¿ãŒãã§ã€ã¹ãå°å ¥
/** * The entity responsible for reservations, created to keep inventory amount (product quantity) up-to-date. * It is created to have a state between order creation and inventory deduction (deduction of specific SourceItems) * * @api */ interface ReservationInterface extends ExtensibleDataInterface { /** * Constants for keys of data array. Identical to the name of the getter in snake case */ const RESERVATION_ID = 'reservation_id'; const STOCK_ID = 'stock_id'; const SKU = 'sku'; const QUANTITY = 'quantity'; const STATUS = 'status'; /**#@+ * Reservation possible statuses. */ const STATUS_OPEN = 1; const STATUS_CLOSED = 2; /**#@-*/ /** * Get Reservation id * * @return int|null */ public function getReservationId(); /** * Get stock id * * @return int */ public function getStockId(); /** * Get Product SKU * * @return string */ public function getSku(); /** * Get Product Qty * * @return float */ public function getQuantity(); /** * Get Reservation Status * * @return int */ public function getStatus(); }
äºçŽã¯Append-Onlyäžå€ã®ãšã³ãã£ãã£ãšããŠèªèããããããReservationInterfaceã«ä¿®é£ŸåïŒã»ãã¿ãŒã¡ãœããïŒã¯å¿ èŠãããŸããã ãããã£ãŠãäºçŽãªããžã§ã¯ããäœæããã«ã¯ãReservationBuilderInterfaceãå¿ èŠã§ãã
$reservationBuilder->setStockId(1); $reservationBuilder->setSku('sku'); $reservationBuilder->setQty(10); $newReservation = $reservationBuilder->build(); //now we could save Reservation entity $reservationAppend->execute([$newReservation]);
ãªããžã§ã¯ãäºçŽãµãŒãã¹
äºçŽïŒäºçŽïŒãè¿œå ãããµãŒãã¹ã¯ã泚æã泚æã®åŠçããŸãã¯æ³šæã®ãã£ã³ã»ã«æã«äœ¿çšãããŸãã è¿åæäœã®äœæãšåŠçã ãã§ãªã ãã®æç¹ã§ãSKUããšã«1ã€ã®äºçŽããã¯ãäœæããããã®ãµãŒãã¹ã䜿çšããŠåŠçã®ããã«è¿œå ãããŸãã
/** * Command which appends reservations when order placed or canceled * * @api */ interface ReservationAppend { /** * Append reservations when Order Placed (or Cancelled) * * @param Reservation[] $reservations * @return void * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function execute(array $reservations); }
次ã®ãµãŒãã¹ã¯ã泚æã®éã«ã·ã¹ãã ãStockItemãšã³ãã£ãã£ïŒä»®æ³éèšïŒãåŠçãããããEvent Stockã®æ§è³ªã«èµ·å ããã¬ã€ãã³ã·ã§Quantity StockItemãæŽæ°ãããããã販売å¯èœãªååã®æ£ç¢ºãªæ°éïŒæ°éïŒãèšç®ããããã«äœ¿çšãããŸãã©ã®ç©çã¹ãã¢ïŒãœãŒã¹ïŒã®å»æ¢æªçœ®ãçºçãããã¯ããããŸããã ãããã£ãŠã泚æã®åŠçãšåŠçã®éã«äžå®ã®æéãçµéããå ŽåããããŸãã
/** * Command which returns Reservation Quantity by Product SKU and Stock * * @api */ interface GetReservationQuantityForProduct { /** * Get Reservation Quantity for given SKU in a given Stock * * @param string $sku * @param int $stockId * @return float */ public function execute($sku, $stockId); }
åäºçŽã¯ãéããç¶æ ãŸãã¯éããç¶æ ã«ããããšãã§ããŸãã
äºçŽã¯å€æŽã§ããªãäžå€ãªããžã§ã¯ãã§ããããã äºçŽã®ã¹ããŒã¿ã¹ãå€æŽãã代ããã«ã2çªç®ã®äºçŽãäœæããæåã®äºçŽããã£ã³ã»ã«ããŸãã
äŸãã°
30åã®ååã泚æãããšãäºçŽãäœæãããŸãã
ReservationID-1ãStockId-1ãSKU-SKU-1ãæ°é-ïŒ- 30 ïŒãã¹ããŒã¿ã¹-OPEN
ãã®æ³šæãåŠçããããå¥ã®äºçŽãäœæããŸã
ReservationID-2ãStockId-1ãSKU-SKU-1ãæ°é-ïŒ +30 ïŒãã¹ããŒã¿ã¹-éåº
åèšã§ãããã2ã€ã®ãªã¶ãŒãïŒ-30ïŒ+ïŒ+30ïŒ= 0ã¯ãStockItemã«æ ŒçŽãããŠããæ°éã«åœ±é¿ããŸããã
ããã§2ã€ã®ããšã«æ³šæããããšãéèŠã§ããäºçŽã¯ä»ã®ããžãã¹ãªãã¬ãŒã·ã§ã³ã«çµã³ä»ããããšãã§ãããããäºçŽãªããžã§ã¯ããšæ³šæïŒæ³šæïŒã®éã«ãã€ã³ãã£ã³ã°ïŒãã€ã³ãã£ã³ã°ïŒãå°å ¥ããŸããã å庫ïŒåšåº«ïŒã®èŠ³ç¹ããèŠããšãååãåºè·ããŠåšåº«ãæžããå¿ èŠããã泚æçªå·ã¯éèŠã§ã¯ãããŸããã
äºçŽã«è² ã®å€ãšæ£ã®å€ã䜿çšãããšãStockItemã«æ ŒçŽãããŠããæ°éããæžç®ããå¿ èŠãããåèšæ°ã®èšç®ãç°¡åã«ãªããŸãã
ããšãã°ã次ã®ã¯ãšãªã䜿çšããŸãã
select SUM(r.qty) as total_reservation_qty from Reservations as r where stockId = {%id%} and sku = {%sku%}
Magento MSIïŒãã«ããœãŒã¹ã€ã³ãã³ããªïŒ
ãã®èšäºã¯ããCQRSãšã€ãã³ããœãŒã·ã³ã°ã䜿çšããå庫管çã·ã¹ãã ãã·ãªãŒãºã®3çªç®ã®èšäºã§ãããMagento 2ã®äŸã䜿çšããå庫管çã·ã¹ãã ã®èŠä»¶ã®åéãèšèšãéçºã«ã€ããŠæ€èšããŸãã
éçºãé²è¡äžã§ãããã³ãã¥ããã£ãšã³ãžãã¢ãé¢äžããŠãããªãŒãã³ãããžã§ã¯ããããã³ãããžã§ã¯ããšããã¥ã¡ã³ãã®çŸåšã®ã¹ããŒã¿ã¹ã«ç²Ÿéããããšãã§ããå Žæã¯ã ããããå ¥æã§ããŸã ã
詳现ãªããã¥ã¡ã³ã
- MSIãµãŒãã¹å¥çŽ ïŒè±èªïŒ
- ãäºçŽ