webburza/sylius-wishlist-plugin

Sylius电子商务平台的愿望单插件。

安装: 329

依赖者: 0

建议者: 0

安全: 0

星星: 19

观察者: 3

分支: 27

开放问题: 3

类型:sylius-plugin


README

此捆绑包为Sylius电子商务平台添加愿望单功能。它可以配置为使用每个用户的单个或多个愿望单,这些愿望单可以是公开的或私有的。

安装

  1. 使用Composer要求捆绑包
$ composer require webburza/sylius-wishlist-plugin
  1. app/AppKernel.php 中启用捆绑包
public function registerBundles()
{
  $bundles = [
    // ...
    new \Webburza\SyliusWishlistPlugin\WebburzaSyliusWishlistPlugin(),
    // ...
  ];
}
  1. 将配置添加到 app/config/config.yml 顶部
imports:
    - { resource: "@WebburzaSyliusWishlistPlugin/Resources/config/config.yml" }

除此之外,这还提供了配置条目,然后在您的应用程序的config.yml中进行覆盖。

webburza_sylius_wishlist:
    multiple: true           # multiple wishlist mode
    default_public: false    # used for automatically created wishlists
  1. app/config/routing.yml 中注册路由
webburza_sylius_wishlist:
  resource: "@WebburzaSyliusWishlistPlugin/Resources/config/routing.yml"
  1. 现在捆绑包已完全集成,但它仍然需要创建数据库表。为此,我们建议使用迁移。
$ bin/console doctrine:migrations:diff
$ bin/console doctrine:migrations:migrate

或者,如果您不使用迁移,可以直接更新数据库模式。

  $ bin/console doctrine:schema:update
  1. 如果您将此捆绑包集成到现有项目中,您的现有用户将不会与任何愿望单相关联。这不是问题,因为需要时愿望单会自动创建。

在商店页面上的集成

现在您已安装并集成捆绑包,用户可以查看他们的愿望单,创建新的愿望单等,具体取决于捆绑包配置,但他们仍然没有方法将产品添加到愿望单中。由于每个项目都将有自定义的产品页面,因此此实现取决于您。有两种方法可以实现。

  1. 简单

由于“添加到愿望单”功能几乎与添加到购物车相同,因此最终集成最简单的方法是在现有表单中添加一个新按钮“添加到愿望单”,位于“添加到购物车”按钮旁边。

打开包含您的“添加到购物车”表单的模板,最可能在: app/Resources/SyliusShopBundle/views/Product/Show/_addToCart.html.twig

找到“添加到购物车”按钮,默认情况下

<button type="submit" class="ui huge primary icon labeled button"><i class="cart icon"></i> {{ 'sylius.ui.add_to_cart'|trans }}</button>

并在其下方添加以下行。

{% include '@WebburzaSyliusWishlistPlugin/Shop/Misc/_addToWishlist.html.twig' %}

这将包含“添加到愿望单”按钮,以及所有必需的功能。如果用户有多个愿望单,它还将包含下拉菜单,以便用户可以选择要将项目添加到哪个愿望单。

下拉菜单仅当用户有多个愿望单时才会渲染。

  1. 自定义AJAX实现

另一种选择是实现您自己的完全定制的“添加到愿望单”功能。为此,请将数据提交到 webburza_wishlist_frontend_add_item 路由。

$.ajax({
    url: '/wishlist/item',
    type: 'POST',
    data: {
        productVariantId: 123,
        wishlistId: 456 // optional
    },
    success: // ...
});

您也可以使用与第一个示例相同格式提交数据(“添加到购物车”表单),两个示例都使用相同的路由,并且都接受需要解析的变体数据(第一个示例)或已解析的产品变体ID。

愿望单徽章

您可能还希望在页眉中添加一个徽章,该徽章链接到愿望单并显示当前添加的项目数量,类似于现有的购物车徽章。

为此,只需将此行添加到同一文件 app/Resources/SyliusShopBundle/views/Cart/_widget.html.twig 的底部

{% include '@WebburzaSyliusWishlistPlugin/Shop/Misc/_badge.html.twig' %}

翻译和命名

该捆绑包支持多语言,并且可以通过在 app/Resources/WebburzaSyliusWishlistPlugin/translations 目录中创建翻译文件,以与其他任何捆绑包一样覆盖语言文件。

要开始,请检查捆绑包的主要语言文件: src/Resources/translations/messages.en.yml

手动运行和测试应用程序

  • 初始安装和固定数据

    $ composer install
    
    $ (cd tests/Application && yarn install)
    $ (cd tests/Application && yarn run gulp)
    $ (cd tests/Application && bin/console assets:install web -e dev)
    
    $ (cd tests/Application && bin/console doctrine:database:create -e dev)
    $ (cd tests/Application && bin/console doctrine:schema:create -e dev)
    $ (cd tests/Application && bin/console sylius:fixtures:load -e dev)
  • 启动应用程序

    $ (cd tests/Application && bin/console server:start -d web -e dev)
  • 停止应用程序

    $ (cd tests/Application && bin/console server:stop)

自动测试

  • Behat(非JavaScript场景)

    $ bin/behat --tags="~@javascript"
  • Behat(带有JavaScript场景)

    1. 下载 Chromedriver

    2. 使用之前下载的Chromedriver运行Selenium服务器

      $ bin/selenium-server-standalone -Dwebdriver.chrome.driver=/path/to/chromedriver
    3. localhost:8080 上运行测试应用的web服务器

      $ (cd tests/Application && bin/console server:run 127.0.0.1:8080 -d web -e test)
    4. 运行Behat

      $ bin/behat

许可协议

此包受 MIT许可协议 保护。