loevgaard / sylius-brand-plugin
A Sylius plugin for handling brands
Fund package maintenance!
Setono
Installs: 132 608
Dependents: 2
Suggesters: 1
Security: 0
Stars: 30
Watchers: 5
Forks: 30
Open Issues: 20
Type:sylius-plugin
Requires
- sylius/sylius: ^1.3
Requires (Dev)
- behat/behat: ^3.4
- behat/mink: ^1.7@dev
- behat/mink-browserkit-driver: ^1.3
- behat/mink-extension: ^2.2
- behat/mink-selenium2-driver: ^1.3
- ergebnis/composer-normalize: ^2.0
- friends-of-behat/mink-debug-extension: ^1.2.3 || ^2.0
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/service-container-extension: ^1.0
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.0
- friends-of-behat/variadic-extension: ^1.1
- lchrusciel/api-test-case: ^4.0 || ^5.0
- matthiasnoback/symfony-config-test: ^4.0
- phpspec/phpspec: ^7.0
- phpstan/phpstan: ^0.12 || ^1.0
- phpstan/phpstan-doctrine: ^0.12 || ^1.0
- phpstan/phpstan-symfony: ^0.12 || ^1.0
- phpstan/phpstan-webmozart-assert: ^0.12 || ^1.0
- phpunit/phpunit: ^8.0
- roave/security-advisories: dev-master
- sensiolabs/security-checker: ^5.0
- sylius-labs/coding-standard: ^4.0
- symfony/browser-kit: ^3.4 || ^4.1
- symfony/debug-bundle: ^3.4 || ^4.1
- symfony/dotenv: ^4.2
- symfony/event-dispatcher: ^3.4 || ^4.1
- symfony/intl: ^3.4 || ^4.1
- symfony/web-profiler-bundle: ^3.4 || ^4.1
- symfony/web-server-bundle: ^3.4 || ^4.1
Conflicts
- symfony/browser-kit: 4.1.8
- symfony/dependency-injection: 4.1.8
- symfony/doctrine-bridge: 4.3.0
- symfony/dom-crawler: 4.1.8
- symfony/framework-bundle: 4.3.0
- symfony/routing: 4.1.8
- symfony/symfony: 4.1.8
- 3.x-dev
- 2.x-dev
- v2.2.1
- v2.2.0
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v2.0.0-beta.6
- v2.0.0-beta.5
- v2.0.0-beta.4
- v2.0.0-beta.3
- v2.0.0-beta.2
- v2.0.0-beta
- dev-master / 1.3.x-dev
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- dev-l10n_master
- dev-php8
- dev-example-extend-entities
This package is auto-updated.
Last update: 2024-12-11 12:10:36 UTC
README
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
Screenshots
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 before (!) SyliusGridBundle
:
<?php # config/bundles.php return [ // ... Loevgaard\SyliusBrandPlugin\LoevgaardSyliusBrandPlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], // ... ];
Step 3: Configure the plugin
# config/packages/loevgaard_sylius_brand.yaml imports: # ... - { resource: "@LoevgaardSyliusBrandPlugin/Resources/config/app/config.yaml" } # If you want to see Brand column at admin products list - uncomment next line # - { resource: "@LoevgaardSyliusBrandPlugin/Resources/config/grids/sylius_admin_product.yaml" }
# config/routes/loevgaard_sylius_brand.yaml loevgaard_sylius_brand: resource: "@LoevgaardSyliusBrandPlugin/Resources/config/routing.yaml"
Step 4: Extend services and entities
Extend Product
-
If you use
annotations
mapping:<?php declare(strict_types=1); namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Loevgaard\SyliusBrandPlugin\Model\ProductInterface as LoevgaardSyliusBrandPluginProductInterface; use Loevgaard\SyliusBrandPlugin\Model\ProductTrait as LoevgaardSyliusBrandPluginProductTrait; use Sylius\Component\Core\Model\Product as BaseProduct; /** * @ORM\Entity * @ORM\Table(name="sylius_product") */ class Product extends BaseProduct implements LoevgaardSyliusBrandPluginProductInterface { use LoevgaardSyliusBrandPluginProductTrait; }
-
If you use
xml
mapping:<?php // src/Model/Product.php declare(strict_types=1); namespace App\Model; use Loevgaard\SyliusBrandPlugin\Model\ProductInterface as LoevgaardSyliusBrandPluginProductInterface; use Loevgaard\SyliusBrandPlugin\Model\ProductTrait as LoevgaardSyliusBrandPluginProductTrait; use Sylius\Component\Core\Model\Product as BaseProduct; class Product extends BaseProduct implements LoevgaardSyliusBrandPluginProductInterface { use LoevgaardSyliusBrandPluginProductTrait; // ... }
<?xml version="1.0" encoding="UTF-8"?> <!-- config/doctrine/model/Product.orm.xml --> <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="App\Model\Product" table="sylius_product"> <many-to-one field="brand" target-entity="Loevgaard\SyliusBrandPlugin\Model\BrandInterface" inversed-by="products"> <join-column name="brand_id" on-delete="SET NULL" /> </many-to-one> </mapped-superclass> </doctrine-mapping>
Extend ProductRepository
<?php # src/Doctrine/ORM/ProductRepository.php declare(strict_types=1); namespace App\Doctrine\ORM; use Loevgaard\SyliusBrandPlugin\Doctrine\ORM\ProductRepositoryInterface as LoevgaardSyliusBrandPluginProductRepositoryInterface; use Loevgaard\SyliusBrandPlugin\Doctrine\ORM\ProductRepositoryTrait as LoevgaardSyliusBrandPluginProductRepositoryTrait; use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository as BaseProductRepository; class ProductRepository extends BaseProductRepository implements LoevgaardSyliusBrandPluginProductRepositoryInterface { use LoevgaardSyliusBrandPluginProductRepositoryTrait; // ... }
Configure
config/services.yaml sylius_product: resources: product: classes: model: App\Model\Product # Or App\Entity\Product repository: App\Doctrine\ORM\ProductRepository
Step 5: Update your database schema
$ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate
Fixtures
-
Include prefedined brand fixtures to play with on your dev environment:
# config/packages/loevgaard_sylius_brand.yaml imports: - { resource: "@LoevgaardSyliusBrandPlugin/Resources/config/app/fixtures.yaml" }
-
Or write your own:
-
Add a new yaml file to the folder
config/packages
and name it as you wish, e.g.my_own_fixtures.yaml
. -
Fill this yaml with your own brand fixtures and don't forget to declare the definition of your product(s) before this brand definition or use existing product(s) code.
# config/packages/my_own_fixtures.yaml sylius_fixtures: suites: my_own_brand_fixtures: fixtures: loevgaard_sylius_brand_plugin_brand: options: custom: my_brand: name: 'My brand' code: 'my-brand' images: local_image: type: logo path: images/my-brand/logo.jpg 3rd_party_plugin_image: type: black-and-white path: '@SomePlugin/Resources/images/my-brand/black-and-white.jpg' products: - product_code_1 - product_code_2 - product_code_3
See example at
src/Resources/config/app/fixtures.yaml
.
-
-
Load your fixtures
php bin/console sylius:fixture:load my_own_brand_fixtures
Installation and usage for plugin development
To run test application to play with just type composer try
.
Sonata blocks available
loevgaard_sylius_brand.admin.brand.create.tab_details
loevgaard_sylius_brand.admin.brand.update.tab_details
loevgaard_sylius_brand.admin.brand.create.tab_media
loevgaard_sylius_brand.admin.brand.update.tab_media
Events available
loevgaard_sylius_brand.menu.admin.brand.form
to customizeBrand
admin form like you usually do withProduct
form viasylius.menu.admin.product.form
event.
Testing
Play with API
-
Install https://stedolan.github.io/jq/ (type
brew install jq
at OSX terminal) -
Get admin API access token:
SYLIUS_ADMIN_API_ACCESS_TOKEN=$(curl http://localhost:8000/api/oauth/v2/token \ --silent --show-error \ -d "client_id"=demo_client \ -d "client_secret"=secret_demo_client \ -d "grant_type"=password \ -d "username"=api@example.com \ -d "password"=sylius-api | jq '.access_token' --raw-output)
-
Make requests:
(
GET
requests indexing/showing resources shown here as an example, seetests/Controller/*ApiTest.php
to discover more details about creating/updating/removing brand-related resources, creating new products with brand attached to it, uploading image files forBrandImages
via API)To Brands admin API:
curl http://localhost:8000/api/v1/brands/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
curl http://localhost:8000/api/v1/brands/setono/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
Brand images API:
curl http://localhost:8000/api/v1/brands/setono/images/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
Brand images by type API:
curl http://localhost:8000/api/v1/brands/setono/images/logo/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
curl http://localhost:8000/api/v1/brands/setono/images/<ID>/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
Brand products API:
curl http://localhost:8000/api/v1/brands/setono/products/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
Product details API:
curl http://localhost:8000/api/v1/products/setono-mug/ \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
For XML output, add
-H "Accept: application/xml"
to request
Contribute
Please, run composer all
to run all checks and tests before committing.
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!