tavy315/sylius-labels-plugin
最新稳定版本:v0.6.0
Composer 安装命令:
composer require tavy315/sylius-labels-plugin
包简介
Sylius plugin for product labels.
关键字:
README 文档
README
The labels 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.
Screenshots
Shop:
Admin:
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-labels-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 before (!) SyliusGridBundle:
<?php $bundles = [ Tavy315\SyliusLabelsPlugin\Tavy315SyliusLabelsPlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], ];
Step 3: Configure plugin
# config/packages/tavy315_product_labels.yaml imports: - { resource: "@Tavy315SyliusLabelsPlugin/Resources/config/app/config.yaml" }
Step 4: Import routing
# config/routes/tavy315_product_labels.yaml tavy315_product_labels: resource: "@Tavy315SyliusLabelsPlugin/Resources/config/routing.yaml"
Step 5: Customize models
Read more about Sylius models customization here.
Customize your Product model
Add a Tavy315\SyliusLabelsPlugin\Model\LabelsAwareTrait trait to your App\Entity\Product class.
-
If you use
annotationsmapping:<?php // src/Entity/Product.php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\Product as BaseProduct; use Tavy315\SyliusLabelsPlugin\Model\LabelsAwareTrait; use Tavy315\SyliusLabelsPlugin\Model\ProductInterface; /** * @ORM\Entity * @ORM\Table(name="sylius_product") */ class Product extends BaseProduct implements ProductInterface { use LabelsAwareTrait { LabelsAwareTrait::__construct as private __labelsTraitConstruct; } public function __construct() { $this->__labelsTraitConstruct(); parent::__construct(); } }
-
If you use
xmlmapping:<?php // src/Model/Product.php namespace App\Model; use Sylius\Component\Core\Model\Product as BaseProduct; use Tavy315\SyliusLabelsPlugin\Model\LabelsAwareTrait; use Tavy315\SyliusLabelsPlugin\Model\ProductInterface; class Product extends BaseProduct implements ProductInterface { use LabelsAwareTrait { LabelsAwareTrait::__construct as private __labelsTraitConstruct; } public function __construct() { $this->__labelsTraitConstruct(); parent::__construct(); } }
<?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"> <entity name="App\Model\Product" table="sylius_product"> <many-to-many field="labels" target-entity="Tavy315\SyliusLabelsPlugin\Model\LabelInterface"> <join-table name="tavy315_sylius_product_labels"> <join-columns> <join-column name="product_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" /> </join-columns> <inverse-join-columns> <join-column name="label_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" /> </inverse-join-columns> </join-table> </many-to-many> </entity> </doctrine-mapping>
If you haven't done so already, configure the sylius_product resource to point to your App\Entity\Product like we
did in an example here.
Step 6: Update your database schema
$ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate
Step 7: Add labels to your product templates
Add labels to your product box template. By default, you should use templates/bundles/SyliusShopBundle/Product/__mainImage.html.twig
path. Check out our __mainImage.html.twig file for a reference.
Note the line: {% include "@Tavy315SyliusLabelsPlugin/Shop/Product/Label/_labels.html.twig" with {'labels' : product.labels} %}.
Usage
From now on you should be able to add new labels in the admin panel. Once you add one, you can attach it to products.
统计信息
- 总下载量: 920
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-30


