添加/替换产品组合页面上的 EAN13 字段

问题描述

我正在尝试将产品组合选项卡中的“对价格的影响(不含税)”字段替换为 EAN13 字段,因为这样可以更轻松地扫描条形码并在一页上为所有组合添加数量。我选择替换此字段而不添加新字段,因为我可能永远不会使用它。

到目前为止,我通过修改 form_combination.html.twig 文件设法在影响价格的地方显示了我想要的字段。它读取已经拥有 EAN13 的产品的 EAN13,但是如果我在保存产品时尝试添加修改产品的 EAN13,我会收到一个错误(只保存错误而不是很多信息)。

起初我只是用“EAN13”字段替换了“Impact on price”,当我收到这个错误时,我认为这是因为缺少对价格字段的影响,所以我把它放在 EAN13 所在的位置,但仍然出现保存错误信息。如果我删除产品的 EAN13 并尝试保存它,它会起作用。当我尝试添加新的或替换现有的时,它不会。代码有什么问题?

Here is a pic of where i put the EAN13 field

下面是原代码

<tr class="combination loaded" id="attribute_{{ form.vars.value.id_product_attribute }}" data="{{ form.vars.value.id_product_attribute }}" data-index="{{ form.vars.value.id_product_attribute }}">
  <td width="1%"><input class="js-combination" type="checkBox" data-id="{{ form.vars.value.id_product_attribute }}" data-index="{{ form.vars.value.id_product_attribute }}"></td>
  <td class="img"><div class="fake-img"></div></td>
    <td>{{ form.vars.value.name }}</td>
    <td class="attribute-price">
        <div class="input-group">
            <div class="input-group-prepend">
                <span class="input-group-text">{{ default_currency }}</span>
            </div>
            <input type="text" class="attribute_priceTE form-control text-sm-right" value="{{ form.vars.value.attribute_price }}">
        </div>
    </td>

我替换为

<tr class="combination loaded" id="attribute_{{ form.vars.value.id_product_attribute }}" data="{{ form.vars.value.id_product_attribute }}" data-index="{{ form.vars.value.id_product_attribute }}">
  <td width="1%"><input class="js-combination" type="checkBox" data-id="{{ form.vars.value.id_product_attribute }}" data-index="{{ form.vars.value.id_product_attribute }}"></td>
  <td class="img"><div class="fake-img"></div></td>
    <td>{{ form.vars.value.name }}</td>
    <td class="attribute-price">
        <div class="input-group">
            <fieldset class="form-group">
                            <label class="form-control-label">
                              {{ form.attribute_ean13.vars.label }}
                            </label>
                            {{ form_errors(form.attribute_ean13) }}
                            {{ form_widget(form.attribute_ean13) }}
                        </fieldset>
        </div>
    </td>

最终代码如下

{#**
 * copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web,please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * disCLaimER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 *#}
<tr class="combination loaded" id="attribute_{{ form.vars.value.id_product_attribute }}" data="{{ form.vars.value.id_product_attribute }}" data-index="{{ form.vars.value.id_product_attribute }}">
  <td width="1%"><input class="js-combination" type="checkBox" data-id="{{ form.vars.value.id_product_attribute }}" data-index="{{ form.vars.value.id_product_attribute }}"></td>
  <td class="img"><div class="fake-img"></div></td>
    <td>{{ form.vars.value.name }}</td>
    <td class="attribute-price">
        <div class="input-group">
            <fieldset class="form-group">
                            <label class="form-control-label">
                              {{ form.attribute_ean13.vars.label }}
                            </label>
                            {{ form_errors(form.attribute_ean13) }}
                            {{ form_widget(form.attribute_ean13) }}
                        </fieldset>
        </div>
    </td>
    <td class="attribute-finalprice text-sm-right">
      <span data-price="{{ form.vars.value.final_price }}" data-uniqid="{{ form.vars.value.id_product_attribute }}">{{ form.vars.value.final_price }}</span> {{ default_currency }}
    </td>
    {% if 'PS_STOCK_MANAGEMENT'|configuration %}
      <td class="attribute-quantity">
          <div>
              <input type="text" value="{{ form.vars.value.attribute_quantity }}" class="form-control text-sm-right">
          </div>
      </td>
    {% endif %}

    <td class="attribute-actions">
        <div class="btn-group btn-group-sm" role="group">
            <a href="#combination_form_{{ form.vars.value.id_product_attribute }}" class="btn btn-open tooltip-link btn-sm"><i class="material-icons">mode_edit</i></a>
        </div>
        <div id="combination_form_{{ form.vars.value.id_product_attribute }}" data="{{ form.vars.value.id_product_attribute }}" class="combination-form hide row">
            <div class="col-sm-12 nav">
                {# "Prev." is short for "PrevIoUs" #}
                <a class="btn-sensitive prev"><i class="material-icons">keyboard_arrow_left</i> {{ 'Prev. combination'|trans({},'Admin.Catalog.Feature') }}</a>
                <a class="next btn-sensitive">{{ 'Next combination'|trans({},'Admin.Catalog.Feature') }} <i class="material-icons">keyboard_arrow_right</i></a>
            </div>
            <div class="panel col-md-12 p-2">
                <div class="float-left">
                    <button type="button" class="back-to-product btn btn-outline-secondary btn-back"><i class="material-icons">arrow_back</i> {{ 'Back to product'|trans({},'Admin.Catalog.Feature') }}</button>
                </div>
                <h2 class="title pt-2">
                  {{ "Combination details"|trans({},'Admin.Catalog.Feature') }} -
                  {{ form.vars.value.name }}
                </h2>
                {{ form_widget(form.attribute_default) }}
                <div class="row">
                  {% if 'PS_STOCK_MANAGEMENT'|configuration %}
                    <div class="col-md-2">
                      <fieldset class="form-group">
                          <label class="form-control-label">
                            {{ form.attribute_quantity.vars.label }}
                          </label>
                          {{ form_errors(form.attribute_quantity) }}
                          {{ form_widget(form.attribute_quantity) }}
                      </fieldset>
                    </div>
                  {% endif %}
                    <div class="col-md-3">
                      <fieldset class="form-group">
                          <label class="form-control-label">{{ form.available_date_attribute.vars.label }}</label>
                          {{ form_errors(form.available_date_attribute) }}
                          {{ form_widget(form.available_date_attribute) }}
                      </fieldset>
                    </div>
                    <div class="col-md-2">
                      <fieldset class="form-group">
                          <label class="form-control-label">
                            {{ form.attribute_minimal_quantity.vars.label }}
                            <span class="help-Box" data-toggle="popover"
                              data-content="{{ "The minimum quantity required to buy this product (set to 1 to disable this feature). E.g.: if set to 3,customers will be able to purchase the product only if they take at least 3 in quantity."|trans({},'Admin.Catalog.Help') }}" ></span>
                          </label>
                          {{ form_errors(form.attribute_minimal_quantity) }}
                          {{ form_widget(form.attribute_minimal_quantity) }}
                      </fieldset>
                    </div>
                    <div class="col-md-4">
                      <fieldset class="form-group">
                          <label class="form-control-label">{{ form.attribute_reference.vars.label }}</label>
                          {{ form_errors(form.attribute_reference) }}
                          {{ form_widget(form.attribute_reference) }}
                      </fieldset>
                    </div>
                </div>
                <h2 class="title">
                  {{ 'Stock'|trans({},'Admin.Catalog.Feature') }}
                </h2>
                <div class="row">
                  <div class="col-md-3">
                    <fieldset class="form-group">
                      <label class="form-control-label">{{ form.attribute_location.vars.label }}</label>
                      {{ form_errors(form.attribute_location) }}
                      {{ form_widget(form.attribute_location) }}
                    </fieldset>
                  </div>
                  <div class="col-md-3">
                    <fieldset class="form-group">
                      <label class="form-control-label">{{ form.attribute_low_stock_threshold.vars.label }}</label>
                      {{ form_errors(form.attribute_low_stock_threshold) }}
                      {{ form_widget(form.attribute_low_stock_threshold) }}
                    </fieldset>
                  </div>
                  <div class="col-md-9">
                    <fieldset class="form-group widget-checkBox-inline">
                      <label class="form-control-label">&nbsp;</label>
                      <div class="widget-checkBox-inline">
                        {{ form_errors(form.attribute_low_stock_alert) }}
                        {{ form_widget(form.attribute_low_stock_alert) }}
                        <span class="help-Box" data-toggle="popover" data-html="true" data-content="{{ "The email will be sent to all the users who have the right to run the stock page. To modify the permissions,go to [1]Advanced Parameters > Team[/1]"|trans({'[1]':'<a href=&quot;'~getAdminLink("Adminemployees")~'&quot;>','[/1]':'</a>'},'Admin.Catalog.Help')|raw }}" ></span>
                      </div>
                    </fieldset>
                  </div>
                </div>
                <h2 class="title">
                  {{ "Price and impact"|trans({},'Admin.Catalog.Feature') }}
                </h2>
                <div class="row">
                    <div class="col-md-3">
                        <fieldset class="form-group">
                            <label class="form-control-label">{{ form.attribute_wholesale_price.vars.label }}</label>
                            {{ form_errors(form.attribute_wholesale_price) }}
                            {{ form_widget(form.attribute_wholesale_price) }}
                        </fieldset>
                    </div>
                    <div class="col-md-3">
                        <fieldset class="form-group">
                            <label class="form-control-label">
                              {{ form.attribute_price.vars.label }}
                              <span class="help-Box" data-toggle="popover"
                                data-content="{{ "Does this combination have a different price? Is it cheaper or more expensive than the default retail price?"|trans({},'Admin.Catalog.Help') }}" ></span>
                            </label>
                            {{ form_errors(form.attribute_price) }}
                            {{ form_widget(form.attribute_price) }}
                        </fieldset>
                    </div>
                    <div class="col-md-3">
                        <fieldset class="form-group">
                            <label class="form-control-label">{{ form.attribute_priceTI.vars.label }}</label>
                            {{ form_errors(form.attribute_priceTI) }}
                            {{ form_widget(form.attribute_priceTI) }}
                        </fieldset>
                    </div>
                    <div class="col-md-3">
                      <small class="form-control-label vcenter">{{ "Final retail price (tax excl.) will be"|trans({},'Admin.Catalog.Feature') }} <span class="final-price" data-price="{{ form.vars.value.final_price }}" data-uniqid="{{ form.vars.value.id_product_attribute }}">{{ form.vars.value.final_price }}</span> {{ default_currency }}</small>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-3 {% if 'PS_USE_ECOTAX'|configuration != 1 %}hide{% endif %}">
                        <fieldset class="form-group">
                            <label class="form-control-label">{{ form.attribute_ecotax.vars.label }}</label>
                            {{ form_errors(form.attribute_ecotax) }}
                            {{ form_widget(form.attribute_ecotax) }}
                        </fieldset>
                    </div>
                    <div class="col-md-3">
                        <fieldset class="form-group">
                            <label class="form-control-label">
                              {{ form.attribute_unity.vars.label }}
                              <span class="help-Box" data-toggle="popover"
                                data-content="{{ "Does this combination have a different price per unit?"|trans({},'Admin.Catalog.Feature') }}" ></span>
                            </label>
                            {{ form_errors(form.attribute_unity) }}
                            {{ form_widget(form.attribute_unity) }}
                        </fieldset>
                    </div>
                    <div class="col-md-3">
                        <fieldset class="form-group">
                            <label class="form-control-label">{{ form.attribute_weight.vars.label }}</label>
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <span class="input-group-text">{{ 'PS_WEIGHT_UNIT'|configuration }}</span>
                                </div>
                                {{ form_errors(form.attribute_weight) }}
                                {{ form_widget(form.attribute_weight) }}
                            </div>
                        </fieldset>
                    </div>
                </div>
                <h2 class="title">
                  {{ "Specific references"|trans({},'Admin.Catalog.Feature') }}
                </h2>
                <div class="row">
                    <div class="col-md-4">
                        <fieldset class="form-group">
                            <label class="form-control-label">{{ form.attribute_isbn.vars.label }}</label>
                            {{ form_errors(form.attribute_isbn) }}
                            {{ form_widget(form.attribute_isbn) }}
                        </fieldset>
                    </div>
                    <div class="col-md-4">
                        <fieldset class="form-group">
                            <label class="form-control-label">
                              {{ form.attribute_ean13.vars.label }}
                              <span class="help-Box" data-toggle="popover"
                                data-content="{{ "This type of product code is specific to Europe and Japan,but is widely used internationally. It is a superset of the UPC code: all products marked with an EAN will be accepted in north America."|trans({},'Admin.Catalog.Help') }}" ></span>
                            </label>
                            {{ form_errors(form.attribute_ean13) }}
                            {{ form_widget(form.attribute_ean13) }}
                        </fieldset>
                    </div>
                    <div class="col-md-4">
                        <fieldset class="form-group">
                            <label class="form-control-label">{{ form.attribute_upc.vars.label }}</label>
                            {{ form_errors(form.attribute_upc) }}
                            {{ form_widget(form.attribute_upc) }}
                        </fieldset>
                    </div>
                    <div class="col-md-4">
                        <fieldset class="form-group">
                            <label class="form-control-label">{{ form.attribute_mpn.vars.label }}</label>
                            {{ form_errors(form.attribute_mpn) }}
                            {{ form_widget(form.attribute_mpn) }}
                        </fieldset>
                    </div>
                </div>
                <h2 class="title">
                  {{ "Images"|trans({},'Admin.Catalog.Feature') }}
                </h2>
                <div class="row">
                    <div class="col-md-12">
                        <fieldset class="form-group js-combination-images">
                            <label>
                                <small class="form-control-label">{{ form.id_image_attr.vars.label }}</small>
                                <small class="form-control-label number-of-images"></small>
                            </label>
                            {{ form_errors(form.id_image_attr) }}
                            {{ form_widget(form.id_image_attr) }}
                        </fieldset>
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-12">
                        {{ renderhook('displayAdminProductsCombinationBottom',{ 'id_product': form.vars.value.id_product,'id_product_attribute': form.vars.value.id_product_attribute }) }}
                    </div>
                </div>

                {{ form_widget(form.id_product_attribute) }}
            </div>
        </div>
    </td>
    <td width="5%">
      <a href="{{ path('admin_delete_attribute',{'idProduct': form.vars.value.id_product}) }}" class="btn tooltip-link btn-sm delete" data="{{ form.vars.value.id_product_attribute }}"><i class="material-icons">delete</i></a>
    </td>
    <td>
      {% set checked = form.vars.value.attribute_default == 1 ? 'checked' : '' %}
      <input class="attribute-default" type="radio" {{ checked }} data-id="{{ form.vars.value.id_product_attribute }}">
    </td>
</tr>

解决方法

我终于设法让它工作了,所以我发布了解决方案。我知道它不是 100% 正确并且不适合升级,但是如果您想快速将条形码添加到组合中,它的工作非常好。对于任何想知道这是我最终得到的工作代码的人:

Pulp Fiction
9.99
Jumanji
13.99
And so on...

代码从 form_combination.html.twig 的第 25 行开始

我还更改了 form_combinations.html.twig 中的表标题名称,使其显示为 Barcode