Jump to content

[SOLVED] How to show manufacturer in features list


Tomasci

Recommended Posts

Hello,

 

I would like to add the manufacturer to the features list. So it would be visible on product page and comparison pages.

 

I imagine that these 2 files should be changed:

/themes/default-bootstrap/product.tpl  => working solution in post #13

/themes/default-bootstrap/products-comparison.tpl => working solution in post #17

 

But I only understand the html part. Could use some help. Pretty please..  :rolleyes: 

 

Product.tpl:

{if isset($features) && $features}
<!-- Data sheet -->
<section class="page-product-box">
<h3 class="page-product-heading">{l s='Data sheet'}</h3>
<table class="table-data-sheet">
{foreach from=$features item=feature}
<tr class="{cycle values="odd,even"}">
{if isset($feature.value)}
<td>{$feature.name|escape:'html':'UTF-8'}</td>
<td>{$feature.value|escape:'html':'UTF-8'}</td>
{/if}
</tr>
{/foreach}
</table>
</section>
<!--end Data sheet -->
{/if}

 

Products-Comparison.tpl:

{if $ordered_features}
{foreach from=$ordered_features item=feature}
{cycle values='comparison_feature_odd,comparison_feature_even' assign='classname'}
<td class="{$classname} feature-name" >
<strong>{$feature.name|escape:'html':'UTF-8'}</strong>
</td>
{foreach from=$products item=product name=for_products}
{assign var='product_id' value=$product->id}
{assign var='feature_id' value=$feature.id_feature}
{if isset($product_features[$product_id])}
{assign var='tab' value=$product_features[$product_id]}
<td class="{$classname} comparison_infos product-{$product->id}">{if (isset($tab[$feature_id]))}{$tab[$feature_id]|escape:'html':'UTF-8'}{/if}</td>
{else}
<td class="{$classname} comparison_infos product-{$product->id}"></td>
{/if}
{/foreach}
</tr>
{/foreach}
{else}
<tr>
<td></td>
<td colspan="{$products|@count}" class="text-center">{l s='No features to compare'}</td>
</tr>
{/if}

I only have some understanding of the html structure.

Who can help me put the last bits together?

 

 

Thank you.

Edited by Tomzie (see edit history)
Link to comment
Share on other sites

Hello, thanks for the assist. Part 1 is working. The manufacturer now shows in top of the Features list in Product Page.

 

This is the code used (first 4 lines):

<tr class="even">
           <td>{l s='Manufacturer'}</td>
           <td>{Manufacturer::getNameById($product->id_manufacturer)}</td>
</tr>

{foreach from=$features item=feature}
<tr class="{cycle values="odd,even"}">
{if isset($feature.value)}
<td>{$feature.name|escape:'html':'UTF-8'}</td>
<td>{$feature.value|escape:'html':'UTF-8'}</td>
{/if}
</tr>
{/foreach}

But I want to have this conditionally. I only know how to put it in words, not in code:

 

IF manufacturer is not empty, then show manufacturer:

{if ???? }
          <tr class="even">
                 <td>{l s='Manufacturer'}</td>
                 <td>{Manufacturer::getNameById($product->id_manufacturer)}</td>
           </tr> 
{/if}

Also, for the features row class:

If manufacturer is not empty, use class="{cycle values="odd,even"}" ELSE use class="{cycle values="even,odd"}"

<tr class="{cycle values="{IF ???} odd,even {ELSE} even,odd {/IF}"}">

Please advise on these {IF} situation. I do not yet understand php.

Many thanks!

Link to comment
Share on other sites

Hi,

 

Many thanks for the assist.

If there is no Manufacturer, then the Manufacturer label and row are still there in the data sheet.

Could it be a typing error? I don't know.

 

This is the result code:

{if isset($features) && $features}
	<!-- Data sheet -->
	<section class="page-product-box">
		<h3 class="page-product-heading">{l s='Data sheet'}</h3>
		<table class="table-data-sheet">
                    {if isset($product->id_manufacturer) && $product->id_manufacturer!='' }
                    <tr class="even">
                        <td>{l s='Manufacturer'}</td>
                        <td>{Manufacturer::getNameById($product->id_manufacturer)}</td>
                    </tr> 
                    {/if}
		    {foreach from=$features item=feature}
		    <tr class="{cycle values="{if $product->id_manufacturer!=''} odd,even {else} even,odd {/if}"}">
			{if isset($feature.value)}
			<td>{$feature.name|escape:'html':'UTF-8'}</td>
			<td>{$feature.value|escape:'html':'UTF-8'}</td>
		     {/if}
		     </tr>
		     {/foreach}                  
	        </table>
		</section>
	<!--end Data sheet -->
{/if}
Edited by Tomzie (see edit history)
Link to comment
Share on other sites

When using id_manufacturer_default, it does not work anymore. The row is not visible, not with or without manufacturer present.

 

 

Back to previous code. That worked nice. Just 1 problem that the row does not hide when manufacturer is empty. The IF function does not work.

 

 

Thanks again

Edited by Tomzie (see edit history)
Link to comment
Share on other sites

Is it possible that products without a manufacturer are auto assigned an existing ID # (like for example #0).

So in that case, the code would be correct but the category ID is just not empty?

 

In that case, something more like this might be helpful:

{if} category=>value is not empty

<tr>...</tr>

{/if}

 

So in short: if the value for this manufacturer ID is empty.

 

Is this a possibility?

Edited by Tomzie (see edit history)
Link to comment
Share on other sites

Wow. It was a simple mistake. Just by changing the !='' to !=0 it works.

 

Part 1 (product.tpl) completed  :)

 

This is working code for product.tpl:

{if isset($features) && $features}
			<!-- Data sheet -->
			<section class="page-product-box">
				<h3 class="page-product-heading">{l s='Data sheet'}</h3>
				<table class="table-data-sheet">
                    {if isset($product->id_manufacturer) && $product->id_manufacturer!=0 }
                    <tr class="even">
                        <td>{l s='Manufacturer'}</td>
                        <td>{Manufacturer::getNameById($product->id_manufacturer)}</td>
                    </tr> 
                    {/if}
                    
					{foreach from=$features item=feature}
					<tr class="{cycle values="{if $product->id_manufacturer!=0} odd,even {else} even,odd {/if}"}">
						{if isset($feature.value)}
						<td>{$feature.name|escape:'html':'UTF-8'}</td>
						<td>{$feature.value|escape:'html':'UTF-8'}</td>
						{/if}
					</tr>
					{/foreach}                  
				</table>
			</section>
			<!--end Data sheet -->
		{/if}
 
Many thanks to Ndiaga!!  :D
Edited by Tomzie (see edit history)
  • Like 1
Link to comment
Share on other sites

Part 2 (product-comparison.tpl) is not yet working as it should.

 

Issues:

  1. If 1 product in comparison does not have a manufacturer, no manufacturer row is visible.
  2. If all products in comparison have manufacturer, they are visible but not in  a row. All in the first column. (see screenshot)

post-763039-0-91933900-1475602045_thumb.png

 

This is the code so far:

{if $ordered_features}
                <!-- START MANUFACTURER -->        
                {if isset($product->id_manufacturer) && $product->id_manufacturer!=0 }
                        {foreach from=$products item=product name=for_products}
                            <tr class="comparison_feature_odd">
                                <td>{l s='Manufacturer'}</td>
                                <td>{Manufacturer::getNameById($product->id_manufacturer)}</td>
                            </tr>
                        {/foreach}
                {/if}
                <!-- END MANUFACTURER -->        
				{foreach from=$ordered_features item=feature}
					<tr>
						{cycle values='comparison_feature_odd,comparison_feature_even' assign='classname'}
						<td class="{$classname} feature-name" >
							<strong>{$feature.name|escape:'html':'UTF-8'}</strong>
						</td>
						{foreach from=$products item=product name=for_products}
							{assign var='product_id' value=$product->id}
							{assign var='feature_id' value=$feature.id_feature}
							{if isset($product_features[$product_id])}
								{assign var='tab' value=$product_features[$product_id]}
								<td class="{$classname} comparison_infos product-{$product->id}">{if (isset($tab[$feature_id]))}{$tab[$feature_id]|escape:'html':'UTF-8'}{/if}</td>
							{else}
								<td class="{$classname} comparison_infos product-{$product->id}"></td>
							{/if}
						{/foreach}
					</tr>
				{/foreach}
			{else}
                <!-- START MANUFACTURER -->        
                {if isset($product->id_manufacturer) && $product->id_manufacturer!=0 }
                        {foreach from=$products item=product name=for_products}
                            <tr class="comparison_feature_odd">
                                <td>{l s='Manufacturer'}</td>
                                <td>{Manufacturer::getNameById($product->id_manufacturer)}</td>
                            </tr>
                        {/foreach}
                {/if}
                <!-- END MANUFACTURER -->  
				<tr>
					<td></td>
					<td colspan="{$products|@count}" class="text-center">{l s='No features to compare'}</td>
				</tr>
			{/if}

Again.. Many thanks for the assist! Almost there  ;)

Edited by Tomzie (see edit history)
Link to comment
Share on other sites

Second issue as in screenshot previous post is now fixed.

First issue persists. If 1 manufacturer is empty, the manufacturer row is not visible.

 

So the change should probably be again in this line:

{if isset($product->id_manufacturer) && $product->id_manufacturer!=0 }

Now I believe it says: If no manufacturer ID = 0.

 

It should say something like:

 

If any product in this range does not have manufacturer with ID 0.

 

How could this be defined?

 

Thank you

Edited by Tomzie (see edit history)
Link to comment
Share on other sites

Try replacing that line with:

{assign var='has_manufacturers' value=false}
{foreach from=$products item=product}
    {if $product->id_manufacturer > 0}
        {assign var='has_manufacturers' value=true}
        {break}
    {/if}
{/foreach}
{if $has_manufacturers}

This should check whether any product has a manufacturer.

Link to comment
Share on other sites

Hi Rocky,

 

Thanks! That is Great. Now it works flawless.

Part 2 (product-comparison.tpl) completed.

 

This is the working code:

{if $ordered_features}
                <!-- START MANUFACTURER -->        
                    {assign var='has_manufacturers' value=false}
                    {foreach from=$products item=product}
                    {if $product->id_manufacturer > 0}
                    {assign var='has_manufacturers' value=true}
                    {break}
                    {/if}
                    {/foreach}
                        {if $has_manufacturers}
                        <tr class="comparison_feature_odd">
                            <td class="feature-name"><strong>{l s='Manufacturer'}</strong></td>
                            {foreach from=$products item=product name=for_products}
                                {assign var='product_id' value=$product->id}
							    {assign var='id_manufacturer' value={Manufacturer::getNameById($product->id_manufacturer)[spam-filter]                                
                            <td class="comparison_feature_odd comparison_infos manufacturer">{Manufacturer::getNameById($product->id_manufacturer)}</td>
                            {/foreach}
                        </tr>
                    {/if}
                <!-- END MANUFACTURER -->        
				{foreach from=$ordered_features item=feature}
					<tr>
						{cycle values='comparison_feature_odd,comparison_feature_even' assign='classname'}
						<td class="{$classname} feature-name" >
							<strong>{$feature.name|escape:'html':'UTF-8'}</strong>
						</td>
						{foreach from=$products item=product name=for_products}
							{assign var='product_id' value=$product->id}
							{assign var='feature_id' value=$feature.id_feature}
							{if isset($product_features[$product_id])}
								{assign var='tab' value=$product_features[$product_id]}
								<td class="{$classname} comparison_infos product-{$product->id}">{if (isset($tab[$feature_id]))}{$tab[$feature_id]|escape:'html':'UTF-8'}{/if}</td>
							{else}
								<td class="{$classname} comparison_infos product-{$product->id}"></td>
							{/if}
						{/foreach}
					</tr>
				{/foreach}
			{else}
                <!-- START MANUFACTURER -->        
                {assign var='has_manufacturers' value=false}
                {foreach from=$products item=product}
                {if $product->id_manufacturer > 0}
                {assign var='has_manufacturers' value=true}
                {break}
                {/if}
                {/foreach}
                        {if $has_manufacturers}
                        <tr class="comparison_feature_odd">
                            <td class="feature-name"><strong>{l s='Manufacturer'}</strong></td>
                            {foreach from=$products item=product name=for_products}
                                {assign var='product_id' value=$product->id}
							    {assign var='id_manufacturer' value={Manufacturer::getNameById($product->id_manufacturer)[spam-filter]                                
                            <td class="comparison_feature_odd comparison_infos manufacturer">{Manufacturer::getNameById($product->id_manufacturer)}</td>
                            {/foreach}
                        </tr>
                {/if}
                <!-- END MANUFACTURER -->  
				<tr>
					<td></td>
					<td colspan="{$products|@count}" class="text-center">{l s='No features to compare'}</td>
				</tr>
			{/if}

Many thanks to Rocky and Ndiaga!!  :D

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...