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
Related
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}
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}
Construction is this:
<!-- projects list -->
{if !empty($userObjects)}
<select id="projects-list" tabindex="1" name="project">
{if !isset($selected)}<option value="0">Choose project</option>{/if}
{foreach from=$userObjects item=v}
<option value="{$v.Id}" {if $selected==$v.Id}selected="selected"{/if} }>{$v.Name}
{* if it's 1st element *}
{if $smarty.foreach.v.index == 0}
{if isset($limit)}<br /><span id="projlimit">{$limit}</span> {$currency->sign}{/if}
{/if}
</option>
{/foreach}
</select>
as you can see I did
{if $smarty.foreach.v.index == 0}
but it's going wrong. In this case all the options elemets has a $limit value. How to make it good? I need only first one.
I don't want to appear rude, but Bondye's answer will not work in all cases. Since PHP's arrays are ordered maps, the value of the first key will not always be 0.
In these cases you can use the #index, #iteration or #first properties. More details are in the smarty foreach documentation at http://www.smarty.net/docs/en/language.function.foreach.tpl#foreach.property.iteration
One of the possible solutions to your question is bellow:
{foreach $rows as $row}
{if $row#iteration == 1}
First item in my array
{/if}
{/foreach}
You can use this code:
{foreach from=$userObjects item=v name=obj}
{if $smarty.foreach.obj.first}
This is the first item
{/if}
{if $smarty.foreach.obj.last}
This is the last item.
{/if}
{/foreach}
Could you do this by the array key?
{foreach from=$rows key=i item=row}
{if $i == 0}
First item in my array
{/if}
{/foreach}
Im trying to view contents of array on the page:
{foreach from=$entries key=i item=topic}
{if $topic.topic_style == question}
<li class="mail">
{$topic.title}
{$topic.tags}
</li>
{/if}
{/foreach}
$topic.tags is an array but i dont seem to be able to extract the contents to the page can anyone help?
Try this:
{foreach from=$entries key=i item=topic}
{if $topic.topic_style == question}
<li class="mail">
{$topic.title}
{foreach from=$topic.tags key=j item=tag}
{$tag}
{/foreach}
</li>
{/if}
{/foreach}
Where tag is the value of the tag name in the tags array().