tavy315 / sylius-sales-prices-plugin
Sylius plugin for sales prices.
Installs: 148
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:sylius-plugin
Requires
- php: >=7.4
- sylius/sylius: ^1.8
Requires (Dev)
- phpstan/phpstan: ^0.12
- phpstan/phpstan-doctrine: ^0.12
- phpstan/phpstan-strict-rules: ^0.12
- phpstan/phpstan-symfony: ^0.12
- phpstan/phpstan-webmozart-assert: ^0.12
- sensiolabs/security-checker: ^5.0
- sylius-labs/coding-standard: ^3.2
README
The sales prices plugin for Sylius allows you to configure nice badges for different set of products based on specific rules. It provides a common set of configuration by default and is very flexible when it comes to adding new ones.
Supports Doctrine ORM driver only.
Installation
Step 1: Install the plugin
Open a command console, enter your project directory and execute the following command to download the latest stable version of this plugin:
$ composer require tavy315/sylius-sales-prices-plugin
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the plugin
Then, enable the plugin by adding it to the list of registered plugins/bundles
in config/bundles.php
file of your project:
<?php $bundles = [ Tavy315\SyliusSalesPricesPlugin\Tavy315SyliusSalesPricesPlugin::class => ['all' => true], ];
Step 3: Configure plugin
# config/packages/_sylius.yaml imports: - { resource: '@Tavy315SyliusSalesPricesPlugin/Resources/config/config.yml'}
Step 4: Import routing
# config/routes.yaml tavy315_salesprice_bundle: resource: '@Tavy315SyliusSalesPricesPlugin/Resources/config/routing.yml'
Step 5: Customize models
Read more about Sylius models customization here.
Customize your ProductVariant model
Add a Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableTrait
trait to your App\Entity\Product\ProductVariant
class.
-
If you use
annotations
mapping:<?php // src/Entity/Product/ProductVariant.php namespace App\Entity\Product; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant; use Tavy315\SyliusSalesPricesPlugin\Entity\ProductVariantInterface; use Tavy315\SyliusSalesPricesPlugin\Entity\SalesPriceInterface; use Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableInterface; use Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableTrait; /** * @ORM\Entity * @ORM\Table(name="sylius_product_variant") */ class ProductVariant extends BaseProductVariant implements SalesPriceableInterface, ProductVariantInterface { use SalesPriceableTrait; /** * @ORM\OneToMany(targetEntity="Tavy315\SyliusSalesPricesPlugin\Entity\SalesPrice", mappedBy="productVariant", orphanRemoval=true, cascade={"all"}) * @ORM\OrderBy({"priceGroup"="ASC","qty"="ASC"}) * @var SalesPriceInterface[]|ArrayCollection */ protected $salesPrices; public function __construct() { parent::__construct(); $this->initSalesPriceableTrait(); } }
-
If you use
xml
mapping:<?php // src/Model/Product/ProductVariant.php namespace App\Entity\Product; use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant; use Tavy315\SyliusSalesPricesPlugin\Entity\ProductVariantInterface; use Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableInterface; use Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableTrait; class ProductVariant extends BaseProductVariant implements SalesPriceableInterface, ProductVariantInterface { use SalesPriceableTrait; public function __construct() { parent::__construct(); $this->initSalesPriceableTrait(); } }
<?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <mapped-superclass name="Tavy315\SyliusSalesPricesPlugin\Entity\SalesPrice" repository-class="Tavy315\SyliusSalesPricesPlugin\Repository\SalesPriceRepository" table="tavy315_sylius_sales_price"> <id name="id" type="integer" column="id"> <generator strategy="AUTO" /> </id> <field name="price" type="integer" column="price" /> <field name="qty" type="integer" column="qty" /> <field name="priceGroup" type="string" column="price_group" length="30" /> <field name="startingDate" type="datetime" column="starting_date" nullable="true" /> <field name="endingDate" type="datetime" column="ending_date" nullable="true" /> <many-to-one target-entity="Sylius\Component\Channel\Model\ChannelInterface" field="channel"> <join-column name="channel_id" /> </many-to-one> <many-to-one target-entity="Sylius\Component\Product\Model\ProductVariantInterface" field="productVariant" inversed-by="salesPrices"> <join-column name="product_variant_id" /> </many-to-one> </mapped-superclass> </doctrine-mapping>
Step 6: Update your database schema
$ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate
Usage
From now on you should be able to add new sales prices in the admin panel.