Merge pull request #854 from Richtermeister/inventory-noop

Add easy way to disable inventory tracking.
This commit is contained in:
Paweł Jędrzejewski 2014-01-27 01:29:07 -08:00
commit b2f6bfa43a
5 changed files with 56 additions and 2 deletions

View file

@ -38,3 +38,4 @@ parameters:
sylius.oauth.google.clientsecret: <google_client_secret>
sylius.inventory.backorders_enabled: true
sylius.inventory.tracking_enabled: true

View file

@ -70,6 +70,7 @@ sylius_promotions:
sylius_inventory:
backorders: %sylius.inventory.backorders_enabled%
track_inventory: %sylius.inventory.tracking_enabled%
classes:
unit:
model: Sylius\Bundle\CoreBundle\Model\InventoryUnit

View file

@ -39,10 +39,21 @@ class Configuration implements ConfigurationInterface
->children()
->scalarNode('driver')->isRequired()->cannotBeEmpty()->end()
->booleanNode('backorders')->defaultTrue()->end()
->booleanNode('track_inventory')->defaultTrue()->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()
->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);

View file

@ -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.
}
}

View file

@ -19,6 +19,7 @@
<parameters>
<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.backorders_handler.class">Sylius\Bundle\InventoryBundle\Operator\BackordersHandler</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" />
</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%">
<argument>%sylius.backorders%</argument>
</service>