Jump to content

Add/Replace EAN13 field on product combinations page


Recommended Posts

Hello, i am trying to replace the "Impact on price (tax excl.)" field with EAN13 field at the product combinations tab because it is easier to scan barcodes and add quantities for all combinations at one page. I chose to replace this field and not add a new one because i will probably never use it.

So far i managed to show the field I want at the place of Impact on Price by modifying form_combination.html.twig file. It reads the EAN13 for products that already have it, but if I try to add or modify EAN13 of a product when I save it i get an error (just save error not a lot of info).

At first i just replaced "Impact on price" with "EAN13" field and when I got this error I thought it was because the impact on price field was missing so I put it where EAN13 was, but still got the save error message. If i delete the EAN13 of a product and try to save it, it works. It just doesn't when I try to add new or replace the existing one. What is wrong with the code?

Here is a pic of where i put the EAN13 field

Below is the original code

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

which i replaced with

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

Complete final code looks like this

{#**
 * 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 [email protected] 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>

 

Link to comment
Share on other sites

I finally managed to get it working, so I am posting the solution. I know it is not 100% correct and not upgrade friendly, but it does the job really good if you want to add barcode to combinations fast. For anyone wondering this is the working code i ended up with :

<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>
        
                        <fieldset class="form-group">
                            {{ form_errors(form.attribute_ean13) }}
                            {{ form_widget(form.attribute_ean13) }}
                        </fieldset>
    </td>

Code starts in line 25 of form_combination.html.twig

I also change the table header name at form_combinations.html.twig so that it says Barcode

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...