Display features product on category page - prestashop

I am looking to display the characteristics of a product under prestashop in the category page on each product thumbnail display. Do you have any idea how is it possible to do this?
Thank you for your help.

In file \themes\default-bootstrap\product-list.tpl there is
{foreach from=$products item=product name=products}
After that add this:
{$product|#print_r}
Then You have all product data with characteristics. This code above dispaly all variable which is return by controller. You just need to display what You want.

its ok solution like this:
<div class="features">
{foreach from=$product.features item=feature}
{if $feature.name == 'Contenance'}
<div class="row">
<span><img src="{$img_dir}arrow-right-purple-2.png"
class="left_arrow"/>{$feature.value}</span>
</div>
{/if}
{if $feature.name == 'Couleur'}
<div class="row">
<span><img src="{$img_dir}arrow-right-purple-2.png"
class="left_arrow"/>{$feature.value}</span>
</div>
{/if}
{/foreach}
</div>
Thanks

Related

Prestashop: Hide categories without products

I would like to know if there's a way to hide categories whose sub-categories' products are out of stock.
The file with the code to show the categories is "ps_mainmenu.tpl", whose code is attached
Thanks in advance
Ive tried with some modules like "block-categories-with-counter" but it doesn't work
{assign var=_counter value=0}
{function name="menu" nodes=[] depth=0 parent=null}
{if $nodes|count}
<ul class="top-menu top-menu--level-{$depth}" {if $depth == 0}id="top-menu"{/if} data-depth="{$depth}">
{foreach from=$nodes item=node}
<li class="category-custom category-custom--level-{$depth} {$node.type}{if $node.current} current {/if}" id="{$node.page_identifier}">
{assign var=_counter value=$_counter+1}
<a
class="{if $depth >= 0}dropdown-item{/if}{if $depth === 1} dropdown-submenu{/if}"
href="{$node.url}" data-depth="{$depth}"
{if $node.open_in_new_window} target="_blank" {/if}
>
{if $node.children|count}
{* Cannot use page identifier as we can have the same page several times *}
{assign var=_expand_id value=10|mt_rand:100000}
<span class="float-xs-right hidden-md-up">
<span data-target="#top_sub_menu_{$_expand_id}" data-toggle="collapse" class="navbar-toggler collapse-icons">
<i class="material-icons add"></i>
<i class="material-icons remove"></i>
</span>
</span>
{/if}
{$node.label}
</a>
{if $node.children|count}
<div {if $depth === 0} class="popover sub-menu js-sub-menu collapse"{else} class="collapse"{/if} id="top_sub_menu_{$_expand_id}">
{menu nodes=$node.children depth=$node.depth parent=$node}
</div>
{/if}
</li>
{/foreach}
</ul>
{/if}
{/function}
<div class="menu js-top-menu position-static hidden-sm-down" id="_desktop_top_menu">
{menu nodes=$menu.children}
<div class="clearfix"></div>
</div>
You need to remove empty category in the SQL query, so in your php wrap your code with something like that :
$count = Db::getInstance()->getValue('SELECT COUNT(cp.id_category) FROM '._DB_PREFIX_.'category_product cp, '._DB_PREFIX_.'product pr WHERE cp.id_category = '.$id_current_category .' AND cp.id_product = pr.id_product AND pr.active = 1' );
if($count>0)
{
//your actual code to get the category
}

How can I set a price for custom text?

Is there a way to add price if the client add the custom text (the one inside the Options section when you add the product) in a product? or have I to add it by product combinations (adding a lot of combinations)?
With the input radio I can't control what the user will do and I can't set it as "required" because it must be a free choice.
{block name='product_customization_form'}
<form method="post" action="{$product.url}" enctype="multipart/form-data">
<ul class="clearfix">
{foreach from=$customizations.fields item="field"}
<li class="product-customization-item">
<label> {$field.label}</label>
{if $field.type == 'text'}
<textarea placeholder="{l s='Your message here' d='Shop.Forms.Help'}" class="product-message" maxlength="250" {if $field.required} required {/if} name="{$field.input_name}"></textarea>
<small class="float-xs-right">{l s='250 char. max' d='Shop.Forms.Help'}</small>
{if $field.text !== ''}
<h6 class="customization-message">{l s='Your customization:' d='Shop.Theme.Catalog'}
<label>{$field.text}</label>
</h6>
{/if}
</li>
{/foreach}
</ul>
<div class="clearfix">
<button class="btn btn-primary float-xs-right" type="submit" name="submitCustomizedData">{l s='Save Customization' d='Shop.Theme.Actions'}</button>
</div>
</form>
{/block}
The best way to achieve this would be to have two product combinations:
With custom text (+$0)
Without custom text (+$1.00)
Next, add some custom Javascript code to your product page (the proper way would be via a module) that would do the following:
Check if the customization textarea element is present on the page
Check if it is empty or not
If not, force the combination ID to the right ID (the "with customization" version)
That's it.
That way, the buyer won't have to select any option, they just have to fill a custom text if they would like to and the price will adjust automatically in their shopping cart.
I hope this helps!

display subcategories from category ID - Prestashop 1.7

I'd like to show all subcategory of category on homepage in prestashop 1.7
I was create this functions but it's show only 1 deep child subcategory:
How to set forech all subcategory from category ID 231?
$categories shows only main categories, no subcategories.
{if isset($categories) AND $categories}
<div id="subcategories">
<ul class="clearfix">
{foreach from=$categories item=subcategory name=homeCategories}<li>
<div class="subcategory-image">
<a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}"
title="{$subcategory.name|escape:'html':'UTF-8'}" class="img">
{if $subcategory.id_image}
<img class="replace-2x"
src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'category_default')|escape:'html':'UTF-8'}"
alt="" width="{$mediumSize.width|escape:'htmlall':'UTF-8'}" height="{$mediumSize.height|escape:'htmlall':'UTF-8'}"/>
{else}
<img class="replace-2x" src="{$img_cat_dir|escape:'htmlall':'UTF-8'}{$lang_iso|escape:'htmlall':'UTF-8'}-default-medium_default.jpg"
alt="" width="{$mediumSize.width|escape:'htmlall':'UTF-8'}" height="{$mediumSize.height|escape:'htmlall':'UTF-8'}"/>
{/if}
</a>
</div>
<h5><a class="subcategory-name"
href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}">{$subcategory.name|truncate:60:'...'|escape:'html':'UTF-8'}</a>
</h5>
</li>{/foreach}
</ul class="clearfix">
</div>
{else}
<p>{l s='No categories' mod='homecategories'}</p>
{/if}

Modify the customer address form in prestashop 1.7 front office

I have configured this tpl for client addresses, the file is called "address-form.tpl" and has the following content
{block name="address_form"}
<div class="js-address-form">
{include file='_partials/form-errors.tpl' errors=$errors['']}
{block name="address_form_url"}
<form
method="POST"
action="{url entity='address' params=['id_address' => $id_address]}"
data-id-address="{$id_address}"
data-refresh-url="{url entity='address' params=['ajax' => 1, 'action' => 'addressForm']}"
>
{/block}
{block name="address_form_fields"}
<section class="form-fields">
{block name='form_fields'}
{foreach from=$formFields item="field"}
{block name='form_field'}
{form_field field=$field}
{/block}
{/foreach}
{/block}
</section>
{/block}
{block name="address_form_footer"}
<footer class="form-footer clearfix">
<input type="hidden" name="submitAddress" value="1">
{block name='form_buttons'}
<button class="btn btn-primary float-xs-left" type="submit" class="form-control-submit">
{l s='Save' d='Shop.Theme.Actions'}
</button>
{/block}
</footer>
{/block}
</form>
</div>
{/block}
Here the problem I have is that I loosen all the fields and renders them in the order that he wants, for example it shows me the "alias" first and then the name and surname, if what I want is to put the "alias" to end with this tpl file that I have how should I do it?
Thank you
You can control this order in (for Prestashop 1.7) your backoffice : International > Locations > Countries (or Internacional > Ubicaciones Geográficas > Países ;) ) then select a country.
You should make a simple workaround, like remaking the variable used in the foreach loop so you can control the order :
{$formFields = ["lastname","firstname","alias","..."]}
If you want to leave the "alias" field last in the form, you could use the array_reverse function, just replace the following line:
{foreach from = $formFields item = "field"}
by
{foreach item = "field" from = $formFields | #array_reverse: true}
Sorry for my English.

How to display Homeslider in all pages in Prestashop

I'm setting a webshop in Prestashop (1.6.1.1.) using the theme Default-Bootstrap.
I'm using the "Image slider for your homepage" module but it's only displayed in the homepage. I tried different things but any of them worked:
I've removed the condition {if $page_name =='index'}from the /homeslider.tpl
I've tried to force it by using the following condition in header.tpl:
{if $page_name !='index' && $page_name !='pagenotfound'}
{include file="$tpl_dir./modules/homeslider/homeslider.tpl"}
{/if}
I've tried to copy&paste the code from the /homeslider.tpl directly to the header/tpl template but only the <!-- Module HomeSlider -->comments are displayed with anything between (the {if isset($homeslider_slides)} condition seems to return false).
Of course, the module is hooked in the DisplayTop but still nothing happens outside the homepage... and using DisplayTopColumn is not an option.
Here is the code of the homeslider.tpl:
<!--{if $page_name =='index'} -->
<!-- Module HomeSlider -->
{if isset($homeslider_slides)}
<div id="homepage-slider">
{if isset($homeslider_slides.0) && isset($homeslider_slides.0.sizes.1)}{capture name='height'}{$homeslider_slides.0.sizes.1}{/capture}{/if}
<ul id="homeslider"{if isset($smarty.capture.height) && $smarty.capture.height} style="max-height:{$smarty.capture.height}px;"{/if}>
{foreach from=$homeslider_slides item=slide}
{if $slide.active}
<li class="homeslider-container">
<a href="{$slide.url|escape:'html':'UTF-8'}" title="{$slide.legend|escape:'html':'UTF-8'}">
<img src="{$link->getMediaLink("`$smarty.const._MODULE_DIR_`homeslider/images/`$slide.image|escape:'htmlall':'UTF-8'`")}"{if isset($slide.size) && $slide.size} {$slide.size}{else} width="100%" height="100%"{/if} alt="{$slide.legend|escape:'htmlall':'UTF-8'}" />
</a>
{if isset($slide.description) && trim($slide.description) != ''}
<div class="homeslider-description">{$slide.description}</div>
{/if}
</li>
{/if}
{/foreach}
</ul>
</div>
{/if}
<!-- /Module HomeSlider -->
<!--{/if}-->
And a piece of the header.tpl:
<div class="header-container">
<header id="header">
{capture name='displayBanner'}{hook h='displayBanner'}{/capture}
{if $smarty.capture.displayBanner}
<div class="banner">
<div class="container">
<div class="row">
{$smarty.capture.displayBanner}
</div>
</div>
</div>
{/if}
{capture name='displayNav'}{hook h='displayNav'}{/capture}
{if $smarty.capture.displayNav}
<div class="nav">
<div class="container">
<div class="row">
<nav>{$smarty.capture.displayNav}</nav>
</div>
</div>
</div>
{/if}
<div>
<div class="container">
<div class="row">
<div id="header_logo">
<a href="{if isset($force_ssl) && $force_ssl}{$base_dir_ssl}{else}{$base_dir}{/if}" title="{$shop_name|escape:'html':'UTF-8'}">
<img class="logo img-responsive" src="{$logo_url}" alt="{$shop_name|escape:'html':'UTF-8'}"{if isset($logo_image_width) && $logo_image_width} width="{$logo_image_width}"{/if}{if isset($logo_image_height) && $logo_image_height} height="{$logo_image_height}"{/if}/>
</a>
</div>
{if isset($HOOK_TOP)}{$HOOK_TOP}{/if}
/*********************************************
HERE I'D LIKE TO DISPLAY THE HOMESLIDER MODULE
*********************************************/
<!--{if $page_name !='index' && $page_name !='pagenotfound'}
{include file="$tpl_dir./modules/homeslider/homeslider.tpl"}
{/if} -->
</div>
</div>
</div>
</header>
</div>
I hope I've explained the problem well so you can be able to help me :)
Thanks in advance!
iarcas
I think you're on the right track, you foudn the conditional in templates, but have you checked the actual hook in the module?
See this:
homslider.php
public function hookdisplayTopColumn($params)
{
if (!isset($this->context->controller->php_self) || $this->context->controller->php_self != 'index')
return;
if (!$this->_prepareHook())
return false;
return $this->display(__FILE__, 'homeslider.tpl', $this->getCacheId());
}
So basically, you have to make an override for this function:
/override/modules/homeslider/homeslider.php
<?php
class HomeSliderOverride extends HomeSlider
{
public function hookdisplayTopColumn($params)
{
if (!$this->_prepareHook())
return false;
return $this->display(__FILE__, 'homeslider.tpl', $this->getCacheId());
}
}