tavy315/sylius-sales-prices-plugin 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tavy315/sylius-sales-prices-plugin

最新稳定版本:v0.5.0

Composer 安装命令:

composer require tavy315/sylius-sales-prices-plugin

包简介

Sylius plugin for sales prices.

README 文档

README

Latest Version Latest Unstable Version Software License Build Status

The sales prices plugin for Sylius allows you to configure nice badges for different set of products based on specific rules. It provides a common set of configuration by default and is very flexible when it comes to adding new ones.

Supports Doctrine ORM driver only.

Installation

Step 1: Install the plugin

Open a command console, enter your project directory and execute the following command to download the latest stable version of this plugin:

$ composer require tavy315/sylius-sales-prices-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:

<?php
$bundles = [
    Tavy315\SyliusSalesPricesPlugin\Tavy315SyliusSalesPricesPlugin::class => ['all' => true],
];

Step 3: Configure plugin

# config/packages/_sylius.yaml

imports:
    - { resource: '@Tavy315SyliusSalesPricesPlugin/Resources/config/config.yml'}

Step 4: Import routing

# config/routes.yaml

tavy315_salesprice_bundle:
    resource: '@Tavy315SyliusSalesPricesPlugin/Resources/config/routing.yml'

Step 5: Customize models

Read more about Sylius models customization here.

Customize your ProductVariant model

Add a Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableTrait trait to your App\Entity\Product\ProductVariant class.

  • If you use annotations mapping:

    <?php 
    // src/Entity/Product/ProductVariant.php
    
    namespace App\Entity\Product;
    
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\ORM\Mapping as ORM;
    use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant;
    use Tavy315\SyliusSalesPricesPlugin\Entity\ProductVariantInterface;
    use Tavy315\SyliusSalesPricesPlugin\Entity\SalesPriceInterface;
    use Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableInterface;
    use Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableTrait;
    
    /**
     * @ORM\Entity
     * @ORM\Table(name="sylius_product_variant")
     */
    class ProductVariant extends BaseProductVariant implements SalesPriceableInterface, ProductVariantInterface
    {
        use SalesPriceableTrait;
    
        /**
         * @ORM\OneToMany(targetEntity="Tavy315\SyliusSalesPricesPlugin\Entity\SalesPrice", mappedBy="productVariant", orphanRemoval=true, cascade={"all"})
         * @ORM\OrderBy({"priceGroup"="ASC","qty"="ASC"})
         * @var SalesPriceInterface[]|ArrayCollection
         */
        protected $salesPrices;
      
        public function __construct()
        {
            parent::__construct();
    
            $this->initSalesPriceableTrait();
        }
    }
  • If you use xml mapping:

    <?php
    // src/Model/Product/ProductVariant.php
    
    namespace App\Entity\Product;
    
    use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant;
    use Tavy315\SyliusSalesPricesPlugin\Entity\ProductVariantInterface;
    use Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableInterface;
    use Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableTrait;
    
    class ProductVariant extends BaseProductVariant implements SalesPriceableInterface, ProductVariantInterface
    {
        use SalesPriceableTrait;
      
        public function __construct()
        {
            parent::__construct();
    
            $this->initSalesPriceableTrait();
        }
    }
        <?xml version="1.0" encoding="utf-8"?>
        <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="Tavy315\SyliusSalesPricesPlugin\Entity\SalesPrice"
                               repository-class="Tavy315\SyliusSalesPricesPlugin\Repository\SalesPriceRepository"
                               table="tavy315_sylius_sales_price">
                <id name="id" type="integer" column="id">
                    <generator strategy="AUTO" />
                </id>
                <field name="price" type="integer" column="price" />
                <field name="qty" type="integer" column="qty" />
                <field name="priceGroup" type="string" column="price_group" length="30" />
                <field name="startingDate" type="datetime" column="starting_date" nullable="true" />
                <field name="endingDate" type="datetime" column="ending_date" nullable="true" />
                <many-to-one target-entity="Sylius\Component\Channel\Model\ChannelInterface" field="channel">
                    <join-column name="channel_id" />
                </many-to-one>
                <many-to-one target-entity="Sylius\Component\Product\Model\ProductVariantInterface" field="productVariant" inversed-by="salesPrices">
                    <join-column name="product_variant_id" />
                </many-to-one>
            </mapped-superclass>
        </doctrine-mapping>

Step 6: Update your database schema

$ php bin/console doctrine:migrations:diff
$ php bin/console doctrine:migrations:migrate

Usage

From now on you should be able to add new sales prices in the admin panel.

统计信息

  • 总下载量: 225
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固