A Sylius plugin to enable the association of brands to your products
Switch branches/tags
Nothing to show
Clone or download
loevgaard Merge pull request #18 from nicoplh/patch-1
Update AdminMenuListener.php
Latest commit 37ef2b1 Nov 22, 2018

README.md

Sylius Brand Plugin

Latest Version on Packagist Software License Build Status Quality Score

If you want to add a brand to your products this is the plugin to use. Use cases:

  • Add brand logo to your product pages
  • Filter by brand in the frontend or backend, i.e. product lists

Installation

Step 1: Download the plugin

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require loevgaard/sylius-brand-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

return [
    // ...
    Loevgaard\SyliusBrandPlugin\LoevgaardSyliusBrandPlugin::class => ['all' => true],
    // ...
}

Step 3: Configure the plugin

# config/services.yml

imports:
    # ...
    - { resource: "@LoevgaardSyliusBrandPlugin/Resources/config/config.yml" }
# config/routing.yml

loevgaard_sylius_brand:
    resource: "@LoevgaardSyliusBrandPlugin/Resources/config/routing.yml"
# config/doctrine/Product.orm.yml

AppBundle\Entity\Product:
    type: entity
    table: sylius_product
    manyToOne:
        brand:
            targetEntity: Loevgaard\SyliusBrandPlugin\Entity\Brand
            joinColumn:
                name: brand_id
                referencedColumnName: id

Step 4: Import product trait

<?php
// src/Entity/Product.php

declare(strict_types=1);

namespace AppBundle\Entity;

use Loevgaard\SyliusBrandPlugin\Entity\BrandAwareInterface;
use Loevgaard\SyliusBrandPlugin\Entity\ProductTrait;
use Sylius\Component\Core\Model\Product as BaseProduct;

class Product extends BaseProduct implements BrandAwareInterface
{
    use ProductTrait;
    
    // ...
}

NOTE: If you haven't extended the Product entity yet, follow the customization instructions first because you need to add a bit more configuration.

Step 5: Update your database schema

$ php bin/console doctrine:schema:update --force

or use Doctrine Migrations.

Step 6: Add form widget to twig template

You need to override the template displaying the product form and add a form_row statement with the brand. In the example below I have added it below the channels widget.

{# app/Resources/SyliusAdminBundle/views/Product/Tab/_details.html.twig #}

{# ... #}

<div class="column">
    {{ form_row(form.channels) }}

    {{ form_row(form.brand) }} {# This is the part you should add #}
</div>

{# ... #}

If you haven't overridden the template yet, you can just copy the template from vendor/loevgaard/sylius-brand-plugin/src/Resources/views/SyliusAdminBundle to app/Resources/SyliusAdminBundle/views/

Installation and usage for plugin development

Find more information here

Contribute by translating

We use the same service as Sylius for translating, namely Crowdin. You can help out by translating this project into your mother tongue ;)

Thanks!