担保评论公司/sylius-sag-plugin

Société des Avis Garantis的产品评论集成。


README

sylius-logo

插件SAG

Dedi开发的Sylius SAG插件。Société des Avis Garantis的产品评论集成。Société des Avis Garantis

关于Dedi

在Dedi,我们不仅仅是创建网站。我们正在共同努力,结合您的业务需求与我们的技术技能,打造一个真实的数字战略。我们长期从事开源工作,并决定开始通过贡献和共享一些自己的插件来回馈社区。

我们期待与您见面,欢迎联系我们。在我们的网站上了解更多关于我们的信息。

目录

安装

使用composer安装插件

composer require societe-des-avis-garantis/sylius-sag-plugin --no-scripts

Symfony Flex会自动注册并配置config/bundles.php文件,添加插件行

<?php

return [
    //..
    Dedi\SyliusSAGPlugin\DediSyliusSAGPlugin::class => ['all' => true],
];
  • config/packages文件夹中创建一个dedi_sag_plugin.yaml文件,以导入所需配置
# config/packages/dedi_sag_plugin.yaml

imports:
    - { resource: "@DediSyliusSAGPlugin/Resources/config/config.yml" }
  • 将插件路由添加到您的配置中。
# 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

配置产品

您的Product实体需要实现Dedi\SyliusSAGPlugin\Entity\Product\ProductInterface接口并使用Dedi\SyliusSAGPlugin\Entity\Product\ProductTrait特性。

<?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;
}

配置ProductReview

您的ProductReview实体需要实现Dedi\SyliusSAGPlugin\Entity\Review\ProductReviewInterface接口并使用Dedi\SyliusSAGPlugin\Entity\Review\ProductReviewTrait特性。

<?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;
    }
}

您的ProductReviewRepository仓库需要实现Dedi\SyliusSAGPlugin\Repository\Review\ProductReviewRepositoryInterface接口并使用Dedi\SyliusSAGPlugin\Repository\Review\ProductReviewRepositoryTrait特性。

<?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;
}

别忘了根据需要更新Sylius资源配置。

# 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

您的ProductReviewFactory应实现Dedi\SyliusSAGPlugin\Factory\Review\ReviewFactoryInterface并使用Dedi\SyliusSAGPlugin\Factory\Review\ReviewFactoryTrait特性。

<?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);
    }
}

别忘了添加相应的服务。

# 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

配置订单

您的OrderRepository仓库需要实现Dedi\SyliusSAGPlugin\Repository\Order\OrderRepositoryInterface接口并使用Dedi\SyliusSAGPlugin\Repository\Order\OrderRepositoryTrait特性。

<?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;
}

别忘了根据需要更新Sylius资源配置。

# config/_sylius.yaml

sylius_order:
    resources:
        order:
            classes:
                repository: App\Repository\Order\OrderRepository

配置渠道

您的Channel实体需要实现Dedi\SyliusSAGPlugin\Entity\Channel\ChannelInterface接口并使用Dedi\SyliusSAGPlugin\Entity\Channel\ChannelTrait特性。

<?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;
}

创建迁移

迁移已由插件本身提供。

bin/console doctrine:migration:migrate

模板

覆盖Sylius默认模板。

cp -R vendor/dedi/sylius-sag-plugin/tests/Application/templates/* templates/

概述

产品索引

此插件为您的商店添加以下功能

  • JavaScript小部件
  • Iframe小部件
  • 页脚证书链接

docs/img/shop_product_index.png

产品显示

在您的产品页面上,您将检索来自Societé des Avis Garantis的评论和一些统计数据。

docs/img/shop_product_show.png

管理员密钥索引

在后台办公室,一个名为“SAG API密钥”的新条目允许您使用Société des Avis Garantis API配置您的商店。

docs/img/admin_key_index.png

docs/img/admin_key_edit.png

管理员渠道配置

渠道配置表单新增一个部分,您可以在其中启用或禁用以下部分在您的商店中

  • JavaScript小部件
  • Iframe小部件
  • 页脚证书链接

docs/img/admin_channel_edit.png

管理员评论

为了符合Société des Avis Garantis的要求,评论现在不能在后台办公室中编辑。

docs/img/admin_review_index.png