setono/sylius-reserve-stock-plugin

Reserve Stock Plugin for Sylius.

Installs: 17 718

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 2

Forks: 3

Open Issues: 12

Type:sylius-plugin

v1.3.1 2022-02-03 10:49 UTC

README

Latest Version on Packagist Software License Build Status Quality Score

This plugin will reserve items in your customers' carts in a given amount of time.

Installation

1. Composer

composer require setono/sylius-reserve-stock-plugin

2. Load bundle

Add to the bundle list in config/bundles.php:

<?php

return [
    // ...
    Setono\SyliusReserveStockPlugin\SetonoSyliusReserveStockPlugin::class => ['all' => true],
    // ...
];

3. Configuration

Default configuration is applied automatically. Find out which settings can be adjusted by running:

bin/console config:dump-reference SetonoSyliusReserveStockPlugin

The default configuration is:

setono_sylius_reserve_stock:

    # Define the Time To Live (TTL) for a product reservation.
    ttl: 3600 # Example: 1800

4. Include repository

Option 1: load repository via config

This option applies if you didn't extend the OrderItem repository yet.

sylius_order:
    resources:
        order_item:
            classes:
                repository: Setono\SyliusReserveStockPlugin\Repository\OrderItemRepository

Option 2: include repository trait in your repository

This option applies if you extended the OrderItem repository already. Add the trait to your repository class as shown in the example below. The package also comes with an interface (InCartQuantityForProductVariantOrderItemRepositoryAwareInterface) which you can optionally load.

<?php

declare(strict_types=1);

namespace App\Repository\OrderItemRepository;

use Setono\SyliusReserveStockPlugin\Repository\InCartQuantityForProductVariantOrderItemRepositoryAwareInterface;
use Setono\SyliusReserveStockPlugin\Repository\ProductVariantCartOrderItem;
use Sylius\Bundle\OrderBundle\Doctrine\ORM\OrderItemRepository as BaseOrderItemRepository;

final class OrderItemRepository extends BaseOrderItemRepository implements InCartQuantityForProductVariantOrderItemRepositoryAwareInterface
{
    use ProductVariantCartOrderItem; // Load trait here
}