tavy315/sylius-sales-prices-plugin

Sylius 销售价格插件。

安装: 146

依赖: 0

建议者: 0

安全: 0

星星: 0

关注者: 3

分支: 0

开放问题: 0

类型:sylius-plugin

v0.5.0 2022-12-02 12:35 UTC

This package is auto-updated.

Last update: 2024-08-30 01:09:15 UTC


README

Latest Version Latest Unstable Version Software License Build Status

Sylius 的销售价格插件允许您根据特定规则为不同产品组配置漂亮的徽章。它默认提供一组配置,并在添加新配置时非常灵活。

仅支持 Doctrine ORM 驱动。

安装

步骤 1:安装插件

打开命令行,进入您的项目目录,并执行以下命令以下载此插件的最新稳定版本

$ composer require tavy315/sylius-sales-prices-plugin

此命令要求您全局安装 Composer,如 Composer 文档中的安装章节所述。

步骤 2:启用插件

然后,通过将其添加到项目 config/bundles.php 文件中注册的插件/捆绑包列表中来启用插件。

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

步骤 3:配置插件

# config/packages/_sylius.yaml

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

步骤 4:导入路由

# config/routes.yaml

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

步骤 5:自定义模型

有关 Sylius 模型定制的更多信息,请参阅此处

自定义您的产品变体模型

Tavy315\SyliusSalesPricesPlugin\Traits\SalesPriceableTrait 特性添加到您的 App\Entity\Product\ProductVariant 类中。

  • 如果您使用 注解 映射

    <?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();
        }
    }
  • 如果您使用 xml 映射

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

步骤 6:更新数据库模式

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

用法

从现在起,您应该能够在管理面板中添加新的销售价格。