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
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.
Then, enable the plugin by adding it to the list of registered plugins/bundles
in the app/AppKernel.php
file of your project:
<?php
// app/AppKernel.php
use Sylius\Bundle\CoreBundle\Application\Kernel;
final class AppKernel extends Kernel
{
public function registerBundles(): array
{
return array_merge(parent::registerBundles(), [
// ...
new \Loevgaard\SyliusBrandPlugin\LoevgaardSyliusBrandPlugin(),
// ...
]);
}
// ...
}
# app/config/config.yml
imports:
# ...
- { resource: "@LoevgaardSyliusBrandPlugin/Resources/config/config.yml" }
# app/config/routing.yml
loevgaard_sylius_brand:
resource: "@LoevgaardSyliusBrandPlugin/Resources/config/routing.yml"
# src/AppBundle/Resources/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
<?php
// src/AppBundle/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.
$ php bin/console doctrine:schema:update --force
or use Doctrine Migrations.
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/
We use the same service as Sylius for translating, namely Crowdin. You can help out by translating this project into your mother tongue ;)
Thanks!