Use Prestashop module tpl variable inside product page - php

I have a Prestashop module built that enable me upload additional images for each product. By using hook, The image is displayed on the product page using the hook {hook h='displayProductAdditionalInfo' product=$product}. See the module tpl code below:
{if $images}
{foreach from=$images item=image}
{if $image.type ==1}
<img src="{$this_path}uploads/{$image.image}" width="">
{else}
<img src="{$this_path}uploads/{$image.image}" width="">
{/if}
{/foreach}
{/if}
The challenge I have is that I want to use one of this image as background image for a section my poduct.tpl file. For example, using the code below:
<div class="uk-background-cover uk-panel" style="background-image: url(...);">
{block name='page_header'}
<h1 class="h1" itemprop="name">{block name='page_title'}{$product.name}
{/block}</h1>
{/block}
</div>
I thought of using {assign var=bgpath value="{hook='displayProductAdditionalInfo'}"} and then using it {$bgpath} inside style="background-image: url({$bgpath}); but it brought errror.
I also tried below so that I can use style="background-image: url({$bgpath});:
{if $images}
{foreach from=$images item=image}
{if $image.type ==1}
{assign var=bgpath value="{$this_path}uploads/{$image.image}"
{/if}
{/foreach}
{/if}
It didn't work because this variables are not available in product.tpl but in the module.tpl
I read that we may use controller override but I am not sure if it will work or how to implement it.

You can use style tag instead of style attribute in your tpl file.
{if $images}
{foreach from=$images item=image}
{if $image.type ==1}
{assign var=bgpath value="{$this_path}uploads/{$image.image}"
{/if}
{/foreach}
<style>
div.uk-background-cover {
background-image: url({$bgpath});
}
</style>
{/if}

Related

How to detect device in smarty in prestashop 1.7 in a TPL file?

I want the following:
& I understand I have to take the codes from context.php of PrestaShop but I seem to be making an error. A link to getcontext is as follows: (The code to detect mobile device is here)
https://github.com/PrestaShop/PrestaShop/blob/develop/classes/Context.php
{if isset($products) AND $products}
{$tabname=rand()+count($products)}
{if isset($display_mode) && $display_mode == 'carousel'}
{include file="{$items_owl_carousel_tpl}" items=$products image_size=$image_size}
{else}
{if device is MOBILE} /* Correct Code Needed */
{include file="{$items_normal_tpl}" items=$products image_size="homepage_default"}
{else device is NOT MOBILE} /* Correct Code Needed */
{include file="{$items_normal_tpl}" items=$products image_size="home_default"}
{/if}
{/if}
{/if}
What codes should I enter in the IF condition to make sure it detects mobile and not mobile.
Also is the IF condition written properly, what should I change in this code?
This is .TPL File.
try with :
{if Context::getContext()->isMobile() == 1}
{if Context::getContext()->getDevice() != 2}
// TABLETTE
{else}
// MOBILE
{/if}
{else}
// PC
{/if}
Regards
In Prestashop 1.7.8.2 it works this -->
{assign var="dispositivo" value="desktop"}
{if Context::getContext()->isMobile()}
{assign var="dispositivo" value="mobile"}
{else if Context::getContext()->isTablet()}
{assign var="dispositivo" value="tablet"}
{else}
{assign var="dispositivo" value="desktop"}
{/if}

Show product image instead of product name on the "recently viewed" block

I'm using CS-Cart 4.1.x
I created an override for the block "design\themes\basic\templates\blocks\products\products_text_links.tpl"
The code that I see in the default file is:
{** block-description:text_links **}
<{if $block.properties.item_number == "Y"}ol{else}ul{/if} class="bullets-list">
{foreach from=$items item="product"}
{assign var="obj_id" value="`$block.block_id`000`$product.product_id`"}
{if $product}
<li>
{$product.product nofilter}
</li>
{/if}
{/foreach}
</{if $block.properties.item_number == "Y"}ol{else}ul{/if}>
What I need to do is just to replace the following line with the proper code to show the product's default image instead of its name:
{$product.product nofilter}
Any ideas?
Thanks
Try:
{foreach from=$items item="product"}
{if $product}
{assign var="obj_id" value="`$block.block_id`000`$product.product_id`"}
{include file="common/image.tpl" image_width=$block.properties.thumbnail_width image_height=$block.properties.thumbnail_height obj_id=$obj_id images=$product.main_pair href="products.view?product_id=`$product.product_id`"|fn_url}
{/if}
{/foreach}

adjusting css with a site using smarty php

I am trying to adjust some boxes on a site using smarty.
three sections populate data to the boxes all three sections share the same class. I am trying to figure out where to go to add a new classes or remove them if necessary but this is gibberish to me.
If someone can make sense of this I would appreciate it.
this file seems to be calling all the classes that makes sense to me. Now how to change them beats me.
classifieds.tpl
{if count($from)}
<div class="classifieds">
<div class="list">
{foreach from=$from item=item key=key name=tmp}
{if $item.featured}<div class="featured">{/if}
<div class="listItemDiv">
<div class="listRowDiv">
{if $item.photo}<div class="image">
<div class="photo-photo">
<div>
{html_image file="$url/photos/`$item.photo`"}
</div>
</div>
</div>{/if}
<div class="title">{$item.title}</div>
<div class="description">{$item.description}</div>
{include file="$theme_template_root/items/actions.tpl"}
</div>
</div>
{if $item.featured}</div>{/if}
{/foreach}
</div></div>
{else}
<div class="centerText">{$language.nothing_found}</div>
{/if}
This file seems to add the heading of each section but then call a function? maybe? To populate the box with the correct data?
<div class="columnSmall">
{if $tip_message}
{include file="boxes/tip.tpl" tip=$tip_message}
{/if}
{include file="boxes/greyTop/open.tpl" secheader=$language.quick_search}
<div class="quickSearchForm">{include file="forms/simple.tpl" form="classifieds_qsearch"}</div>
{include file="boxes/greyTop/close.tpl"}
{if $banners.3}
<div class="banner-side">{banner area="3"}</div>
{/if}
</div>
<div class="columnWide">
{include file="boxes/white/open.tpl"}
<h2>{$language.featured_classifieds}</h2>
{include file="lists/classifieds.tpl" from=$featured.cards}
<h2>{$language.popular_classifieds}</h2>
{include file="lists/classifieds.tpl" from=$popular.cards}
<h2>{$language.new_classifieds}</h2>
{include file="lists/classifieds.tpl" from=$new_classifieds.cards}
{include file="boxes/white/close.tpl"}
</div>

PHP <li> loop listing the folders in the server

I'm learning PHP "on the go" as I edit a template for a website which I have to do at work, and I'm kinda lost. The original code looks like this:
<!-- start of top menubar -->
<table border="0" cellpadding="0" cellspacing="0" width="{$web_var_main_width}" align="center">
<tr style="background-color:#{$web_var_top_tabs_background};">
{php}
global $lang;
$this->assign('web_var_top_folder', $this->get_template_vars('web_var_top_folder_'.$lang));
{/php}
<td align="right" style="{if $web_var_top_tabs_image ne "" and $web_var_top_tabs_image ne 0}background:url(http://{$lang}.{$website_name}/{$RSwebPath}utilities/getScaledPicture.php?imageID={$web_var_top_tabs_image}&w={$web_var_top_tabs_image_x}&h={$web_var_top_tabs_image_y}&adj=d) top left repeat-y;{/if}background-color:#{$web_var_top_tabs_background_right};">
{if $folders_structure|#count gt 0}
{if $web_var_top_folder gt 0}
{section name=findtop loop=$folders_structure}
{if $folders_structure[findtop].key eq $web_var_top_folder}{assign var="top_menu" value=$folders_structure[findtop].childs}{/if}
{/section}
{if $top_menu|#count gt 0}
<table border="0" cellpadding="0" cellspacing="0" align="right">
<tr>
{if $web_var_top_font_size eq "small"}
{assign var="web_var_top_font_size" value="10px"}
{elseif $web_var_top_font_size eq "medium"}
{assign var="web_var_top_font_size" value="12px"}
{elseif $web_var_top_font_size eq "large"}
{assign var="web_var_top_font_size" value="14px"}
{elseif $web_var_top_font_size eq "extra large"}
{assign var="web_var_top_font_size" value="16px"}
{/if}
{section name=mytopsec loop=$top_menu}
<td width="5"></td>
{strip}
{if $top_menu[mytopsec].key eq $folders_selected[1]}
{assign var="topsel" value="1"}
<td bgcolor="#{$web_var_top_selected_tabs_color}" style="padding:6px 30px"><span style="font-family:{$web_var_top_font_family}; color:#{$web_var_top_font_color}; font-size:{$web_var_top_font_size}; font-weight:{$web_var_top_font_weight}; font-style:{$web_var_top_font_style}; text-decoration:none">{$top_menu[mytopsec].name}</span></td>
{else}
<td bgcolor="#{$web_var_top_tabs_color}" onMouseOver="this.style.backgroundColor='#{$web_var_top_tabs_hover}'; style.cursor='pointer'; style.cursor='hand'" onMouseOut="this.style.backgroundColor='#{$web_var_top_tabs_color}'" style="padding:6px 30px">{$top_menu[mytopsec].name}</td>
{/if}
{/strip}
{/section}
</tr>
</table>
{/if}
{/if}
{/if}
</td>
</tr>
<!-- end of top menubar -->
I have to send a folder ID which is the one the code scans into and shows all its childs.
And the function which scans the folders and lists them as menu items is this one:
<?
include_once "folderFunctions.php";
global $lang;
$global_deep=0;
$this->assign("folder_structure",getFolderChilds(0,$_SESSION["rs_domain_id"],$lang,"WEB",0,$global_deep));
$this->assign("folder_deep",$global_deep);
?>
Which uses the funcion GetFolderChilds from folderFunctions.php:
function getFolderChilds($identification,$website,$lang,$type,$local_deep,&$global_deep){
$child_list=array();
$childs = #mysql_query("SELECT `HB_IDENTIFICATION`,`HB_TITLE`,`HB_DESCRIPTION`,`HB_IMAGE_IDENTIFICATION`,`HB_LINK` FROM `hb_folders` WHERE `HB_PARENT_IDENTIFICATION` = ".$identification." AND `HB_DELETED`=0 AND `HB_PUBLISHED`=1 AND HB_WEBSITE_ID=".$website.(($type=='image')?(''):(" AND HB_LANGUAGE_ID='".$lang."'"))." AND HB_TYPE='".$type."' ORDER BY HB_ORDER");
$local_deep++;
if($local_deep>$global_deep&&#mysql_num_rows($childs)>0) $global_deep=$local_deep;
while($child = #mysql_fetch_assoc($childs)){
//$auxPermissions=getPermissions($_SESSION["rs_user_login"],$_SESSION["rs_user_pass"],$website,$child['HB_IDENTIFICATION'],'FOLDER');
//if($auxPermissions['read']==1){
$child_list[]=array("key"=>$child['HB_IDENTIFICATION'], "name"=>$child['HB_TITLE'], "desc"=>$child['HB_DESCRIPTION'], "image"=>$child['HB_IMAGE_IDENTIFICATION'], "link"=>$child['HB_LINK'], "childs"=>getFolderChilds($child['HB_IDENTIFICATION'],$website,$lang,$type,$local_deep,$global_deep));
//}
}
return $child_list;
}
And its output is something like this (tab changes color when mouse is on it, and so):
Well, that's what I figured out until now.
The thing is that I want to do a menu with these PHP functions, that is, creating the folders in the server and doing a loop which scans and shows them in my menu.
The thing is, that code uses tables, and has a lot of things which I don't need, such as image tabs and so (I just want to have a text menu with no images).
My question is, how can I implement the function to get the folders and list them not in a table, but in a list, so the output is something similar to this (I want to keep it as simple as posible in order to understand what is being done in any point)?
<header>
<ul class="navigation0">
<li>start</li>
<li>about us</li>
<li>contact</li>
</ul>
</header>
Which shows this:
Thanks a lot.
I believe I've solved it:
{php}
global $lang;
$this->assign('web_var_top_left_folder', $this->get_template_vars('web_var_top_left_folder_'.$lang));
{/php}
{if $folders_structure_left|#count gt 0}
{if $web_var_top_left_folder gt 0}
{section name=findtopleft loop=$folders_structure_left}
{if $folders_structure_left[findtopleft].key eq $web_var_top_left_folder}{assign var="top_left_menu" value=$folders_structure_left[findtopleft].childs}{/if}
{/section}
{if $top_left_menu|#count gt 0}
{if $web_var_top_font_size eq "small"}
{assign var="web_var_top_font_size" value="10px"}
{elseif $web_var_top_font_size eq "medium"}
{assign var="web_var_top_font_size" value="12px"}
{elseif $web_var_top_font_size eq "large"}
{assign var="web_var_top_font_size" value="14px"}
{elseif $web_var_top_font_size eq "extra large"}
{assign var="web_var_top_font_size" value="16px"}
{/if}
<ul class"leftmenu">
{section name=mytopsecleft loop=$top_left_menu}
{strip}
{if $top_left_menu[mytopsecleft].key eq $folders_selected[1]}
{assign var="topselleft" value="1"}
<li><span style="font-family:{$web_var_top_font_family}; color:#{$web_var_top_font_color}; font-size:{$web_var_top_font_size}; font-weight:{$web_var_top_font_weight}; font-style:{$web_var_top_font_style}; text-decoration:none">{$top_left_menu[mytopsecleft].name}</span></li>
{else}
<li onMouseOver="style.cursor='pointer'; style.cursor='hand'>{$top_left_menu[mytopsecleft].name}</li>
{/if}
{/strip}
{/section}
</ul>
{/if}
{/if}
{/if}

PHP/Smarty Shop Script issue

I'm trying to get Shop-Script Free by Webasyst to display the same shopping cart on 2 different websites. I want to only use one admin section.
I can get the categories, product names, product counts, prices and layout to display properly on both websites but I can't get the product images to show up on the second website (they display fine on the 'main' website).
The code I need help with is in the if statements for the $product_info[7] and $product_info[5]. They are coming back as false (0) and are not displaying.
{if $product_info[7]}
<a href="index.php?productID={$product_info[11]}">
<img src="products_pictures/{$product_info[7]}" alt="{$product_info[1]|replace:'"':'& quot;'}" border=0 /><br />
{$smarty.const.MORE_INFO_ON_PRODUCT}
</a>
{else}
{if $product_info[5]}
<a href="index.php?productID={$product_info[11]}">
<img src="products_pictures/{$product_info[5]}" alt="{$product_info[1]|replace:'"':'& quot;'}" border=0 />
{$smarty.const.MORE_INFO_ON_PRODUCT}
</a>
{/if}
{/if}
I've tried {if $product_info[7] ne ''} and {if $product_info[7] ne NULL}
Any thoughts or help would be greatly appreciated.
I'm pretty sure that with Smarty you have to use isset to check for a null value. So try this out:
{if isset($product_info[5]) && $product_info[5] != ""}
I think you have to use dot-notation to index into arrays in smarty. So try this:
{if $product_info.7}
<a href="index.php?productID={$product_info.11}">
<img src="products_pictures/{$product_info.7}" alt="{$product_info.1|replace:'"':'& quot;'}" border=0 /><br />
{$smarty.const.MORE_INFO_ON_PRODUCT}
</a>
{else}
{if $product_info.5}
<a href="index.php?productID={$product_info.11}">
<img src="products_pictures/{$product_info.5}" alt="{$product_info.1|replace:'"':'& quot;'}" border=0 />
{$smarty.const.MORE_INFO_ON_PRODUCT}
</a>
{/if}
{/if}
However I admit I have not tried it the way you are doing it.
I would recommend using an associative array though, instead of a numerically indexed one. The way Smarty is designed, it works much better if your indexes are named.

Categories