Giter Site home page Giter Site logo

syliusproductdepositplugin's Introduction

Sylius Product Deposit Plugin

Latest Version on Packagist Software License Build Quality Score

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.

Features

  • 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.

Installation

Download the plugin via composer

composer require gewebe/sylius-product-deposit-plugin

Enable the plugin

Register the plugin by adding it to your config/bundles.php file

<?php

return [
    // ...
    Gewebe\SyliusProductDepositPlugin\GewebeSyliusProductDepositPlugin::class => ['all' => true],
];

Configure the plugin

# config/packages/gewebe_sylius_product_deposit.yaml

imports:
    - { resource: '@GewebeSyliusProductDepositPlugin/Resources/config/app/config.yml'}

Copy the template overrides from the plugin directory

From: [shop_dir]/vendor/gewebe/sylius-product-deposit-plugin/test/Application/templates
To: [shop_dir]/templates

Extend ProductVariant entity

  • 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

Update your database schema

bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate

Usage

1. Add a deposit price to a product variant

Screenshot manage product variant deposit price

2. Browse a product variant with deposit price

Screenshot product details with deposit

3. Buy a product with deposit price included in final product price

Screenshot shopping cart with deposit

Testing

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

syliusproductdepositplugin's People

Contributors

gewebe avatar fl0s avatar

Watchers

James Cloos avatar  avatar

Forkers

fl0s

syliusproductdepositplugin's Issues

Official Sylius plugin

Hello!

I'm Mateusz, I work in Sylius company and one of my roles is Plugin Curator - I'm responsible for checking out Sylius Plugins that appear in our ecosystem. We would really love to display this one on our officially accepted plugins list (https://sylius.com/plugins/), as I strongly believe it could be useful for other people in the community :)

The only problem is, we have some strict requirements for the plugin that is meant to be displayed on our website. One of the most important are the properly developed tests. Sadly, your plugin has neither unit (PHPSpec/PHPUnit) nor acceptance (Behat) tests. Do you think you would be able to provide them? It would be great if we could extend our accepted plugins set with SyliusDepositPlugin :)

If you have any question, please, feel free to ask me.
Nevertheless, thank you for choosing Sylius and for your great job!

Error installing using composer

I'm facing the following issue:
image

Which further information do you need in order to identify the issue?
The error message appeared right after running composer require gewebe/sylius-product-deposit-plugin

Sylius version: 1.10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.