"un-group" Product Features - prestashop

In product-details.tpl the features, when grouped, are printed inside a single
For example:
<dl>
<dt>FEATURE</dt>
<dd>Value1 Value2 Value3</dd>
</dl>
I want to print the following:
Code:
<dl>
<dt>FEATURE</dt>
<dd>
<span title="value1">Value1</span>
<span title="value2">Value2</span>
<span title="value2">Value3</span>
</dd>
</dl>
This is the original code
{block name='product_features'}
{if $product.grouped_features}
<section>
<h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3>
<dl>
{foreach from=$product.grouped_features item=feature}
<dt>{$feature.name}</dt>
<dd>{$feature.value|escape:'htmlall'|nl2br nofilter}</dd>
{/foreach}
</dl>
</section>
{/if}
{/block}
I tried
{if $product.grouped_features}
<section>
<h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3>
<dl>
{foreach from=$product.grouped_features item=feature}
<dt>{$feature.name}</dt>
<dd>{foreach $feature.value}<span title="{$feature.value|replace:' ':'_'}">{$feature.value|escape:'htmlall'|nl2br nofilter}</span>{/foreach}</dd>
{/foreach}
</dl>
</section>
{/if}
But of course doesn't work..
Most grateful for any help possible.
Thank you

Try with:
{block name='product_features'}
{if $product.grouped_features}
<section>
<h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3>
<dl>
{foreach from=$product.grouped_features item=feature}
<dt>{$feature.name}</dt>
{assign var=detail_feature value="<br />"|explode:$feature.value}
<dd>
{foreach from=$detail_feature item=det_feature}
<span title="{$det_feature|escape:'htmlall'|nl2br nofilter}">{$det_feature|escape:'htmlall'|nl2br nofilter}</span>
{/foreach}
</dd>
{/foreach}
</dl>
</section>
{/if}
{/block}

Related

Display product availability on Prestashop 1.7.6 cart

I use Prestashop 1.7.6
I need to display the product availability on each product detail on Cart.
What have i to add to the cart-detailed-product-line.tpl and/or other files?
Try with:
{if (!$PS_CATALOG_MODE && $PS_STOCK_MANAGEMENT && ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
{if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}
<span itemprop="offers" itemscope itemtype="http://schema.org/Offer" class="availability">
{if ($product.allow_oosp || $product.quantity > 0)}
<span class="{if $product.quantity <= 0 && !$product.allow_oosp}out-of-stock{else}available-now{/if}">
<link itemprop="availability" href="http://schema.org/InStock" />{if $product.quantity <= 0}{if $product.allow_oosp}{if isset($product.available_later) && $product.available_later}{$product.available_later}{else}{l s='In Stock'}{/if}{else}{l s='Out of stock'}{/if}{else}{if isset($product.available_now) && $product.available_now}{$product.available_now}{else}{l s='In Stock'}{/if}{/if}
</span>
{elseif (isset($product.quantity_all_versions) && $product.quantity_all_versions > 0)}
<span class="available-dif">
<link itemprop="availability" href="http://schema.org/LimitedAvailability" />{l s='Product available with different options'}
</span>
{else}
<span class="out-of-stock">
<link itemprop="availability" href="http://schema.org/OutOfStock" />{l s='Out of stock'}
</span>
{/if}
</span>
{/if}
{/if}
Add it where you want to display this information.
**UPDATE*
Try with this code:
<div class="product-line-grid">
<!-- product left content: image-->
<div class="product-line-grid-left col-md-3 col-xs-3">
<span class="product-image media-middle">
<img src="{$product.cover.bySize.cart_default.url}" alt="{$product.name|escape:'quotes'}">
</span>
</div>
<!-- product left body: description -->
<div class="product-line-grid-body col-md-4 col-xs-6">
<div class="product-line-info">
<a class="label" href="{$product.url}" data-id_customization="{$product.id_customization|intval}">{$product.name}</a>
</div>
<div class="product-line-info product-price h5 {if $product.has_discount}has-discount{/if}">
{if $product.has_discount}
<div class="product-discount">
<span class="regular-price">{$product.regular_price}</span>
<!--{if $product.discount_type === 'percentage'}
<span class="discount discount-percentage">
-{$product.discount_percentage_absolute}
</span>
{else}
<span class="discount discount-amount">
-{$product.discount_to_display}
</span>
{/if}-->
</div>
{/if}
<!--<div class="current-price">
<span class="price">{$product.price}</span>
{if $product.unit_price_full}
<div class="unit-price-cart">{$product.unit_price_full}</div>
{/if}
</div>-->
{if (!$PS_CATALOG_MODE && $PS_STOCK_MANAGEMENT && ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
{if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}
<span itemprop="offers" itemscope itemtype="http://schema.org/Offer" class="availability">
{if ($product.allow_oosp || $product.quantity > 0)}
<span class="{if $product.quantity <= 0 && !$product.allow_oosp}out-of-stock{else}available-now{/if}">
<link itemprop="availability" href="http://schema.org/InStock" />{if $product.quantity <= 0}{if $product.allow_oosp}{if isset($product.available_later) && $product.available_later}{$product.available_later}{else}{l s='In Stock'}{/if}{else}{l s='Out of stock'}{/if}{else}{if isset($product.available_now) && $product.available_now}{$product.available_now}{else}{l s='In Stock'}{/if}{/if}
</span>
{elseif (isset($product.quantity_all_versions) && $product.quantity_all_versions > 0)}
<span class="available-dif">
<link itemprop="availability" href="http://schema.org/LimitedAvailability" />{l s='Product available with different options'}
</span>
{else}
<span class="out-of-stock">
<link itemprop="availability" href="http://schema.org/OutOfStock" />{l s='Out of stock'}
</span>
{/if}
</span>
{/if}
{/if}
</div>
<br/>
{foreach from=$product.attributes key="attribute" item="value"}
<div class="product-line-info">
<span class="label">{$attribute}:</span>
<span class="value">{$value}</span>
</div>
{/foreach}
<div class="col-md-2 col-xs-6 text-xs-right delete">
<div class="cart-line-product-actions">
<a
class = "remove-from-cart"
rel = "nofollow"
href = "{$product.remove_from_cart_url}"
data-link-action = "delete-from-cart"
data-id-product = "{$product.id_product|escape:'javascript'}"
data-id-product-attribute = "{$product.id_product_attribute|escape:'javascript'}"
data-id-customization = "{$product.id_customization|escape:'javascript'}"
>
{if !isset($product.is_gift) || !$product.is_gift}
<span class="float-xs-left"><!--<i class="material-icons">delete_forever</i>-->Rimuovi</span>
{/if}
</a>
{block name='hook_cart_extra_product_actions'}
{hook h='displayCartExtraProductActions' product=$product}
{/block}
</div>
</div>
{if is_array($product.customizations) && $product.customizations|count}
<br>
{block name='cart_detailed_product_line_customization'}
{foreach from=$product.customizations item="customization"}
{l s='Product customization' d='Shop.Theme.Catalog'}
<div class="modal fade customization-modal" id="product-customizations-modal-{$customization.id_customization}" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">{l s='Product customization' d='Shop.Theme.Catalog'}</h4>
</div>
<div class="modal-body">
{foreach from=$customization.fields item="field"}
<div class="product-customization-line row">
<div class="col-sm-3 col-xs-4 label">
{$field.label}
</div>
<div class="col-sm-9 col-xs-8 value">
{if $field.type == 'text'}
{if (int)$field.id_module}
{$field.text nofilter}
{else}
{$field.text}
{/if}
{elseif $field.type == 'image'}
<img src="{$field.image.small.url}">
{/if}
</div>
</div>
{/foreach}
</div>
</div>
</div>
</div>
{/foreach}
{/block}
{/if}
</div>
<!-- product left body: description -->
<div class="product-line-grid-right product-line-actions col-md-5 col-xs-3">
<div class="row">
<!--<div class="col-xs-4 hidden-md-up"></div>-->
<div class="col-md-10 col-xs-12">
<div class="row">
<div class="col-md-6 col-xs-12 price">
<span class="product-price">
<strong>
{if isset($product.is_gift) && $product.is_gift}
<span class="gift">{l s='Gift' d='Shop.Theme.Checkout'}</span>
{else}
{$product.total}
{/if}
</strong>
</span>
</div>
<div class="col-md-6 col-xs-12 qty">
{if isset($product.is_gift) && $product.is_gift}
<span class="gift-quantity">{$product.quantity}</span>
{else}
<input
class="js-cart-line-product-quantity"
data-down-url="{$product.down_quantity_url}"
data-up-url="{$product.up_quantity_url}"
data-update-url="{$product.update_quantity_url}"
data-product-id="{$product.id_product}"
type="number"
value="{$product.quantity}"
name="product-quantity-spin"
min="{$product.minimal_quantity}"
/>
{/if}
</div>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>

how to pass the variable product.tpl or modal.tpl in in prestashoap 1.7

I have a problem that I can not solve. in prestashop 1.7 I have a tpl file called product.tpl where inside, besides the various data, I call a file with the following code:
`{block name='product_variants'}
{include file='catalog/_partials/product-variants.tpl'}
{/block}
{block name='product_miniature_item'}
<article class="product-miniature js-product-miniature" data-id-product="{$product.id_product}" data-id-product-attribute="{$product.id_product_attribute}" itemscope itemtype="http://schema.org/Product">
<div class="thumbnail-container">
{block name='product_thumbnail'}
<a href="{$product.url}" class="thumbnail product-thumbnail">
<img
src = "{$product.cover.bySize.home_default.url}"
alt = "{if !empty($product.cover.legend)}{$product.cover.legend}{else}{$product.name|truncate:30:'...'}{/if}"
data-full-size-image-url = "{$product.cover.large.url}"
>
</a>
{/block}
<div class="product-description">
{block name='product_name'}
<h1 class="h3 product-title" itemprop="name">{$product.name|truncate:30:'...'}</h1>
{/block}
{block name='product_price_and_shipping'}
{if $product.show_price}
<div class="product-price-and-shipping">
{if $product.has_discount}
{hook h='displayProductPriceBlock' product=$product type="old_price"}
<span class="sr-only">{l s='Regular price' d='Shop.Theme.Catalog'}</span>
<span class="regular-price">{$product.regular_price}</span>
{if $product.discount_type === 'percentage'}
<span class="discount-percentage">{$product.discount_percentage}</span>
{/if}
{/if}
{hook h='displayProductPriceBlock' product=$product type="before_price"}
<span class="sr-only">{l s='Price' d='Shop.Theme.Catalog'}</span>
<span itemprop="price" class="price">{$product.price}</span>
{hook h='displayProductPriceBlock' product=$product type='unit_price'}
{hook h='displayProductPriceBlock' product=$product type='weight'}
<div class="add">
<form action="{$urls.pages.cart}" method="post">
<input type="hidden" value="{$product.id_product}" name="id_product">
<!--<input type="number" style="padding: 3px 13px; float:left; width:30%; margin-left: 10px;" class="input-group form-control" name="qty" min="1" value="1">-->
<a style="cursor: pointer; padding: 3px 13px; margin-left: 10px; background: #ff9600; color: #fff;" data-button-action="add-to-cart" class="addtocart-btn"
{if !$product.add_to_cart_url}
disabled
{/if}>
<i class="material-icons shopping-cart"></i>
{l s='Add' d='Shop.Theme.Actions'}
<a href="{$product.url}" style=" padding: 3px 13px; margin-left: 10px;" class="view-dtls-btn">
{if {$language.iso_code} === 'ar'}
{l s='رأي' d='Shop.Theme.Actions'}
{else}
{l s='View' d='Shop.Theme.Actions'}
{/if}
</a>
</form>
</div>
</div>
{/if}
{/block}
{block name='product_reviews'}
{hook h='displayProductListReviews' product=$product}
{/block}
</div>
{block name='product_flags'}
<ul class="product-flags">
{foreach from=$product.flags item=flag}
<li class="product-flag {$flag.type}">{$flag.label}</li>
{/foreach}
</ul>
{/block}
<div class="highlighted-informations{if !$product.main_variants} no-variants{/if} hidden-sm-down">
{block name='quick_view'}
<a class="quick-view" href="#" data-link-action="quickview">
<i class="material-icons search"></i> {l s='Quick view' d='Shop.Theme.Actions'}
</a>
{/block}
{block name='product_variants'}
{if $product.main_variants}
{include file='catalog/_partials/variant-links.tpl' variants=$product.main_variants}
{/if}
{/block}
</div>
</div>
</article>
{/block}`
and everything works correctly.
what interests me most specifically is the portion of code referred to in this block
{block name='product_variants'}
{include file='catalog/_partials/product-variants.tpl'}
{/block}
The code is:
`<div class="product-variants">
{foreach from=$groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
<span class="control-label">{$group.name}</span>
{if $group.group_type == 'select'}
<select
class="form-control form-control-select"
id="group_{$id_attribute_group}"
data-product-attribute="{$id_attribute_group}"
name="group[{$id_attribute_group}]">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
{/foreach}
</select>
{elseif $group.group_type == 'color'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
{/foreach}
</ul>
{elseif $group.group_type == 'radio'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="input-container float-xs-left">
<label>
<input class="input-radio" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span class="radio-label">{$group_attribute.name}</span>
</label>
</li>
{/foreach}
</ul>
{/if}
</div>
{/foreach}
</div>`
then I modified the tpl file of the module product.tpl and modal.tpl and inside the main file "product.tpl and modal.tpl", inside the foreach I inserted a part of the code to display the variants and some product html design.
what happens is that I visualize perfectly the formatting but all the values ​​of the variants do not let me see them, specifically this portion of code does not work`<div class="product-variants">
{foreach from=$groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
<span class="control-label">{$group.name}</span>
{if $group.group_type == 'select'}
<select
class="form-control form-control-select"
id="group_{$id_attribute_group}"
data-product-attribute="{$id_attribute_group}"
name="group[{$id_attribute_group}]">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
{/foreach}
</select>
{elseif $group.group_type == 'color'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
{/foreach}
</ul>
{elseif $group.group_type == 'radio'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="input-container float-xs-left">
<label>
<input class="input-radio" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span class="radio-label">{$group_attribute.name}</span>
</label>
</li>
{/foreach}
</ul>
{/if}
</div>
{/foreach}
</div>`
Obviously the same code in the product page recalls all the variables, while in the home where I recall the contents on the homepage I can not recover them. Where am I wrong? I put hands on prestashop only a few weeks ago and I think I have a confused ideas. I hope little I have been clear, thanks to those who have the patience to answer.
or optional we want to pass the $groups variable in modal.tpl inside ps_shoppingcart please help me..
thnx in advance

How to add google adsense code in prestashop 1.7 footer?

How can we add google Adsense code in my PrestaShop 1.7 footer?
Just go to this file /themes/classic/templates/_partials/footer.tpl
Then enter like this it will work
<div class="container">
<div class="row">
{block name='hook_footer_before'}
{hook h='displayFooterBefore'}
{/block}
</div>
</div>
<div class="footer-container">
<div class="container">
<div class="row">
{block name='hook_footer'}
{hook h='displayFooter'}
{/block}
</div>
<div class="row">
{block name='hook_footer_after'}
{hook h='displayFooterAfter'}
{/block}
</div>
<div class="row">
<div class="col-md-12">
<p class="text-sm-center">
{block name='copyright_link'}
<a class="_blank" href="#" target="_blank">
{l s='%copyright% 2010 - %year% - Shop by %prestashop%' sprintf=['%prestashop%' => 'DICE','%year%' => 'Y'|date, '%copyright%' => '©'] d='Shop.Theme.Global'}
</a>
{/block}
</p>
</div>
</div>
</div>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:block; text-align:center;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="xxxxxxxx"
data-ad-slot="xxxxxxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
For the reference you can check my website https://diceindiagroup.net

Prestashop 1.7 template not pass variable

I have a problem that I can not solve.
in prestashop 1.7 I have a tpl file called product.tpl where inside, besides the various data, I call a file with the following code:
<div class="product-actions">
{block name='product_buy'}
<form action="{$urls.pages.cart}" method="post" id="add-to-cart-or-refresh">
<input type="hidden" name="token" value="{$static_token}">
<input type="hidden" name="id_product" value="{$product.id}" id="product_page_product_id">
<input type="hidden" name="id_customization" value="{$product.customization_id}" id="product_customization_id">
{block name='product_variants'}
{include file='catalog/_partials/product-variants.tpl'}
{/block}
{block name='product_pack'}
{if $packItems}
<section class="product-pack">
<h3 class="h4">{l s='This pack contains' d='Shop.Theme.Catalog'}</h3>
{foreach from=$packItems item="product_pack"}
{block name='product_miniature'}
{include file='catalog/_partials/miniatures/pack-product.tpl' product=$product_pack}
{/block}
{/foreach}
</section>
{/if}
{/block}
{block name='product_discounts'}
{include file='catalog/_partials/product-discounts.tpl'}
{/block}
{block name='product_add_to_cart'}
{include file='catalog/_partials/product-add-to-cart.tpl'}
{/block}
{block name='product_additional_info'}
{include file='catalog/_partials/product-additional-info.tpl'}
{/block}
{block name='product_refresh'}
<input class="product-refresh ps-hidden-by-js" name="refresh" type="submit" value="{l s='Refresh' d='Shop.Theme.Actions'}">
{/block}
</form>
{/block}
</div>
and everything works correctly.
what interests me most specifically is the portion of code referred to in this block
{block name='product_variants'}
{include file='catalog/_partials/product-variants.tpl'}
{/block}
The code is:
<div class="product-variants">
{foreach from=$groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
<span class="control-label">{$group.name}</span>
{if $group.group_type == 'select'}
<select
class="form-control form-control-select"
id="group_{$id_attribute_group}"
data-product-attribute="{$id_attribute_group}"
name="group[{$id_attribute_group}]">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
{/foreach}
</select>
{elseif $group.group_type == 'color'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
{/foreach}
</ul>
{elseif $group.group_type == 'radio'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="input-container float-xs-left">
<label>
<input class="input-radio" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span class="radio-label">{$group_attribute.name}</span>
</label>
</li>
{/foreach}
</ul>
{/if}
</div>
{/foreach}
</div>
then I modified the tpl file of the module ps_featuredproducts and inside the main file "ps_featuredproducts.tpl", inside the foreach I inserted a part of the code to display the variants and some product html design.
what happens is that I visualize perfectly the formatting but all the values ​​of the variants do not let me see them, specifically this portion of code does not work
<div class="product-variants">
{foreach from=$groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
<span class="control-label">{$group.name}</span>
{if $group.group_type == 'select'}
<select
class="form-control form-control-select"
id="group_{$id_attribute_group}"
data-product-attribute="{$id_attribute_group}"
name="group[{$id_attribute_group}]">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
{/foreach}
</select>
{elseif $group.group_type == 'color'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
{/foreach}
</ul>
{elseif $group.group_type == 'radio'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="input-container float-xs-left">
<label>
<input class="input-radio" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span class="radio-label">{$group_attribute.name}</span>
</label>
</li>
{/foreach}
</ul>
{/if}
</div>
{/foreach}
</div>
Obviously the same code in the product page recalls all the variables, while in the home where I recall the contents on the homepage I can not recover them. Where am I wrong? I put hands on prestashop only a few weeks ago and I think I have a confused ideas.
I hope little I have been clear, thanks to those who have the patience to answer.
The variable $groups does not exist in ps_featuredproducts. You have to add it to the module if you want to use it on your home page.
In order to do that, you have to modify function getWidgetVariables() in ps_featuredproducts.php like this.
public function getWidgetVariables($hookName = null, array $configuration = [])
{
$products = $this->getProducts();
foreach ($products as &$product) {
$product_object = new Product((int)$product['id_product']);
$groups = array();
$attributes_groups = $product_object->getAttributesGroups($this->context->language->id);
if (is_array($attributes_groups) && $attributes_groups) {
foreach ($attributes_groups as $k => $row) {
if (!isset($groups[$row['id_attribute_group']])) {
$groups[$row['id_attribute_group']] = array(
'group_name' => $row['group_name'],
'name' => $row['public_group_name'],
'group_type' => $row['group_type'],
'default' => -1,
);
}
$groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = array(
'name' => $row['attribute_name'],
'html_color_code' => $row['attribute_color'],
'texture' => (#filemtime(_PS_COL_IMG_DIR_.$row['id_attribute'].'.jpg')) ? _THEME_COL_DIR_.$row['id_attribute'].'.jpg' : '',
'selected' => (isset($product_for_template['attributes'][$row['id_attribute_group']]['id_attribute']) && $product_for_template['attributes'][$row['id_attribute_group']]['id_attribute'] == $row['id_attribute']) ? true : false,
);
if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1) {
$groups[$row['id_attribute_group']]['default'] = (int) $row['id_attribute'];
}
if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) {
$groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0;
}
$groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += (int) $row['quantity'];
}
// wash attributes list (if some attributes are unavailables and if allowed to wash it)
if (!Product::isAvailableWhenOutOfStock($product_object->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) {
foreach ($groups as &$group) {
foreach ($group['attributes_quantity'] as $key => &$quantity) {
if ($quantity <= 0) {
unset($group['attributes'][$key]);
}
}
}
}
}
$product['groups'] = $groups;
}
if (!empty($products)) {
return array(
'products' => $products,
'allProductsLink' => Context::getContext()->link->getCategoryLink($this->getConfigFieldsValues()['HOME_FEATURED_CAT']),
);
}
return false;
}
I am using here a part of the code from the function ProductController::assignAttributesGroups() to get only $groups variable.
Finally, in ps_featuredproducts.tpl, you have to replace:
<div class="product-variants">
{foreach from=$groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
By:
<div class="product-variants">
{foreach from=$product.groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
And then, all variables will be displayed like on product page.
The variable $groups that is used in catalog/_partials/product-variants.tpl is passed from PoductController.php and is available only on product info page. You cannot use it on your homepage or elsewhere. If you want to achieve the same result you need to create some similar variable within your module and pass it to your own template. The variable created in the file controller/front/ProductController.php within method assignAttributesGroups but it is pretty complicated I think you can create something much simpler.

How to print addition value in smarty template?

I've following smarty code:
<ul class="list-group">
{if $user_package_type_documents}
{assign var=cnt value=0}
{foreach from=$user_package_type_documents item='my_package_type_documents'}
{if $my_package_type_documents.pt_doc_file_iname != ""}
<li class="list-group-item test-series-item-ul-my-doc">
<div class="col-xs-7" style="">
<div class="test-series-heading-doc">
<span>{$cnt + 1})</span><span>{$my_package_type_documents.pt_doc_title}</span>
</div>
</div>
<div class="col-xs-5" style="">
<div class="vr-outter-div">
DOWNLOAD
</div>
</div>
</li>
{assign var=cnt value=$cnt+1}
{/if}
{/foreach}
{if $cnt == 0}
<li class="list-group-item test-series-item-ul-my-doc">
<div class="col-xs-7" style="">
<div class="test-series-heading-doc">
<span></span><span>Document Not Available.</span>
</div>
</div>
<div class="col-xs-5" style="">
<div class="vr-outter-div">
</div>
</div>
</li>
{/if}
{else}
<li class="list-group-item test-series-item-ul-my-doc">
<div class="col-xs-7" style="">
<div class="test-series-heading-doc">
<span></span><span>Document Not Available.</span>
</div>
</div>
<div class="col-xs-5" style="">
<div class="vr-outter-div">
</div>
</div>
</li>
{/if}
</ul>
In above code I want to print the values from 1 till the values come. For it I wrote the code {$cnt + 1} but still it's printing the value from 0. How to print this from 1? Also the initialization shouldn't be changed i.e. it should initialize to zero as it is now. Thank you.
In smarty you can't have whitespace in addition operation, so {$cnt + 1} won't work but {$cnt+1} should (you even do that later on).
Anyway if I understand what're trying to accomplish here, I think you can do it differently. First when you're looping over user_package_type_documents variable you can define loop name , so you'll be able to reference iteration number. That way you'll have those orderly numbers in your document list. In case your array is empty you can either set a condition checking it's count or add foreachelse clause that would replace that {if $cnt == 0}.