Jump to content

Archived

This topic is now archived and is closed to further replies.

jomagalo

Related products

Recommended Posts

Good afternoon,
 
I'm trying to show before "Product Information" products related to that product.
 
To do this, I created an additional field called "related" in the part of adding a new product, which saved correctly in the database.
 
The only thing that would fail me is how to display these products before "Product Information" File "content.product.php"
 
Exactly I need to call those products with the value of the variable "related" to coincide with the product name.
 
 
Best Regards

Share this post


Link to post
Share on other sites

Once you have the list of product_ids you associated with Prod-A, you can get the data about those related products by sending the array of product_ids to $GLOBALS['catalogue']->getProductData($product_ids).

 

The return from getProductData() is an array with the element's key being the product_id and the value being an array of parameters for the product obtained from the CC_inventory database table. For each item in the return, you will need to send the product_id to getProductPrice(), productAssign(), and SEO->buildURL() to get the image info and link URL. All of this data array containing the related products will be assigned to the main product's ['related'] element.

 

In the skin, the main product's variable is {$PRODUCT}, so you would loop through 'related' array:

{foreach $PRODUCT.related => $related}
{$related.name}
{* etc *}
{/foreach}

I have made a plugin called Bundle Products that can be easily adapted to your task.

Share this post


Link to post
Share on other sites

There must be some syntax error in this {foreach $PRODUCT.related => $related} I get blank page

Share this post


Link to post
Share on other sites

Try:

{foreach from=$PRODUCT.related item=related}

This is the syntax used by early versions of the template engine 'Smarty".

 

Later versions of Smarty also understand this syntax, much more like PHP's syntax:

{foreach $PRODUCT.related as $key=>$related}

also {foreach $PRODUCT.related as $related}

 

I wasn't too careful in my suggestion as I believed you would have seen how to do it right - just needed a clue.

Share this post


Link to post
Share on other sites

I did not know that there was a plugin for this. I tried to install it and am not able to make it work. Lock in a bundle I get this " Visit the bundle product plugin control to name the bundle field"

in the bundle field is not clear to me that I set. I tried to put anything and enabled all options but I get it to work. I have installed on cc525 and 5213 without results

Share this post


Link to post
Share on other sites

The Bundle Products plugin will not solve exactly what you require. With a bit of editing, it can.

 

For now, disable the plugin.

 

We will need to work together to make the Bundle Products do what you want.

Share this post


Link to post
Share on other sites

I have only knowledge of PHP, smarty only very little

 

Now this syntax does not fail. But the only thing showing is a numeric value "6 6".

 

This does not get it either, nor where to place that code:

Once you have the list of product_ids you associated with Prod-A, you can get the data about those related products by sending the array of product_ids to $GLOBALS['catalogue']->getProductData($product_ids).

Share this post


Link to post
Share on other sites

I think just be wanting to do a query to the database to be collected later by FOREACH. Something like:

SELECT * FROM `CubeCart_inventory` WHERE name='$related';

But where to place the code.

Share this post


Link to post
Share on other sites
I tried a thousand ways the plugin and am not able to make it work.
 
Could you please tell me how to operate this plugin?

Share this post


Link to post
Share on other sites

Have you tried adding your query as a code snippet?

 

I did a similar thing by writing this snippet - assigned to class.cubecart.display_product:

 

(in my example I created a seperate table in the database for the related products)

{php}

if (($alternative_products = $GLOBALS['db']->query('SELECT ap.id, ap.ProductId, ap.relatedProductId, i.name, i.seo_url, i.stock_level, i.price, imgs.file_id, files.filename FROM `alternative_products` AS ap INNER JOIN `CubeCart_inventory` AS i ON ap.relatedProductId = i.product_id INNER JOIN `CubeCart_image_index` AS imgs ON imgs.product_id = ap.relatedProductId INNER JOIN `CubeCart_filemanager` AS files ON imgs.file_id = files.file_id WHERE ap.ProductId='.$product['product_id'].' AND i.status=1 LIMIT 3'))) {
	
  foreach ($alternative_products as $alternative_product) {
		$alternative_vars[]	= $alternative_product;
	}
  	
  $GLOBALS['smarty']->assign('ALTERNATIVE_PRODUCTS', $alternative_vars);

}

{/php}

I was then able to output this on the product page (templates/content.product.php):

    {if isset($ALTERNATIVE_PRODUCTS)}
  
    <h3 class="">Alternatives Products</h3>
    
    <div class="row product-grid">
    
    {foreach from=$ALTERNATIVE_PRODUCTS item=alt_prod} 
      
      <div class="col-md-12 col-sm-4 col-xs-6">

        <div class="thumbnail product-grid-thumbnail">
      
        		<a href="product/{$alt_prod.seo_url}/{$alt_prod.relatedProductId}" title="{$alt_prod.name}">
        		  <img src="images/source/{$alt_prod.filename}" alt="{$alt_prod.name}" />
        		</a>
     
         	  <div class="caption product-grid-caption">
    
        	   <h4><a href="product/{$alt_prod.seo_url}/{$alt_prod.relatedProductId}" title="{$alt_prod.name}">{$alt_prod.name}</a> &pound;{$alt_prod.price} </h4>
    
        	  </div>

        </div>
        
      </div>
  
    {/foreach}
    
    </div>
    
    {/if}

Hopefully, this can point you in the right direction.

Share this post


Link to post
Share on other sites

Although I am not clear where to include this code:

{php}

if (($alternative_products = $GLOBALS['db']->query('SELECT ap.id, ap.ProductId, ap.relatedProductId, i.name, i.seo_url, i.stock_level, i.price, imgs.file_id, files.filename FROM `alternative_products` AS ap INNER JOIN `CubeCart_inventory` AS i ON ap.relatedProductId = i.product_id INNER JOIN `CubeCart_image_index` AS imgs ON imgs.product_id = ap.relatedProductId INNER JOIN `CubeCart_filemanager` AS files ON imgs.file_id = files.file_id WHERE ap.ProductId='.$product['product_id'].' AND i.status=1 LIMIT 3'))) {
	
  foreach ($alternative_products as $alternative_product) {
		$alternative_vars[]	= $alternative_product;
	}
  	
  $GLOBALS['smarty']->assign('ALTERNATIVE_PRODUCTS', $alternative_vars);

}

{/php}

Share this post


Link to post
Share on other sites

In admin, Manage Hooks, Code Snippets tab, click Add Snippet.

 

On the page that is displayed, make these entries:

Enabled: green check

Unique ID: [email protected] (<- 32 chars max)

Execution Order: 1

Description: Queries related products database table for records associated with a given product.

Trigger: class.cubecart.display_product

Version: 1.0

Author: disco_ii_disco on forums.cubecart.com

PHP Code: enter the code begining with {php} and ending with {/php}

 

Click Save.

Share this post


Link to post
Share on other sites

×
×
  • Create New...