.. rst-class:: outdated Basic Usage =========== .. danger:: We're sorry but **this documentation section is outdated**. Please have that in mind when trying to use it. You can help us making documentation up to date via Sylius Github. Thank you! Stockable Object ---------------- The first thing you should do it is implementing stockable object. Example implementation: .. code-block:: php getOnHand(); // Output will be 0. $inventoryOperator->increase($product, 5); $product->getOnHand(); // Output will be 5. $product->getOnHold(); // Output will be 0. $inventoryOperator->hold($product, 4); $product->getOnHold(); // Output will be 4. $inventoryOperator->release($product, 3); $product->getOnHold(); // Output will be 1. Decrease ~~~~~~~~ .. code-block:: php getOnHand(); // Output will be 5. $inventoryUnit1->setStockable($product); $inventoryUnit1->setInventoryState(InventoryUnitInterface::STATE_SOLD); $inventoryUnit2->setStockable($product); $inventoryUnits->add($inventoryUnit1); $inventoryUnits->add($inventoryUnit2); count($inventoryUnits); // Output will be 2. $inventoryOperator->decrease($inventoryUnits); $product->getOnHand(); // Output will be 4. .. caution:: All methods in **InventoryOperator** throw `InvalidArgumentException`_ or `InsufficientStockException` if an error occurs. .. _InvalidArgumentException: https://php.net/manual/en/class.invalidargumentexception.php .. hint:: To understand how events work check `Symfony EventDispatcher`_. .. _Symfony EventDispatcher: https://symfony.com/doc/current/components/event_dispatcher/introduction.html .. _component_inventory_operator_noop-inventory-operator: NoopInventoryOperator --------------------- In some cases, you may want to have unlimited inventory, this operator will allow you to do that. .. hint:: This operator is based on the null object pattern. For more detailed information go to `Null Object pattern`_. .. _Null Object pattern: https://en.wikipedia.org/wiki/Null_Object_pattern .. _component_inventory_checker_availability-checker: AvailabilityChecker ------------------- The **AvailabilityChecker** checks availability of a given stockable object. To characterize an object which is an **AvailabilityChecker**, it needs to implement the :ref:`component_inventory_checker_availability-checker-interface`. Second parameter of the ``->isStockSufficient()`` method gives a possibility to check for a given quantity of a stockable. .. code-block:: php getOnHand(); // Output will be 5 $product->getOnHold(); // Output will be 4 $availabilityChecker = new AvailabilityChecker(false); $availabilityChecker->isStockAvailable($product); // Output will be true. $availabilityChecker->isStockSufficient($product, 5); // Output will be false. .. _component_inventory_factory_inventory-unit-factory: InventoryUnitFactory -------------------- The **InventoryUnitFactory** creates a collection of new inventory units. .. code-block:: php create($product, 10, InventoryUnitInterface::STATE_RETURNED); // Output will be collection of inventory units. $inventoryUnits[0]->getStockable(); // Output will be your's stockable model. $inventoryUnits[0]->getInventoryState(); // Output will be 'returned'. count($inventoryUnits); // Output will be 10.