### Install Inventory Metapackage Source: https://github.com/magento/inventory/wiki/Metapackage-Installation-Guide Install the inventory-metapackage using Composer. This command symlinks all inventory modules into the vendor directory. ```bash composer require magento/inventory-metapackage ``` -------------------------------- ### Example Curl Command for Stock API Source: https://github.com/magento/inventory/wiki/How-to-create-Web-API-and-How-To-cover-them-with-Functional-Testing Illustrates how to call the 'get' method for a specific stock item using a curl command. The framework parses the URL to extract arguments for the service method. ```bash $curl http://127.0.0.1/index.php/rest/V1/inventory/stock/42 ``` -------------------------------- ### PHP Example: Single Stock and Sales Channel Link Source: https://github.com/magento/inventory/wiki/Sources-to-Sales-Channels-Mapping Illustrates a concrete example of the interfaces, showing how a single stock is linked to a source and a sales channel. ```php interface Stock { public function getStockId(); // 1 public function getStockName(); // "Single Stock" } interface SourceStockLink { public function getStockId(); // 1 public function getSourceId(); // 1 } interface SalesChannel { public function getEntityId(); // 1 public function getSalesChannelId(); // website_id - 1 public function getType(); // "WEBSITE" } interface StockSalesChannelLink { public function getStockId(); // 1 public function getSalesChannelEntityId(); // 1 } ``` -------------------------------- ### Install Composer Dependencies Source: https://github.com/magento/inventory/wiki/Getting-Started-with-MFTF Install all project dependencies required by the MSI acceptance tests using Composer. ```shell composer install ``` -------------------------------- ### Store Can Manage Stock on Stock Scope Example Source: https://github.com/magento/inventory/wiki/Inventory-configuration-Design-and-DB-structure Example row in the inventory_configuration table for 'can_manage_stock' configuration at the Stock level. SKU is null, and Stock ID and value are provided. ```text null | null | Stock-1 | can_manage_stock | 0 ``` -------------------------------- ### Install MSI 1.1.2-beta with Magento 2.3.1 Source: https://github.com/magento/inventory/wiki/MSI-Release-Notes-and-Installation Use this command sequence to install the MSI 1.1.2-beta version on Magento 2.3.1. It involves setting the minimum stability to beta, preferring stable packages, and specifying the exact package version with an alias to override existing constraints. ```shell composer config minimum-stability beta composer config prefer-stable true composer require --no-update "magento/inventory-composer-metapackage:1.1.2-beta2 as 1.1.1" composer update ``` -------------------------------- ### Basic cURL Request Example Source: https://github.com/magento/inventory/wiki/Before-you-begin-[Web-API-Tutorial] This cURL command demonstrates a basic GET request to retrieve country data. It includes placeholders for the host and authorization token, and uses `json_pp` for pretty-printing and `grep` for filtering the output. ```shell endpoint="http:///rest" curl -X GET "$endpoint/V1/directory/countries" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $admin_token" | json_pp | grep -in -B3 -A3 "United States" ``` -------------------------------- ### Store Can Manage Stock on Stock Item Scope Example Source: https://github.com/magento/inventory/wiki/Inventory-configuration-Design-and-DB-structure Example row in the inventory_configuration table for 'can_manage_stock' configuration at the Stock Item level. Includes SKU, Stock ID, and the value. ```text SKU-1 | null | Stock-1 | can_manage_stock | 0 ``` -------------------------------- ### Install MSI 1.1.2-beta with Magento 2.3.0 Source: https://github.com/magento/inventory/wiki/MSI-Release-Notes-and-Installation Use this command sequence to install the MSI 1.1.2-beta version on Magento 2.3.0. It requires setting the minimum stability to beta, preferring stable packages, and then requiring the specific beta package version. ```shell composer config minimum-stability beta composer config prefer-stable true composer require --no-update "magento/inventory-composer-metapackage:1.1.2-beta2" composer update ``` -------------------------------- ### Start Asynchronous Queue Consumer Source: https://github.com/magento/inventory/wiki/MSI-Global-Settings Enable asynchronous operations for legacy stock alignment and admin bulk operations by starting the queue consumer. This command is required for these features to run in the background. ```bash bin/magento queue:consumer:start async.operations.all ``` -------------------------------- ### Store Backorders on Source Scope Example Source: https://github.com/magento/inventory/wiki/Inventory-configuration-Design-and-DB-structure Example row in the inventory_configuration table showing 'backorders' stored at the Source level. SKU is null, and Source Code and value are provided. ```text null | Source-A | null | backorders | 1 ``` -------------------------------- ### Store Backorders on Source Item Scope Example Source: https://github.com/magento/inventory/wiki/Inventory-configuration-Design-and-DB-structure Example row in the inventory_configuration table demonstrating how 'backorders' is stored at the Source Item level. Includes SKU, Source Code, and the value. ```text SKU-1 | Source-A | null | backorders | 1 ``` -------------------------------- ### Add MSI Composer Metapackage Source: https://github.com/magento/inventory/wiki/MSI-Release-Notes-and-Installation Include this line in your composer.json to install the MSI metapackage. ```json magento/inventory-composer-metapackage = ^1.0.2 ``` -------------------------------- ### Bulk Inventory Transfer Example in PHP Source: https://context7.com/magento/inventory/llms.txt Demonstrates how to use BulkInventoryTransferInterface and BulkPartialInventoryTransferInterface to move inventory between sources. Use consolidateWarehouse to move all inventory for given SKUs and rebalanceStock for partial transfers. ```php use Magento\InventoryCatalogApi\Api\BulkInventoryTransferInterface; use Magento\InventoryCatalogApi\Api\BulkPartialInventoryTransferInterface; use Magento\InventoryCatalogApi\Api\Data\PartialInventoryTransferItemInterfaceFactory; class InventoryTransferExample { public function __construct( private readonly BulkInventoryTransferInterface $bulkTransfer, private readonly BulkPartialInventoryTransferInterface $partialTransfer, private readonly PartialInventoryTransferItemInterfaceFactory $transferItemFactory ) {} public function consolidateWarehouse(array $skus): bool { // Move all inventory for given SKUs from east to west; keep east assignment return $this->bulkTransfer->execute( skus: $skus, originSource: 'warehouse_east', destinationSource: 'warehouse_west', unassignFromOrigin: false ); // Returns true on full success, false if any SKU failed } public function rebalanceStock(): void { $items = []; foreach (['MH01-XS-Black' => 20.0, 'MH01-S-Blue' => 15.0] as $sku => $qty) { $item = $this->transferItemFactory->create(); $item->setSku($sku); $item->setQty($qty); $items[] = $item; } $this->partialTransfer->execute( originSourceCode: 'warehouse_west', destinationSourceCode: 'warehouse_east', items: $items ); // Void. Throws ValidationException if origin lacks sufficient qty. } } ``` -------------------------------- ### Get Safety Quantity Interface Source: https://github.com/magento/inventory/wiki/Stock-and-Source-Configuration-design Gets the safety stock value on the level of Product in Stock (StockItem). ```APIDOC ## GetSafetyQuantityInterface ### Description Retrieves the safety stock quantity for a specific product within a stock. ### Method `execute(string $sku, int $stockId): float` ``` -------------------------------- ### Create downloadable product with links and samples Source: https://github.com/magento/inventory/wiki/Create-a-downloadable-product-[Web-API-Tutorial] This comprehensive cURL command creates a downloadable product. It includes base64 encoded file content for links and samples, product details, and custom attributes. ```bash wget https://magento.com/sites/all/themes/mag_redesign/images/magento-adobe-logo.svg base64_encode() { php -r 'print(base64_encode(file_get_contents($argv[1])));' $1; } file_data=$(base64_encode $PWD/magento-adobe-logo.svg) file_data=${file_data////\/} echo $file_data curl -X POST "$endpoint/test/V1/products" -H "Content-Type: application/json" -H "Authorization: Bearer $admin_token" -d '{"product":{"sku":"sku-test-product-downloadable3","name":"sku-test-product-downloadable3","type_id":"downloadable","price":10,"attribute_set_id":10,"extension_attributes":{"category_links":[{"position":0,"category_id":"7"}],"downloadable_product_links":[{"title":"link1","sort_order":10,"is_shareable":1,"price":2,"number_of_downloads":0,"link_type":"file","link_file_content":{"name":"link1_content.svg","file_data":"'"$file_data"'"},"sample_type":"file","sample_file_content":{"name":"link1_sample.svg","file_data":"'"$file_data"'"}},{"title":"link2","sort_order":20,"is_shareable":0,"price":3,"number_of_downloads":100,"link_type":"url","link_url":"http://www.example.com/link2.jpg","sample_type":"url","sample_url":"http://www.example.com/link2.jpg"}],"downloadable_product_samples":[{"title":"sample1","sort_order":10,"sample_type":"url","sample_url":"http://www.example.com/sample1.jpg"},{"title":"sample2","sort_order":20,"sample_type":"file","sample_file_content":{"name":"sample2.svg","file_data":"'"$file_data"'"}}]},"custom_attributes": [ {"attribute_code":"format","value":"9"},{"attribute_code":"activity","value":"14,16,17"}]}}' ``` -------------------------------- ### Create Simple Product via cURL Source: https://github.com/magento/inventory/wiki/Create-a-simple-product-[Web-API-Tutorial] This cURL command creates a simple product with SKU 'Simple Running Backpack'. It includes details like price, weight, stock quantity, and category association. Ensure the endpoint and token are correctly set. ```bash backpacks_category_id="3"; simple_product_SKU="Simple Running Backpack"; test_website_id="2" && curl -X POST "$endpoint/test/V1/products" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $admin_token" \ -d '{"product":{"sku":"' ``` ```bash '$simple_product_SKU'","name":"' ``` ```bash '$simple_product_SKU'","attribute_set_id":4,"price":70,"status":1,"visibility":4,"type_id":"simple","weight":0.8,"extension_attributes":{"website_ids":["' ``` ```bash '$test_website_id"],"category_links":[{"position":0,"category_id":"' ``` ```bash '$backpacks_category_id"}],"stock_item":{"qty":250,"is_in_stock":true,"is_qty_decimal":false}}}}' | json_pp ``` -------------------------------- ### Get Safety Quantity Global Value Interface Source: https://github.com/magento/inventory/wiki/Stock-and-Source-Configuration-design Gets the safety stock global value for all Products assigned to a Stock by Default. ```APIDOC ## GetSafetyQuantityGlobalValueInterface ### Description Retrieves the global safety stock quantity for a specified stock. ### Method `execute(int $stockId): float` ``` -------------------------------- ### HTTP Headers for Product Creation Source: https://github.com/magento/inventory/wiki/Create-a-configurable-product-[Web-API-Tutorial] Use these headers for all product creation requests. Ensure you replace `` with a valid administrator token. ```http Content-Type: application/json Authorization: Bearer ``` -------------------------------- ### GraphQL Pickup Locations Response Example Source: https://github.com/magento/inventory/wiki/In-Store-Pickup-API-Tutorials Example JSON response structure for the `pickupLocations` GraphQL query, detailing the information returned for each pickup location. ```json { "data": { "pickupLocations": { "items": [ { "pickup_location_code": "txspeqs", "name": "Sport Equipment Store", "email": "sales@company.com", "fax": null, "description": "Sport Equipment Store description", "latitude": 29.7543, "longitude": -95.3609, "country_id": "US", "region_id": 57, "region": "Texas", "city": "Houston", "street": "4631 Airport Blvd #125", "postcode": "77010", "phone": "(555) 555-5555" } ], "total_count": 1, "page_info": { "page_size": 1, "current_page": 1, "total_pages": 1 } } } } ``` -------------------------------- ### Example Stock API Route for Curl Source: https://github.com/magento/inventory/wiki/How-to-create-Web-API-and-How-To-cover-them-with-Functional-Testing Shows the specific Web API route configuration that corresponds to the example curl command for retrieving stock information. ```xml ``` -------------------------------- ### Complete cURL Request for Product Creation (V1) Source: https://github.com/magento/inventory/wiki/Create-a-configurable-product-[Web-API-Tutorial] Example cURL request for creating the first product variation. This demonstrates how to send the JSON payload with necessary headers to the API endpoint. ```bash configurable_product_SKU_V1="Swim Warm-Up Hoodie - S" && curl -X POST "$endpoint/test/V1/products" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $admin_token" \ -d '{"product":{"sku":""$configurable_product_SKU_V1"","name":""$configurable_product_SKU_V1"","attribute_set_id":9,"price":90,"status":1,"visibility":1,"type_id":"simple","weight":"0.6","extension_attributes":{"stock_item":{"qty":"70","is_in_stock":true}},"custom_attributes":[{"attribute_code":"size","value":"4"}]}}' | json_pp ``` -------------------------------- ### Complete cURL Request for Product Creation (V2) Source: https://github.com/magento/inventory/wiki/Create-a-configurable-product-[Web-API-Tutorial] Example cURL request for creating the second product variation. Note the updated `sku`, `name`, `weight`, `qty`, and `value` for the size attribute. ```bash configurable_product_SKU_V2="Swim Warm-Up Hoodie - M" && curl -X POST "$endpoint/test/V1/products" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $admin_token" \ -d '{"product":{"sku":""$configurable_product_SKU_V2"","name":""$configurable_product_SKU_V2"","attribute_set_id":9,"price":90,"status":1,"visibility":1,"type_id":"simple","weight":"0.72","extension_attributes":{"stock_item":{"qty":"80","is_in_stock":true}},"custom_attributes":[{"attribute_code":"size","value":"5"}]}}' | json_pp ``` -------------------------------- ### Get attributeGroupId using Web API Source: https://github.com/magento/inventory/wiki/Data-preparation-before-assigning-attribute-to-an-attribute-set-[Web-API-Tutorial] Use this GET request to retrieve the attribute group ID based on attribute set ID and attribute group name. Ensure you have the correct host and authorization token. ```shell curl -X GET "$endpoint/all/V1/products/attribute-sets/groups/list?searchCriteria%5BfilterGroups%5D%5B0%5D%5Bfilters%5D%5B0%5D%5Bfield%5D=attribute_set_id&searchCriteria%5BfilterGroups%5D%5B0%5D%5Bfilters%5D%5B0%5D%5Bvalue%5D=9&searchCriteria%5BfilterGroups%5D%5B0%5D%5Bfilters%5D%5B0%5D%5BconditionType%5D=eq&searchCriteria%5BfilterGroups%5D%5B0%5D%5Bfilters%5D%5B1%5D%5Bfield%5D=attribute_group_name&searchCriteria%5BfilterGroups%5D%5B0%5D%5Bfilters%5D%5B1%5D%5Bvalue%5D=Product%20Details&searchCriteria%5BfilterGroups%5D%5B0%5D%5Bfilters%5D%5B1%5D%5BconditionType%5D=eq&searchCriteria%5BpageSize%5D=50&searchCriteria%5BcurrentPage%5D=1" -H "accept: application/json" -H "Authorization: Bearer $admin_token" | json_pp ``` -------------------------------- ### Search Pickup Locations Request Parameters Source: https://github.com/magento/inventory/wiki/In-Store-Pickup-API-Tutorials This example demonstrates how to construct a search request for pickup locations. You can filter by area, product SKU, and scope. ```http searchRequest[area][radius]: 1500 searchRequest[area][searchTerm]: Austin searchRequest[scopeCode]: base searchRequest[extensionAttributes][productsInfo][0][sku]: SKU1 ``` -------------------------------- ### Building and Appending Reservations Source: https://github.com/magento/inventory/wiki/Salable-Quantity-Calculation-and-Mechanism-of-Reservations Demonstrates how to use the `reservationBuilder` to create new reservation entities with specified SKU, quantity, stock ID, and metadata. The built reservations are then appended using an `execute` method. ```php $reservations[] = $this->reservationBuilder ->setSku($item->getSku()) ->setQuantity((float)$item->getQuantity()) ->setStockId($stockId) ->setMetadata($this->serializer->serialize($this->salesEventToArrayConverter->execute($salesEvent))) ->build(); $reservationAppend->execute($reservations); ```