setono/sylius-cost-price-plugin

使用此插件为您的产品变体添加成本价格属性

安装数: 23,203

依赖者: 1

建议者: 1

安全性: 0

星标: 3

关注者: 2

分支: 2

开放问题: 8

类型:sylius-plugin


README

Latest Version on Packagist Software License Build Status Quality Score

为您的产品添加成本价格属性。

安装

步骤 1:下载插件

打开命令行控制台,进入您的项目目录,并执行以下命令以下载此捆绑包的最新稳定版本

$ composer require setono/sylius-cost-price-plugin

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

步骤 2:启用插件

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

<?php
// config/bundles.php

return [
    // ...
    
    Setono\SyliusCostPricePlugin\SetonoSyliusCostPricePlugin::class => ['all' => true],
    
    // ...
];

步骤 4:导入产品变体特性

<?php
// src/Entity/ProductVariant.php

declare(strict_types=1);

namespace App\Entity;

use Setono\SyliusCostPricePlugin\Model\CostPriceAwareInterface;
use Setono\SyliusCostPricePlugin\Model\ProductVariantTrait as CostPriceProductVariantTrait;
use Sylius\Component\Core\Model\Product as BaseProduct;

/**
 * @ORM\Entity
 * @ORM\Table(name="sylius_product_variant")
 */
class ProductVariant extends BaseProduct implements CostPriceAwareInterface
{
    use CostPriceProductVariantTrait;
    
    // ...
}

注意:如果您尚未扩展 ProductVariant 实体,请首先按照定制说明进行操作,因为您需要添加更多配置。

步骤 5:更新您的数据库

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

步骤 6:将表单小部件添加到twig模板

您需要覆盖显示产品和产品变体表单的模板,并添加成本价格和成本价格货币的 form_row 语句

{# app/Resources/SyliusAdminBundle/views/ProductVariant/Tab/_details.html.twig #}

{# ... #}

<div class="ui segment">
    {{ form_row(form.code) }}
    <div class="two fields">
        {{ form_row(form.shippingCategory) }}
    </div>
    {# This is the part you should add #}
    <div class="four fields">
        {{ form_row(form.costPriceCurrency) }}
        {{ form_row(form.costPrice) }}
    </div>
    {# End of the part you should add #}
    {{ form_row(form.channelPricings) }}
</div>

{# ... #}
{# app/Resources/SyliusAdminBundle/views/Product/Tab/_details.html.twig #}

<div class="ui segment">
    {{ form_row(form.code) }}
    {{ form_row(form.enabled) }}
    {% if product.simple %}
        {{ form_row(form.variant.onHand) }}
        {{ form_row(form.variant.tracked) }}
        {{ form_row(form.variant.shippingRequired) }}
        {{ form_row(form.variant.version) }}
    {% else %}
        {{ form_row(form.options) }}
        {{ form_row(form.variantSelectionMethod) }}
    {% endif %}

    {# Nothing to see here. #}
    <div class="ui hidden element">
        {% if product.simple %}
            {# This is the part you should add #}
            <div class="two fields">
                {{ form_row(form.variant.costPriceCurrency) }}
                {{ form_row(form.variant.costPrice) }}
            </div>
            {# End of the part you should add #}
        
            {{ form_row(form.variant.translations) }}
        {% endif %}
        {{ form_row(form.variantSelectionMethod) }}
    </div>
</div>

如果您尚未覆盖模板,您可以直接将模板从 vendor/setono/sylius-cost-price-plugin/src/Resources/views/SyliusAdminBundle 复制到 app/Resources/SyliusAdminBundle/views/