Skip to content

Commit

Permalink
MOL-1285: use stock manager config
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Dec 18, 2023
1 parent bb26750 commit f70708b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Resources/config/services/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@

<service id="Kiener\MolliePayments\Service\Stock\StockManager">
<argument type="service" id="Doctrine\DBAL\Connection"/>
<argument>%shopware.stock.enable_stock_management%</argument>
</service>


Expand Down
18 changes: 17 additions & 1 deletion src/Service/Stock/StockManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemEntity;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\DataAbstractionLayer\Doctrine\RetryableQuery;
use Shopware\Core\Framework\Feature;
use Shopware\Core\Framework\Uuid\Uuid;

class StockManager implements StockManagerInterface
Expand All @@ -17,13 +18,20 @@ class StockManager implements StockManagerInterface
*/
private $connection;

/**
* @var bool
*/
private $enableStockManagement;


/**
* @param Connection $connection
* @param bool $enableStockManagement
*/
public function __construct(Connection $connection)
public function __construct(Connection $connection, bool $enableStockManagement)
{
$this->connection = $connection;
$this->enableStockManagement = $enableStockManagement;
}

/**
Expand All @@ -35,6 +43,10 @@ public function __construct(Connection $connection)
*/
public function increaseStock(OrderLineItemEntity $lineItem, int $quantity, string $mollieRefundID): void
{
if ($this->isEnabled() === false) {
return;
}

if ($lineItem->getPayload() === null) {
return;
}
Expand All @@ -59,4 +71,8 @@ public function increaseStock(OrderLineItemEntity $lineItem, int $quantity, stri
]
);
}
private function isEnabled(): bool
{
return $this->enableStockManagement && Feature::isActive('STOCK_HANDLING');
}
}

0 comments on commit f70708b

Please sign in to comment.