Shopware 6 custom stock handling

40 views Asked by At

I am trying to override the stock management logic in Shopware 6.5.8.x as per the shopware guideline. The steps I have taken so far are as follows:

  1. I added the flag in the .env file
// <project root>/.env
STOCK_HANDLING=1
  1. Disabled the configuration in yaml
# <project root>/config/packages/shopware.yaml
shopware:
  stock:
    enable_stock_management: false
  1. Decorated the AbstractStockStorage as per this guide to load stock from a different source (a custom ManyToOne table in my case)
public function load(StockLoadRequest $stockRequest, SalesChannelContext $context): StockDataCollection
    {
        // My own implementation to get the stock 

        return new StockDataCollection(
            array_map(function (string $productId, int $stock) {
                return new StockData($productId, $stock, true, null, null, false);
            }, array_keys($result), $result)
        );
    }

For testing the configuration and implementation, my decorated method is returning 50 as stock, so I set the stock of a product to 0 in the product backend (default shopware entity) and marked it as isCloseout, but the product is still showing up as no longer available.

Based on my custom stock implementation, I am explicitly setting isCloseout as false in order to override the isCloseout functionality of Shopware. Am I missing something? Or this is not how it is supposed to work?

Any guidance in this area will be super helpful. Thanks in advance.

0

There are 0 answers