mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-15 01:20:59 +00:00
Merge pull request #854 from Richtermeister/inventory-noop
Add easy way to disable inventory tracking.
This commit is contained in:
commit
b2f6bfa43a
5 changed files with 56 additions and 2 deletions
|
|
@ -38,3 +38,4 @@ parameters:
|
||||||
sylius.oauth.google.clientsecret: <google_client_secret>
|
sylius.oauth.google.clientsecret: <google_client_secret>
|
||||||
|
|
||||||
sylius.inventory.backorders_enabled: true
|
sylius.inventory.backorders_enabled: true
|
||||||
|
sylius.inventory.tracking_enabled: true
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ sylius_promotions:
|
||||||
|
|
||||||
sylius_inventory:
|
sylius_inventory:
|
||||||
backorders: %sylius.inventory.backorders_enabled%
|
backorders: %sylius.inventory.backorders_enabled%
|
||||||
|
track_inventory: %sylius.inventory.tracking_enabled%
|
||||||
classes:
|
classes:
|
||||||
unit:
|
unit:
|
||||||
model: Sylius\Bundle\CoreBundle\Model\InventoryUnit
|
model: Sylius\Bundle\CoreBundle\Model\InventoryUnit
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,21 @@ class Configuration implements ConfigurationInterface
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('driver')->isRequired()->cannotBeEmpty()->end()
|
->scalarNode('driver')->isRequired()->cannotBeEmpty()->end()
|
||||||
->booleanNode('backorders')->defaultTrue()->end()
|
->booleanNode('backorders')->defaultTrue()->end()
|
||||||
|
->booleanNode('track_inventory')->defaultTrue()->end()
|
||||||
->scalarNode('checker')->defaultValue('sylius.availability_checker.default')->cannotBeEmpty()->end()
|
->scalarNode('checker')->defaultValue('sylius.availability_checker.default')->cannotBeEmpty()->end()
|
||||||
->scalarNode('operator')->defaultValue('sylius.inventory_operator.default')->cannotBeEmpty()->end()
|
->scalarNode('operator')->cannotBeEmpty()->end()
|
||||||
->arrayNode('events')->prototype('scalar')->end()
|
->arrayNode('events')->prototype('scalar')->end()
|
||||||
->end();
|
->end()
|
||||||
|
->end()
|
||||||
|
->validate()
|
||||||
|
->ifTrue(function($array){
|
||||||
|
return !isset($array['operator']);
|
||||||
|
})
|
||||||
|
->then(function($array){
|
||||||
|
$array['operator'] = 'sylius.inventory_operator.'.($array['track_inventory'] ? 'default' : 'noop');
|
||||||
|
return $array;
|
||||||
|
})
|
||||||
|
->end();
|
||||||
|
|
||||||
$this->addClassesSection($rootNode);
|
$this->addClassesSection($rootNode);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Sylius package.
|
||||||
|
*
|
||||||
|
* (c) Paweł Jędrzejewski
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Sylius\Bundle\InventoryBundle\Operator;
|
||||||
|
|
||||||
|
use Sylius\Bundle\InventoryBundle\Model\StockableInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inventory operator which does not adjust inventory
|
||||||
|
*
|
||||||
|
* @author Daniel Richter <nexyz9@gmail.com>
|
||||||
|
*/
|
||||||
|
class NoopInventoryOperator implements InventoryOperatorInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function increase(StockableInterface $stockable, $quantity)
|
||||||
|
{
|
||||||
|
// nothing happens.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function decrease($inventoryUnits)
|
||||||
|
{
|
||||||
|
// nothing happens.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
<parameters>
|
<parameters>
|
||||||
<parameter key="sylius.availability_checker.default.class">Sylius\Bundle\InventoryBundle\Checker\AvailabilityChecker</parameter>
|
<parameter key="sylius.availability_checker.default.class">Sylius\Bundle\InventoryBundle\Checker\AvailabilityChecker</parameter>
|
||||||
|
<parameter key="sylius.inventory_operator.noop.class">Sylius\Bundle\InventoryBundle\Operator\NoopInventoryOperator</parameter>
|
||||||
<parameter key="sylius.inventory_operator.default.class">Sylius\Bundle\InventoryBundle\Operator\InventoryOperator</parameter>
|
<parameter key="sylius.inventory_operator.default.class">Sylius\Bundle\InventoryBundle\Operator\InventoryOperator</parameter>
|
||||||
<parameter key="sylius.backorders_handler.class">Sylius\Bundle\InventoryBundle\Operator\BackordersHandler</parameter>
|
<parameter key="sylius.backorders_handler.class">Sylius\Bundle\InventoryBundle\Operator\BackordersHandler</parameter>
|
||||||
<parameter key="sylius.inventory_unit_factory.class">Sylius\Bundle\InventoryBundle\Factory\InventoryUnitFactory</parameter>
|
<parameter key="sylius.inventory_unit_factory.class">Sylius\Bundle\InventoryBundle\Factory\InventoryUnitFactory</parameter>
|
||||||
|
|
@ -41,6 +42,8 @@
|
||||||
<argument type="service" id="sylius.availability_checker" />
|
<argument type="service" id="sylius.availability_checker" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<service id="sylius.inventory_operator.noop" class="%sylius.inventory_operator.noop.class%" />
|
||||||
|
|
||||||
<service id="sylius.availability_checker.default" class="%sylius.availability_checker.default.class%">
|
<service id="sylius.availability_checker.default" class="%sylius.availability_checker.default.class%">
|
||||||
<argument>%sylius.backorders%</argument>
|
<argument>%sylius.backorders%</argument>
|
||||||
</service>
|
</service>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue