The product deposit plugin in Sylius allows you to set an amount of refundable deposit price for any product. For example: deposit for bottles, cans, pallets, batteries or car replacement parts.
- Store individual deposit prices for each product variant and channel
- The deposit price is displayed on the product detail page
- At shopping cart / checkout / order the total unit price inclusive deposit is displayed.
composer require gewebe/sylius-product-deposit-plugin
Register the plugin by adding it to your config/bundles.php
file
<?php
return [
// ...
Gewebe\SyliusProductDepositPlugin\GewebeSyliusProductDepositPlugin::class => ['all' => true],
];
# config/packages/gewebe_sylius_product_deposit.yaml
imports:
- { resource: '@GewebeSyliusProductDepositPlugin/Resources/config/app/config.yml'}
From: [shop_dir]/vendor/gewebe/sylius-product-deposit-plugin/test/Application/templates
To: [shop_dir]/templates
- If you use
annotations
mapping:
# src/Entity/Product/ProductVariant.php
namespace App\Entity\Product;
use Doctrine\ORM\Mapping as ORM;
use Gewebe\SyliusProductDepositPlugin\Entity\ProductVariantInterface as ProductVariantDepositInterface;
use Gewebe\SyliusProductDepositPlugin\Entity\ProductVariantDepositTrait;
use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant;
/**
* @ORM\Entity
* @ORM\Table(name="sylius_product_variant")
*/
class ProductVariant extends BaseProductVariant implements ProductVariantDepositInterface
{
use ProductVariantDepositTrait;
public function __construct()
{
parent::__construct();
$this->initProductVariantDepositTrait();
}
// ...
}
- If you use
yaml
mapping add also:
App\Entity\Product\ProductVariant:
type: entity
table: sylius_product_variant
manyToOne:
depositTaxCategory:
targetEntity: Sylius\Component\Taxation\Model\TaxCategoryInterface
joinColumn:
name: deposit_tax_category_id
referencedColumnName: id
onDelete: SET NULL
oneToMany:
channelDeposits:
targetEntity: Gewebe\SyliusProductDepositPlugin\Entity\ChannelDepositInterface
mappedBy: productVariant
orphanRemoval: true
indexBy: channelCode
cascade:
- all
bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate
Setup
$ composer install
$ cd tests/Application
$ yarn install
$ yarn run gulp
$ bin/console assets:install public -e test
$ bin/console doctrine:schema:create -e test
$ export APP_ENV=test
$ symfony server:start --port=8080 --dir=public
Run Tests
$ vendor/bin/behat
$ vendor/bin/phpspec run
$ vendor/bin/phpstan analyse -c phpstan.neon -l max src/
$ vendor/bin/psalm