Jump to content

“Group Features” available on the “product.tpl“


Sybille

Recommended Posts

you'll have to use an action hook to query the database because that information is not available to the templates by default.

 

even when it is partially available, e.g in "Cloud Slider", it's being pulled via the Class method for the current chosen product group... whereas, you need all the features of all the product groups.

Link to comment
Share on other sites

Thanks for your help. Do you know where I get a hook like this? I haven't got the knowledge to write something like this. :oops:

it's not going to be a million miles away from the hook I wrote for you previously for product bundles...

 

http://forum.whmcs.com/showthread.php?116082-separate-Page-for-Product-Categories&p=469819#post469819

 

you could use a similar hook to create an array containing a list of group features of all groups, and then use the template to show them under the appropriate product group - now it's not the most efficient way, but it's going to work and avoids the need for joining tables on a Tuesday morning! :idea:

 

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function group_features_hook($vars) {

   $features = Capsule::table('tblproduct_group_features')
               ->select('product_group_id','feature')
               ->orderby('product_group_id','asc')
               ->orderby('order','asc')
               ->get();

   $encodedata = json_encode($features);
   $decodedata = json_decode($encodedata, true);

   return array("groupfeatures" => $decodedata);
}
add_hook("ClientAreaPageCart", 1, "group_features_hook");
?>

and then in your products.tpl do something like below - remembering that you'll need to add all your <div>, css etc for layout...

 

{foreach $productgroups as $group}
   {$group.name}
       {foreach $groupfeatures as $gpfeatures}
           {if $gpfeatures.product_group_id eq $group.gid}
               <li>{$gpfeatures.feature}</li>
           {/if}
       {/foreach}
{/foreach}

Link to comment
Share on other sites

As I just realised, my code doesn't work properly. Either the layout Looks correct (product groups are displayed and their Features if they have some), but then the value gid is empty and nothing happens, when you click on a category or to get forwarded if you click on a category works, but, the group features from one group will be shown in every category.

 

My code:

<div class="row">
		{if $productgroup.name !== 'Bundles'}
			{foreach key=num item=productgroup from=$productgroups}
				<div class="col-md-3">
					<div class="category">
						<a href="cart.php?gid={$productgroup.gid}">{$productgroup.name}</a>
						{foreach $groupfeatures as $gpfeatures}
							{foreach $productgroups as $group}
								{if $gpfeatures.product_group_id eq $group.gid}
									<li><ul>{$gpfeatures.feature}</ul></li>
								{/if}
							{/foreach}
						{/foreach}
					</div>
				</div>
			{/foreach}
		{/if}
	</div>

 

How it looks like:

Produktübersicht.png

 

I guess for you it's a simple mistake but I'm note aware of PHP that much...

Thanks in advanced for your inputs.

Link to comment
Share on other sites

try this instead...

 

<div class="row">
   {foreach $productgroups as $productgroup} 
       {if $productgroup.name neq 'Bundles'}
           <div class="col-md-3">
               <div class="category">
                   <a href="cart.php?gid={$productgroup.gid}">{$productgroup.name}</a>
                       {foreach $groupfeatures as $gpfeatures}
                           {if $gpfeatures.product_group_id eq $productgroup.gid}
                               <li style="margin-left:30px;">{$gpfeatures.feature}</li>
                           {/if}
                       {/foreach}
               </div>
           </div>
       {/if}
   {/foreach}
</div>

you can remove the style from the <li> tag and replace with proper css - I just added that for my testing locally. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated