societe-des-avis-garantis / sylius-sag-plugin
Product review integration for Société des Avis Garantis.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 1
Open Issues: 0
Type:sylius-plugin
Requires
- php: ^8.0
- sylius/sylius: ~1.11.0
- symfony/http-client: ^5.4
Requires (Dev)
- behat/behat: ^3.6.1
- behat/mink-selenium2-driver: ^1.4
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink: ^1.8
- friends-of-behat/mink-browserkit-driver: ^1.4
- friends-of-behat/mink-debug-extension: ^2.0.0
- friends-of-behat/mink-extension: ^2.4
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.1
- friends-of-behat/variadic-extension: ^1.3
- friendsofsymfony/oauth-server-bundle: ^1.6 || >2.0.0-alpha.0 ^2.0@dev
- phpspec/phpspec: ^7.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: 0.12.99
- phpstan/phpstan-doctrine: 0.12.33
- phpstan/phpstan-strict-rules: ^0.12.0
- phpstan/phpstan-webmozart-assert: 0.12.12
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- sensiolabs/security-checker: ^6.0
- sylius-labs/coding-standard: ^4.0
- symfony/browser-kit: ^5.4
- symfony/debug-bundle: ^5.4
- symfony/dotenv: ^5.4
- symfony/intl: ^5.4
- symfony/web-profiler-bundle: ^5.4
- vimeo/psalm: 4.7.1
README
Plugin SAG
Sylius SAG plugin by Dedi. Product review integration for Société des Avis Garantis
About Dedi
At Dedi, we do not just create websites. We are building together a real digital strategy to combine your business requirements with our technical skills. We've been working with open source for a long time and decided to start giving back to the community by contributing and sharing some plugin of our own.
We’ll be happy to meet you, feel free to contact us. Learn more about us on our website.
Table of Content
- Installation
- Configure Product
- Configure Product Review
- Configure Order
- Configure Channel
- Migrations
- Templates
- Overview
Installation
Require plugin with composer:
composer require societe-des-avis-garantis/sylius-sag-plugin --no-scripts
Symfony Flex will automatically register and configure the config/bundles.php
file to add the line for the plugin :
<?php return [ //.. Dedi\SyliusSAGPlugin\DediSyliusSAGPlugin::class => ['all' => true], ];
- Create a
dedi_sag_plugin.yaml
file intoconfig/packages
folder to import required config
# config/packages/dedi_sag_plugin.yaml imports: - { resource: "@DediSyliusSAGPlugin/Resources/config/config.yml" }
- Add the plugin routes to your config.
# config/routes.yaml dedi_sylius_sag_shop: resource: "@DediSyliusSAGPlugin/Resources/config/shop_routing.yml" prefix: /{_locale} requirements: _locale: ^[a-z]{2}(?:_[A-Z]{2})?$ dedi_sylius_sag_admin: resource: "@DediSyliusSAGPlugin/Resources/config/admin_routing.yml" prefix: /admin dedi_sylius_sag_api: resource: "@DediSyliusSAGPlugin/Resources/config/api_routing.yml" prefix: /sag-api
Configure Product
Your Product
entity needs to implement the Dedi\SyliusSAGPlugin\Entity\Product\ProductInterface
interface and use the Dedi\SyliusSAGPlugin\Entity\Product\ProductTrait
trait.
<?php declare(strict_types=1); namespace App\Entity\Product; use Dedi\SyliusSAGPlugin\Entity\Product\ProductInterface as DediSAGProductInterface; use Dedi\SyliusSAGPlugin\Entity\Product\ProductTrait as DediSAGProductTrait; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\Product as BaseProduct; /** * @ORM\Entity * @ORM\Table(name="sylius_product") */ class Product extends BaseProduct implements DediSAGProductInterface { use DediSAGProductTrait; }
Configure ProductReview
Your ProductReview
entity needs to implement the Dedi\SyliusSAGPlugin\Entity\Review\ProductReviewInterface
interface and use the Dedi\SyliusSAGPlugin\Entity\Review\ProductReviewTrait
trait.
<?php declare(strict_types=1); namespace App\Entity\Product; use Dedi\SyliusSAGPlugin\Entity\Review\ProductReviewInterface as DediSAGProductReviewInterface; use Dedi\SyliusSAGPlugin\Entity\Review\ProductReviewTrait as DediSAGProductReviewTrait; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\ProductReview as BaseProductReview; /** * @ORM\Entity * @ORM\Table(name="sylius_product_review") */ class ProductReview extends BaseProductReview implements DediSAGProductReviewInterface { use DediSAGProductReviewTrait; public function setId(?int $id): void { $this->id = $id; } }
Your ProductReviewRepository
repository needs to implement the Dedi\SyliusSAGPlugin\Repository\Review\ProductReviewRepositoryInterface
interface and use the Dedi\SyliusSAGPlugin\Repository\Review\ProductReviewRepositoryTrait
trait.
<?php declare(strict_types=1); namespace App\Repository\Review; use Dedi\SyliusSAGPlugin\Repository\Review\ProductReviewRepositoryInterface as DediSAGProductReviewRepositoryInterface; use Dedi\SyliusSAGPlugin\Repository\Review\ProductReviewRepositoryTrait as DediSAGProductReviewRepositoryTrait; use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductReviewRepository as BaseProductReviewRepository; final class ProductReviewRepository extends BaseProductReviewRepository implements DediSAGProductReviewRepositoryInterface { use DediSAGProductReviewRepositoryTrait; }
Don't forget to update the Sylius resource config accordingly.
# config/_sylius.yaml sylius_review: resources: product: review: classes: model: App\Entity\Product\ProductReview repository: App\Repository\Review\ProductReviewRepository reviewer: classes: # configure the reviewer with this entity otherwise it will use the Customer entity model: Sylius\Component\Review\Model\Reviewer
Your ProductReviewFactory
should implement Dedi\SyliusSAGPlugin\Factory\Review\ReviewFactoryInterface
and use the Dedi\SyliusSAGPlugin\Factory\Review\ReviewFactoryTrait
trait.
<?php declare(strict_types=1); namespace App\Factory\Review; use Dedi\SyliusSAGPlugin\Factory\Review\ReviewFactoryInterface as DediSAGReviewFactoryInterface; use Dedi\SyliusSAGPlugin\Factory\Review\ReviewFactoryTrait as DediSAGReviewFactoryTrait; use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\Component\Review\Factory\ReviewFactoryInterface; use Sylius\Component\Review\Model\ReviewableInterface; use Sylius\Component\Review\Model\ReviewerInterface; use Sylius\Component\Review\Model\ReviewInterface; final class ReviewFactory implements DediSAGReviewFactoryInterface { use DediSAGReviewFactoryTrait { __construct as initializeDediSAGArguments; } /** @var ReviewFactoryInterface */ private $baseFactory; public function __construct( ReviewFactoryInterface $baseFactory, FactoryInterface $reviewerFactory ) { $this->baseFactory = $baseFactory; $this->initializeDediSAGArguments($reviewerFactory); } public function createNew() { return $this->baseFactory->createNew(); } public function createForSubject(ReviewableInterface $subject): ReviewInterface { return $this->baseFactory->createForSubject($subject); } public function createForSubjectWithReviewer(ReviewableInterface $subject, ?ReviewerInterface $reviewer): ReviewInterface { return $this->baseFactory->createForSubjectWithReviewer($subject, $reviewer); } }
Don't forget to add the corresponding service.
# config/services.yaml services: app.factory.product_review: class: App\Factory\Review\ReviewFactory decorates: sylius.factory.product_review arguments: $baseFactory: '@app.factory.product_review.inner' $reviewerFactory: '@sylius.factory.product_reviewer' public: false
Configure Order
Your OrderRepository
repository needs to implement the Dedi\SyliusSAGPlugin\Repository\Order\OrderRepositoryInterface
interface and use the Dedi\SyliusSAGPlugin\Repository\Order\OrderRepositoryTrait
trait.
<?php declare(strict_types=1); namespace App\Repository\Order; use Dedi\SyliusSAGPlugin\Repository\Order\OrderRepositoryInterface as DediSAGOrderRepositoryInterface; use Dedi\SyliusSAGPlugin\Repository\Order\OrderRepositoryTrait as DediSAGOrderRepositoryTrait; use Sylius\Bundle\CoreBundle\Doctrine\ORM\OrderRepository as BaseOrderRepository; class OrderRepository extends BaseOrderRepository implements DediSAGOrderRepositoryInterface { use DediSAGOrderRepositoryTrait; }
Don't forget to update the Sylius resource config accordingly.
# config/_sylius.yaml sylius_order: resources: order: classes: repository: App\Repository\Order\OrderRepository
Configure Channel
Your Channel
entity needs to implement the Dedi\SyliusSAGPlugin\Entity\Channel\ChannelInterface
interface and use the Dedi\SyliusSAGPlugin\Entity\Channel\ChannelTrait
trait.
<?php declare(strict_types=1); namespace App\Entity\Channel; use Dedi\SyliusSAGPlugin\Entity\Channel\ChannelInterface as DediSAGChannelInterface; use Dedi\SyliusSAGPlugin\Entity\Channel\ChannelTrait as DediSAGChannelTrait; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\Channel as BaseChannel; /** * @ORM\Entity * @ORM\Table(name="sylius_channel") */ class Channel extends BaseChannel implements DediSAGChannelInterface { use DediSAGChannelTrait; }
Create migration
Migrations are already provided by the plugin itself.
bin/console doctrine:migration:migrate
Templates
Override sylius default templates.
cp -R vendor/dedi/sylius-sag-plugin/tests/Application/templates/* templates/
Overview
Product Index
This plugin adds the following features to your shop:
- Javascript widget
- Iframe widget
- footer certificate link
Product Show
On your product page, you will retrieve reviews from Societé des Avis Garantis with some statistics.
Admin Key Index
In the back office, a new entry "SAG Api keys" allows you to configure your shop with Société des Avis Garantis api.
Admin Channel configuration
The channel configuration form gets a new section where you can enable or disable the following parts on your shop:
- Javascript widget
- Iframe widget
- footer certificate link
Admin Reviews
Reviews are now not editable in the back office to comply with Société des Avis Garantis requirements.