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.
Related
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}
I am trying to filter out the prices with a nested foreach and if statement in smarty, but whenever i use if statement inside foreach loop it results in blank page.
Here is code causing issue
{foreach $value.Regstration as $price}
{if($price.price gt 0)}
<br>{var_dump($price.price)} <br>
{/if}
{/foreach}
Even i tried with this
{foreach $value.Regstration as $price}
{if(1==1)}
<br>{var_dump($price.price)} <br>
{/if}
{/foreach}
This is also returning blank page
But without if statement i am getting result like this
float(14.95)
float(-1)
float(-1)
float(-1)
So can anyone tell me where i am doing wrong or if not can anyone tell me how can i filter the prices equal to or lower then zero.
Try this:
{foreach $value.Regstration as $price}
{if 1 == 1}
<!--
For debug:
{$price|var_dump}
-->
<br>{$price.price|var_dump}<br>
{/if}
{/foreach}
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,
after reinstalling cs-cart 4.2.4 we wanted to list the categories with it's subcategories in a block on the fronted.
We had this code to do this:
<div class="cat-blocks">
{foreach from=$items item="category"}
<li class="cat-blocks-item-li">
<div class="cat-blocks-item-li-wrapper">
<div class="cat-blocks-item-li-image">
<a href="{"categories.view?category_id=`$category.more.category_id`"|fn_url}" class="ty-subcategories-block__a">
{if $category.more.main_pair}
{include file="common/image.tpl"
show_detailed_link=false
images=$category.more.main_pair
no_ids=true
image_id="category_image"
image_width=235
image_height=220
class="cat-blocks-item-img"
}
{/if}
</a>
</div>
<div class="cat-blocks-item-li-name">
<h3> <a href="{"categories.view?category_id=`$category.more.category_id`"|fn_url}" class="cat-blocks-item-li-name__a">
{$category.more.category}</a></h3>
{if $category.sub}
<div class="cat-blocks-item-li-subcategories">
{foreach from=$category.sub item="sub"}
<a href="{"categories.view?category_id=`$sub.category_id`"|fn_url}" class="cat-blocks-item-li-sub__a">
{$sub.category}
</a>
{/foreach}
</div>
{/if}
</div>
</div>
</li>
{/foreach}
</div>
After reinstalling the website although the css is ok the block is totally empty and all we are see in firebug is
<a href="http://www.example.com/index.php?dispatch=categories.view&category_id=" class="ty-subcategories-block__a"`>
What am I missing.
Can anyone please help ?
Thank you
Please remove .more from all variables (category_id, category, main_pair )
before
{$category.more.category}
after
{$category.category}
Please add
{$items|fn_print_r}
before this line of code:
{foreach from=$items item="category"}
Then clear cache and check the result. You will see the content of the $items array. Please make sure that each element of this array contains the "category", "category_id" and "main_pair" values.
I have been reading up on best method in smarty to set every 4th item in the loop a class, and came across the use of "interation" however the example code below is kind of working but it is apply the class to everything after the 4th one and im wanting to apply a last class on every 4th one. Is this possible using this method?
{foreach from=$product.image_pairs item="image_pair" name="additional_images"}
{if $image_pair}
{if $image_pair.image_id == 0}
{assign var="img_id" value=$image_pair.detailed_id}
{else}
{assign var="img_id" value=$image_pair.image_id}
{/if}
{if $smarty.foreach.additional_images.iteration is div by 4}
{assign var="last_image" value="last"}
{/if}
{include file="common_templates/image.tpl" images=$image_pair object_type="detailed_product" link_class="cm-thumbnails-mini $last_image" image_width=$th_size image_height=$th_size show_thumbnail="Y" show_detailed_link=false obj_id="`$preview_id`_`$img_id`_mini" make_box=true wrap_image=true}
{/if}
{/foreach}
Result:
<a class="">content</a>
<a class="">content</a>
<a class="">content</a>
<a class="">content</a>
<a class="last">content</a>
<a class="last">content</a>
<a class="last">content</a>
{assign var="last_image" value="last"}
Will assign this variable on 4th iteration, and this will prevail for next iterations. You should add else and assign empty string to this variable.