Jump to content
thirty bees forum

How to add an extra field on product page


zimmer-media

Recommended Posts

step 1 Add an entry to the database in the table prefix_product (for example name and lenght - what you need)

0_1514159821465_5ae550fd-3379-49ab-9281-d0909e99e80f-grafik.png

step 2.1 modify the file “Product.php” from “/classes/Product.php”, preferably in the folder classes Override “/override/classes/Product.php” save see the lines /** @var int Supplier id */ public $id_supplier; /** @var int default Category id */ public $id_category_default; /** @var int default Shop id */ public $id_shop_default; /** @var string Manufacturer name */ public $manufacturer_name; just add the following /** @var string new_field */ public $new_field; step 2.2 for example find 'id_supplier' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId'], 'reference' => ['type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 32], after this add 'new_field' => ['type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 200], step 3 copy your informations.tpl under override / controllers / admin / templates / products / informations.tpl for example and find the code (depending on where this additional field should appear.) <div class="form-group"> <div class="col-lg-1"><span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="name" type="default" multilang="true"}</span></div> <label class="control-label col-lg-2 required" for="name_{$id_lang}"> <span class="label-tooltip" data-toggle="tooltip" title="{l s='The public name for this product.'} {l s='Invalid characters:'} &lt;&gt;;=#{}"> {l s='Name'} </span> </label> <div class="col-lg-5"> {include file="controllers/products/input_text_lang.tpl" languages=$languages input_class="{$class_input_ajax}{if !$product->id || Configuration::get('PS_FORCE_FRIENDLY_PRODUCT')}copy2friendlyUrl{/if} updateCurrentText" input_value=$product->name input_name="name" required=true } </div> </div> after this insert <div class="form-group"> <div class="col-lg-1"><span class="pull-right">{include file="controllers/products/multishop/checkbox.tpl" field="name" type="default" multilang="true"}</span></div> <label class="control-label col-lg-2"> <span class="label-tooltip" data-toggle="tooltip" title="{l s='The additional field for your product'} {l s='Invalid characters:'} &lt;&gt;;=#{}"> {l s='New Field'} </span> </label> <div class="col-lg-5"> <input type="text" id="new_field" name="new_field" value="{$product->new_field|default:''}"/> </div> </div> step 4 if you want to see this field in your frontoffice product view - in your theme product.tpl add the follow code with h1-6 tag or p tag in your tpl {$product->new_field|escape:'html':'UTF-8'}

product admin 0_1514161186516_9fbcf2bd-759e-47b4-b6db-947f039a4ab1-grafik.png

product front office before 1_1514161289031_Screenshot-2017-12-25 Soap.png0_1514161289031_Screenshot-2017-12-25 Candle.png

product front office after changes 1_1514161355504_Screenshot-2017-12-25 Soap1.png0_1514161355504_Screenshot-2017-12-25 Candle1.png

  • Thanks 1
Link to comment
Share on other sites

  • 2 years later...
  • 1 year later...

Another way to add pack weight width depth & height to the product template (product.tpl).

This works for information that's already available without new fields in the database and with only a change to the product.tpl file, if your theme doesn't use it already. It doesn't add a box that customers can fill-in.

In the product.tpl file, under the cart forms ending in {/if} and before the next section starting {if...}, cut and paste:

        pack ■ {sprintf("%.2f",$product->weight)} kg,  

        ↔ {sprintf("%.1f",$product->width)} cm,  

        ⤢ {sprintf("%.1f",$product->depth)} cm,  

        ↕ {sprintf("%.1f",$product->height)} cm,<br>

Best to copy the /product.tpl file from /themes/themename/product.tpl to /themes/themename/templates/products/product.tpl (next to product-wide.tpl) and select it for each product, or find some other way of saving it from theme updates.

On a fresh install there are probably no shipping details set for sample products, so the result reads like this, just below the order form and above the sharing and print icons.

pack ■ 0.00 kg, ↔ 0.0 cm, ⤢ 0.0 cm, ↕ 0.0 cm,

That's it!

---------------------------------------------------------------------
Elaboration:

This also works for {sprintf($id_product)} for product id.

On a test site, typing {debug} at the top of the template reveals all the variables available this way, but there aren't many. The zimmer media post works much harder at adapting other files so more is available. Or maybe they did it by witchcraft.  I don't know.

---------------------------------------------------------------------
Elaboration:

On  my own page, I tried adding a schema tag round each variable, as part of a product and offer schema on the page, as well as a title to be on the safe side. I don't know if it helped or not, but it looks like this

            pack ■ <span title="shipping_weight" itemprop="weight">{sprintf("%.2f",$product->weight)} kg</span>,
            
            ↔ <span title="shipping_width" itemprop="width">{sprintf("%.1f",$product->width)} cm</span>,
            
            ⤢ <span title="shipping_depth" itemprop="depth">{sprintf("%.1f",$product->depth)} cm</span>,
            
            ↕ <span title="shipping_height" itemprop="height">{sprintf("%.1f",$product->height)} cm</span>,<br>

---------------------------------------------------------------------
Elaboration:
https://forum.thirtybees.com/topic/5112-how-to-add-a-feature-with-markup-round-it-to-the-product-page/
says  how to show on specific feature on your product page so you can put tags round that as well

---------------------------------------------------------------------
Elaboration:
google shopping flux version 7.4 can post this data into a product feed. There's a switch on the module.

Edited by veganline
Link to comment
Share on other sites

I copied some tags from the "microdata" example on schema.org/product at the top and bottom of the page

  1. <div itemscope itemtype="https://schema.org/Product">
    .... most of the product.tpl page ...
    </div>
    https://validator.schema.org/ finds the weights OK but
    https://search.google.com/search-console/ has a line at the bottom for "unparsable structured data" ... maybe that explains some of the other errors

    Error Invalid value in field 'itemtype'

    There's nothing about sizes; I think the spider missed them altogether.

    Error    197 items
    Error    Either 'offers', 'review' or 'aggregateRating' should be specified 
    Error    Invalid object type for field 'name' 
    Error    Missing field 'name' 

    Valid with Warnings 67 items
    Warning    No global identifier provided (e.g. gtin, mpn, isbn) 
    Warning    Missing field 'brand'
    Warning    Invalid object type for field 'brand' (I tried putting country of origen as brand)
    Warning    Missing field 'sku' 
    Warning    Missing field 'priceValidUntil' (this is true)
    Warning    Missing field 'aggregateRating' (this is true)
    Warning    Missing field 'review' (this is true)
    Warning    Missing field 'url'
    Warning    Missing field 'availability'
    Warning    Missing field 'image' N/A
    Warning    Missing field 'description'

    It looks as though I am not getting everything right. 
    merchants.google.com used to do scans and got the thumbnail pictures mixed-up with the full sized ones as well.

    So - mixed result!
Edited by veganline
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...