This is items.tpl module of Prestashop CMS, it shows random productes in home page, i need to not show products quantity =0.
sry for my bad English.
Thanks for help guys.
{if isset($products) && $products}
<div class="{if isset($SNSPRT_EFFECT)}{$SNSPRT_EFFECT}{/if} product_list products-grid grid {if isset($class) && $class} {$class}{/if}">
{if isset($ajax_start) && $ajax_start}
{assign var='nbstart' value=$ajax_start}
{else}
{assign var='nbstart' value=0}
{/if}
{counter start=$nbstart skip=1 print=false name=i assign="i"}
{foreach from=$products item=product name=products}
<div class="ajax_block_product item item-animate{if isset($item_class) && $item_class} {$item_class}{/if}">
{counter name=i}
{include file="$tpl_dir./product-blockgrid.tpl"}
</div>
{if $i % $SNSPRT_XS == 0}<div class="clearfix visible-xs"></div>{/if}
{if $i % $SNSPRT_SM == 0}<div class="clearfix visible-sm"></div>{/if}
{if $i % $SNSPRT_MD == 0}<div class="clearfix visible-md"></div>{/if}
{if $i % $SNSPRT_LG == 0}<div class="clearfix visible-lg"></div>{/if}
{/foreach}
</div>
{addJsDefL name=min_item}{l s='Please select at least one product' js=1}{/addJsDefL}
{addJsDefL name=max_item}{l s='You cannot add more than %d product(s) to the product comparison' sprintf=$comparator_max_item js=1}{/addJsDefL}
{addJsDef comparator_max_item=$comparator_max_item}
{addJsDef comparedProductsIds=$compared_products}
{/if}
Your problem is not here in TPL file. It is on PHP associated module file. You should look for module displaying products in home page (like blockbestsellers or blocknewproducts) and look for main PHP module file. Inside you should find the MySQL request. For example from blocknewproducts:
protected function getNewProducts()
{
if (!Configuration::get('NEW_PRODUCTS_NBR'))
return;
$newProducts = false;
if (Configuration::get('PS_NB_DAYS_NEW_PRODUCT'))
$newProducts = Product::getNewProducts((int) $this->context->language->id, 0, (int)Configuration::get('NEW_PRODUCTS_NBR'));
if (!$newProducts && Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY'))
return;
return $newProducts;
}
You should change this $newProducts = Product::getNewProducts((int) $this->context->language->id, 0, (int)Configuration::get('NEW_PRODUCTS_NBR')); for your own MySQL sentence keeping original behavior but avoiding random.
Good luck
Related
Using Prestashop 1.7.6
I have a question regarding Free shipping, as you all know that it always shows Free (because it is selected by default in back office carriers) until it has been changed in carrier selection step.
so what I need guidance on is that I want to hide the shipping cost until "shipping method" step in check out. (or possibly if it says "To be calculated on next step" )
here is the cartpresenter.php code , which i guess shall need modifying ?
if (isset($deliveryOptionList) && count($deliveryOptionList) > 0) {
foreach ($deliveryOptionList as $option) {
foreach ($option as $currentCarrier) {
if (isset($currentCarrier['is_free']) && $currentCarrier['is_free'] > 0) {
$shippingDisplayValue = $this->translator->trans('Free', [], 'Shop.Theme.Checkout');
break 2;
Best Regards
You can create a theme and modify smarty templates :
For the cart
Copy to your theme and modify /themes/classic/templates/checkout/_partials/cart-detailed-totals.tpl and insert a condition at line 31 and close it at line 47:
<div class="card-block">
{foreach from=$cart.subtotals item="subtotal"}
{if $subtotal && $subtotal.value|count_characters > 0 && $subtotal.type !== 'tax'}
{if $subtotal.type === 'shipping' && $subtotal.amount > 0} {* line added *}
<div class="cart-summary-line" id="cart-subtotal-{$subtotal.type}">
<span class="label{if 'products' === $subtotal.type} js-subtotal{/if}">
{if 'products' == $subtotal.type}
{$cart.summary_string}
{else}
{$subtotal.label}
{/if}
</span>
<span class="value">
{if 'discount' == $subtotal.type}- {/if}{$subtotal.value}
</span>
{if $subtotal.type === 'shipping'}
<div><small class="value">{hook h='displayCheckoutSubtotalDetails' subtotal=$subtotal}</small></div>
{/if}
</div>
{/if} {* line added *}
{/if}
{/foreach}
</div>
For the checkout
Just do the same for file /themes/classic/templates/checkout/_partials/cart-summary-subtotals.tpl
Good luck :)
I am facing one problem of changing style of the unavailable sizes of product please help me to do so. my code is below
<ul id="color_to_pick_list" class="clearfix">
{assign var="default_colorpicker" value=""}
{foreach from=$group.attributes key=id_attribute item=group_attribute}
{assign var='img_color_exists' value=file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')}
<li{if $group.default == $id_attribute} class="selected"{/if}>
<a href="{$link->getProductLink($product)|escape:'html':'UTF-8'}" id="color_{$id_attribute|intval}" name="{$colors.$id_attribute.name|escape:'html':'UTF-8'}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}" title="{$colors.$id_attribute.name|escape:'html':'UTF-8'}">
{$group_attribute|escape:'html':'UTF-8'}</a></li>
{if ($group.default == $id_attribute)}
{$default_colorpicker = $id_attribute}
{/if}
{/foreach}
</ul>
So I want to show the the css line through for unavailable sizes of products.
It's complicated because the stock is registered on Prestashop not on variations but on a whole, which will give him such a product size 38 red a different stock of a product size 38 green.
So with queries we can see variations not available, but that does not happen in two lines.
I recommend taking a module is all for it.
Regards,
This code shows me all selections I have made.
How can I filter this and only show the selection of a specific Group?
For example {if $sConfigurator.groupID == 113}
{$configurator = $sArticle.sConfigurator}
{foreach $configurator as $configuratorGroup}
{foreach $configuratorGroup.values as $option}
{if $option.selected}
<div class="selected">
<div class="group">{$configuratorGroup.groupname}</div>
<div class="option">{$option.optionname}</div>
</div>
{/if}
{/foreach}
{/foreach}
I'm also not sure what you mean or what configurator your code is about...
Maybe just add the condition to the if?
{if $option.selected && $configuratorGroup.id == 113}
<div class="selected">
<div class="group">{$configuratorGroup.groupname}</div>
<div class="option">{$option.optionname}</div>
</div>
{/if}
Working with prestashop.
I have set up attributes for a product I need to display these in a table format like this http://www.solopress.com/leaflet-printing/bond-leaflet.html
So across the top it has the Paper Size and each row is the QTY of paper.
In my back-end I have the Attribute QTY for 250/500 etc etc and Size A4/A5/A6 etc
Is there any way I can pull the attributes from the drop down and list them as a table with the price being a Add to Cart button?
Any helpful bits of code or input would be great.
Many thanks!
This is definately not an answer but should give you a heads up on the problem itself.
Your text was not that clear but I'll assume you mean't that you created new attribute values and assigned them under combinations tag.
You have to create a specific table structure ( like you need ) in the product.tpl file and display the specific attrbitues by a smarty forach loop.
By default there are three group types for attributes: select, color, radio. You can add new attributes but without alterations in the database itself ( dont know if you are able to add them via admin panel ) the group types will remain the same.
Here is a code from product.tpl file that might help you
{foreach from=$groups key=id_attribute_group item=group}
{if $group.attributes|#count}
<fieldset class="attribute_fieldset span5">
<div id="attribute_label_container">
<label class="attribute_label" for="group_{$id_attribute_group|intval}">{$group.name|escape:'htmlall':'UTF-8'} : </label>
</div>
{assign var="groupName" value="group_$id_attribute_group"}
<div class="attribute_list">
{if ($group.group_type == 'select')}
<select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="attribute_select" onchange="findCombination();getProductAttribute();">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<option value="{$id_attribute|intval}"{if (isset($smarty.get.$groupName) && $smarty.get.$groupName|intval == $id_attribute) || $group.default == $id_attribute} selected="selected"{/if} title="{$group_attribute|escape:'htmlall':'UTF-8'}">{$group_attribute|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</select>
{elseif ($group.group_type == 'color')}
<ul id="color_to_pick_list" class="clearfix">
{assign var="default_colorpicker" value=""}
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li{if $group.default == $id_attribute} class="selected"{/if}>
<a id="color_{$id_attribute|intval}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}" style="background: {$colors.$id_attribute.value};" title="{$colors.$id_attribute.name}" onclick="colorPickerClick(this);getProductAttribute();">
{if file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')}
<img src="{$img_col_dir}{$id_attribute}.jpg" alt="{$colors.$id_attribute.name}" width="20" height="20" />
{/if}
</a>
</li>
{if ($group.default == $id_attribute)}
{$default_colorpicker = $id_attribute}
{/if}
{/foreach}
</ul>
<input type="hidden" class="color_pick_hidden" name="{$groupName}" value="{$default_colorpicker}" />
{elseif ($group.group_type == 'radio')}
<ul>
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li>
<input type="radio" class="attribute_radio" name="{$groupName}" value="{$id_attribute}" {if ($group.default == $id_attribute)} checked="checked"{/if} onclick="findCombination();getProductAttribute();" />
<span>{$group_attribute|escape:'htmlall':'UTF-8'}</span>
</li>
{/foreach}
</ul>
{/if}
</div>
</fieldset>
{/if}
{/foreach}
That will display the results in a list as you can see. To make it display in a table structure just edit the correct group_type IF content.
I hope that it helps you a bit.
BR's
I'm in a loop to display products...
4 per row, unlimited rows'
I need to know if it's the nth entry... example every 4 items... So I know its the first column as in
item 1, item5, item 9 etc...
Or last item
item 4, item 8, item 12
Tried these where
{foreach from=$sproducts item="product" name="sproducts"}
{counter assign="bobis" name="bobis" }
{if $bobis is div by 4|| $laster ==1}
{if $bobis mod 4 == 0}
{if $bobis !=4 && $bobis !=8 && $bobis != 12}
Any simple way?
If I understand the question right, just put a col- class on your item:
<div class="col-{$bobis mod 4}">...</div>
You should get the following:
<div class="col-1">...</div>
<div class="col-2">...</div>
<div class="col-3">...</div>
<div class="col-4">...</div>
<div class="col-1">...</div>
<div class="col-2">...</div>
...and so on
If you are using tables this is something I pulled from a script I am currently working on and adapted to your code somewhat. You probably would have to make some changes but it somewhat gives you an idea.
<table>
{foreach from=$sproducts item="product" name="sproducts"}
{if $product#first}<tr>{/if}
<td>{$product}</td>
{if $product#last}</tr>
{else}{if $product#iteration is div by 4}</tr><tr>
{/if}
{/if}
{/foreach}
</table>