Jump to content
Skittles

Optional Related Products, Version 4.0

Recommended Posts

Hi,

 

I've just installed this contribution and got confused as it's not working for me.

Well the store is still running without getting any bugs, the configuration and management in Admin area works OK, but there's nothing displayed at product info page.

I am using the STS contrib and made several tests. I have placed the insertion PHP script (that includes the optional_related_products.php) to my template and nothing has changed, even when I've pasted the entire code of optional_related_products.php to the template. No HTML tags, no images, nothing.

 

Any ideas?

 

Thank you.

Madenio,

 

I'm sorry. I have not had the time (yet) to create an STS install, so I have no idea what it will take to get this contribution to work with STS. I know it's no consolation, but making this work with STS is on the "To Do" list...

 

-Skittles

Share this post


Link to post
Share on other sites

I was able to get this working with STS. I made it a user defined box by opening up catalog/includes/modules/sts_inc/sts_user_code.php and adding this before the final ?>

 

 $sts->start_capture();
  require(DIR_WS_MODULES . FILENAME_RELATED_PRODUCTS);
  $sts->stop_capture('related_products', 'box');

 

This created an STS variable called $related_products that I inserted into my template. I think there is an easier way, but I haven't had time to work through it. You can see it working here:

 

http://bellagemmadesigns.com/product_info....;products_id=70

 

 

Hi,

 

I've just installed this contribution and got confused as it's not working for me.

Well the store is still running without getting any bugs, the configuration and management in Admin area works OK, but there's nothing displayed at product info page.

I am using the STS contrib and made several tests. I have placed the insertion PHP script (that includes the optional_related_products.php) to my template and nothing has changed, even when I've pasted the entire code of optional_related_products.php to the template. No HTML tags, no images, nothing.

 

Any ideas?

 

Thank you.

Share this post


Link to post
Share on other sites

Hi!.

 

Nice contribution!.

 

I just tried installing this one, I have a modded version of oscommerce, I can't get it to work apperantly :(.

 

I edited all files as mentioned in the "new_install" text, but I get this error when I try to enter the Admin pages:

 

Fatal error: Cannot redeclare tep_get_products_description() (previously declared in /home/apache/htdocs/kunder/importhandel.no/www/admin/includes/functions/general.php:523) in /home/apache/htdocs/kunder/importhandel.no/www/admin/includes/functions/general.php on line 539

 

 

My site seems to work fine, except when I view products, then I get this error:

 

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'RELATED_PRODUCTS_MAX_DISP' at line 14

SELECT pop_products_id_slave, products_name, products_model, products_price, products_quantity, products_tax_class_id, products_image FROM products_related_products, products_description pa, products pb WHERE pop_products_id_slave = pa.products_id AND pa.products_id = pb.products_id AND language_id = '4' AND pop_products_id_master = '219' AND products_status='1' ORDER BY rand() limit RELATED_PRODUCTS_MAX_DISP

[TEP STOP]

 

 

I've probably done some mistakes in the general.php, please help me out :'( .

 

 

Here's some code from General.php LINE: 523 to 551:

 

		function tep_get_products_description($product_id, $language_id) {
	  $product_query = tep_db_query("select products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language_id . "'");
	  $product = tep_db_fetch_array($product_query);

	  return $product['products_description'];
	}










 function tep_get_products_description($product_id, $language_id) {
$product_query = tep_db_query("select products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language_id . "'");
$product = tep_db_fetch_array($product_query);

return $product['products_description'];
 }

 function tep_get_products_url($product_id, $language_id) {
$product_query = tep_db_query("select products_url from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language_id . "'");
$product = tep_db_fetch_array($product_query);

return $product['products_url'];
 }

 

Thanks!. Hope we can get this running :).

 

Sorry for beeing a noob :P

 

Andree

Share this post


Link to post
Share on other sites

Dang, I can't edit or delete the last post!.

 

I actually managed to fix it myself :D. I started again with a clean general.php and modified it correct this time, found out that I misunderstood you the first time :s.

 

But now everything alright!. Secondly I had problems because the default language on my admin is Norwegian, how should I go about that?. It dosent matter for me that it is in English, but I need to have Norwegian as default!.

 

Thanks again,

Andree

Share this post


Link to post
Share on other sites
Dang, I can't edit or delete the last post!.

 

I actually managed to fix it myself :D. I started again with a clean general.php and modified it correct this time, found out that I misunderstood you the first time :s.

 

But now everything alright!. Secondly I had problems because the default language on my admin is Norwegian, how should I go about that?. It dosent matter for me that it is in English, but I need to have Norwegian as default!.

 

Thanks again,

Andree

Andree,

 

Step 6 has you make changes to the language files. Make the same changes to the corresponding Norwegian files (translating into Norwegian, if you like...):

 

6) Make changes to the language files

6a) [catalog/]admin/includes/languages/norwegian.php
	Add anywhere before the final "?>"

	/* Optional Related Products (ORP) */
	define('BOX_CATALOG_CATEGORIES_RELATED_PRODUCTS', 'Related Products');
	define('IMAGE_BUTTON_NEW_INSTALL_SQL', 'Install SQL for New Install of Related Products, Version 4.0');
	define('IMAGE_BUTTON_UPGRADE_SQL', 'Update SQL for Upgrade Install of Related Products, Version 4.0');
	define('IMAGE_BUTTON_REMOVE_SQL', 'Remove SQL for all versions of Related Products');
	/***********************************/


6b) [catalog/]includes/languages/norwegian.php
	Add anywhere before the final "?>"

	/* Optional Related Products (ORP) */
	define('IMAGE_BUTTON_RP_BUY_NOW', 'Buy Now');
	/***********************************/


6c) [catalog/]includes/languages/norwegian/product_info.php
	Add anywhere before the final "?>"

	/* Optional Related Products (ORP) */
	define('TEXT_RELATED_PRODUCTS', 'Other Products You Might Like');
	define('RELATED_PRODUCTS_MODEL_COMBO', ' (%s)');
	define('RELATED_PRODUCTS_PRICE_TEXT', '@ %s');
	define('RELATED_PRODUCTS_QUANTITY_TEXT', 'Only %s left!');
	/***********************************/

Then upload the following files, found in the corresponding "english" directory:

 

[catalog/]admin/includes/languages/norwegian/optional_related_products.php
[catalog/]admin/includes/languages/norwegian/sql_setup_related_products.php
[catalog/]admin/includes/languages/norwegian/images/buttons/button_related_products.gif
[catalog/]admin/includes/languages/norwegian/images/buttons/button_new_install_sql.gif
[catalog/]admin/includes/languages/norwegian/images/buttons/button_upgrade_sql.gif
[catalog/]admin/includes/languages/norwegian/images/buttons/button_remove_sql.gif

[catalog/]includes/languages/norwegian/images/buttons/button_rp_buy_now.gif

All but the "buy now" button are only used in the Admin. The buy now button, "button_rp_buy_now.gif", is actually a copy of the original buy now button. Assuming your Norwegian files include a buy now button, you can copy that file and rename the copy button_rp_buy_now.gif.

 

Everything will still be in English, unless you translate it into Norwegian, but it should work with Norwegian as the default language.

 

Steps 6b and 6c should be repeated for each language your store is supporting, and you should add a buy now button for each language as well.

 

I hope this helps.

-Skittles

Share this post


Link to post
Share on other sites

Thanks for all the help!. Its almost perfect now :D.

 

If you want to take a look, scroll down here:

http://www.importhandel.no/product_info.php?products_id=140

 

:)

 

 

I want to add a table around the related products, just like the table above with the product info in.

Not currently sure how I would do that correctly, if you want to tell me how then thanks :)

 

I just can't thank you guys enough, perfect script and perfect coding :D. Please do continue with your excellent effort and work.

 

Cheers,

Andree

Share this post


Link to post
Share on other sites

and yeah, hehe, I only support Norwegian as language, or, english too, but mainly Norwegian, the site dosent display correctly in English, so I need to fix that too shortly, as the site is active.

Share this post


Link to post
Share on other sites
I was able to get this working with STS. I made it a user defined box by opening up catalog/includes/modules/sts_inc/sts_user_code.php and adding this before the final ?>

 

 $sts->start_capture();
  require(DIR_WS_MODULES . FILENAME_RELATED_PRODUCTS);
  $sts->stop_capture('related_products', 'box');

 

This created an STS variable called $related_products that I inserted into my template. I think there is an easier way, but I haven't had time to work through it. You can see it working here:

 

http://bellagemmadesigns.com/product_info....;products_id=70

 

Hello charmdiva,

 

thank you for your suggestion. I tried your solution, but it doesn't work either. On product info page, I just see $related_products :( I've even tried to check in Admin panel and everything seems to be OK, I have even enabled to use the sts_user_code.php .

 

Don't you see any solution for me please?

 

Thank you!

Share this post


Link to post
Share on other sites

Product in Whats New Box with related items attached to it does not show related items when clicked.

 

Is there a fix for this?

 

Anyone run into this problem?

 

I have searched this forum with no success.

 

Thomas0012

Share this post


Link to post
Share on other sites
Product in Whats New Box with related items attached to it does not show related items when clicked.

 

Is there a fix for this?

 

Anyone run into this problem?

 

I have searched this forum with no success.

 

Thomas0012

Thomas0012,

 

I'm not quite sure what you mean. It sounds like you're saying the product page isn't showing the related products. But if that's true, it wouldn't matter if the product was accessed from the "What's New" box or the product listing.

 

If the site in question is online, it would be helpful to include the URL so I can check it out. (It doesn't have to be in English, I'll be looking at the source code for the product page...)

 

-Skittles

Share this post


Link to post
Share on other sites
Thomas,

 

It sounds like you really only need support for the catalog side, not the admin.

 

There are only four language constants added to the language files for product_info.php:

 

  /* Optional Related Products (ORP) */
 define('TEXT_RELATED_PRODUCTS', 'Other Products You Might Like');
 define('RELATED_PRODUCTS_MODEL_COMBO', ' (%s)');
 define('RELATED_PRODUCTS_PRICE_TEXT', '@ %s');
 define('RELATED_PRODUCTS_QUANTITY_TEXT', 'Only %s left!');
 /***********************************/

What languages will your client's shop support?

 

If you list them here, maybe we can get a response from one or more folks reading this thread who will translate the these lines for you.

 

It's worth a try...

 

-Skittles

 

Sorry for the slow reply..behind schedule working like crazy

 

Decided to just go english for now, will deal with multi-language later.

 

Thanks Again

Share this post


Link to post
Share on other sites
Thomas0012,

 

I'm not quite sure what you mean. It sounds like you're saying the product page isn't showing the related products. But if that's true, it wouldn't matter if the product was accessed from the "What's New" box or the product listing.

 

If the site in question is online, it would be helpful to include the URL so I can check it out. (It doesn't have to be in English, I'll be looking at the source code for the product page...)

 

-Skittles

 

Sorry Skittles for not explaining this better

 

One of my "main line of products" with "related products attached" was listed in the "Whats New Box" in the left column. When this New Product in the "Whats New Box" is clicked and displayed, the related products attached to this main product are not displayed. The related products are present when the main product is accessed through the main categories list in the left hand column.

 

Also I have another problem :)

 

I can't link to any of my other pages in the admin/catalog/related_products. It shows page 2 or whatever page I click in the address i.e. "admin/optional_related_products.php?attribute_page=2" but it remains on the first page. I had the same problem with attributes page links not working and found this fix. This is the actual code

 

I came across this in another thread...hope it helps!

 

in your catalog\admin\products_attributes.php

 

after this code

$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

 

Add:

CODE

$option_page = (isset($HTTP_GET_VARS['option_page']) ? $HTTP_GET_VARS['option_page'] : '1');

$value_page = (isset($HTTP_GET_VARS['value_page']) ? $HTTP_GET_VARS['value_page'] : '1');

$attribute_page = (isset($HTTP_GET_VARS['attribute_page']) ? $HTTP_GET_VARS['attribute_page'] : '1');

 

 

I don't know if this will help or if there is a quick fix for this.

 

Thanks in Advance

 

Thomas0012

Share this post


Link to post
Share on other sites
Sorry Skittles for not explaining this better

 

One of my "main line of products" with "related products attached" was listed in the "Whats New Box" in the left column. When this New Product in the "Whats New Box" is clicked and displayed, the related products attached to this main product are not displayed. The related products are present when the main product is accessed through the main categories list in the left hand column.

 

Also I have another problem :)

 

I can't link to any of my other pages in the admin/catalog/related_products. It shows page 2 or whatever page I click in the address i.e. "admin/optional_related_products.php?attribute_page=2" but it remains on the first page. I had the same problem with attributes page links not working and found this fix. This is the actual code

 

I came across this in another thread...hope it helps!

 

in your catalog\admin\products_attributes.php

 

after this code

$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

 

Add:

CODE

$option_page = (isset($HTTP_GET_VARS['option_page']) ? $HTTP_GET_VARS['option_page'] : '1');

$value_page = (isset($HTTP_GET_VARS['value_page']) ? $HTTP_GET_VARS['value_page'] : '1');

$attribute_page = (isset($HTTP_GET_VARS['attribute_page']) ? $HTTP_GET_VARS['attribute_page'] : '1');

I don't know if this will help or if there is a quick fix for this.

 

Thanks in Advance

 

Thomas0012

 

'SHOCK' Threw that code above in the related products page and it worked, haven't looked for any other bugs yet though

 

So for anyone who has had the same problem "can't link to next page in admin/attributes or admin/related products.

The above code does the trick

 

GREAT CONTRIB SKITTLES HOOOWA...ya me tired :)

Share this post


Link to post
Share on other sites

I have installed this and I get....in the product_info in the store.

 

1052 - Column 'products_model' in field list is ambiguous

 

SELECT pop_products_id_slave, products_name, products_model, products_price, products_quantity, products_tax_class_id, products_image FROM products_related_products, products_description pa, products pb WHERE pop_products_id_slave = pa.products_id AND pa.products_id = pb.products_id AND language_id = '1' AND pop_products_id_master = '2366' AND products_status='1' ORDER BY rand()

 

[TEP STOP]

Share this post


Link to post
Share on other sites
I have installed this and I get....in the product_info in the store.

 

1052 - Column 'products_model' in field list is ambiguous

 

SELECT pop_products_id_slave, products_name, products_model, products_price, products_quantity, products_tax_class_id, products_image FROM products_related_products, products_description pa, products pb WHERE pop_products_id_slave = pa.products_id AND pa.products_id = pb.products_id AND language_id = '1' AND pop_products_id_master = '2366' AND products_status='1' ORDER BY rand()

 

[TEP STOP]

swtnhpy,

 

Open [catalog]/includes/modules/optional_related_products.php and find the following code starting at line 22:

 

  $attributes = "
	 SELECT
	 pop_products_id_slave,
	 products_name,
	 products_model,
	 products_price,
	 products_quantity,
	 products_tax_class_id,
	 products_image
	 FROM " .
	 TABLE_PRODUCTS_RELATED_PRODUCTS . ", " .
	 TABLE_PRODUCTS_DESCRIPTION . " pa, ".
	 TABLE_PRODUCTS . " pb
	 WHERE pop_products_id_slave = pa.products_id
	 AND pa.products_id = pb.products_id
	 AND language_id = '" . (int)$languages_id . "'
	 AND pop_products_id_master = '".$HTTP_GET_VARS['products_id']."'
	 AND products_status='1' " . $orderBy;

Replace it with this code:

 

  $attributes = "
	 SELECT
	 rp.pop_products_id_slave,
	 pd.products_name,
	 p.products_model,
	 p.products_price,
	 p.products_quantity,
	 p.products_tax_class_id,
	 p.products_image
	 FROM " .
	 TABLE_PRODUCTS_RELATED_PRODUCTS . " rp, " .
	 TABLE_PRODUCTS_DESCRIPTION . " pd, ".
	 TABLE_PRODUCTS . " p
	 WHERE rp.pop_products_id_slave = p.products_id
	 AND p.products_id = pd.products_id
	 AND language_id = '" . (int)$languages_id . "'
	 AND rp.pop_products_id_master = '".$HTTP_GET_VARS['products_id']."'
	 AND products_status='1' " . $orderBy;

 

The sql statement did not specify which tables the data columns were in. The new sql code above does, and the convention has been changed in keeping with other osCommerce files: using 'p.' instead of 'pb.' and 'pd.' instead of 'pa.'.

 

Future releases will have this updated code.

 

If this doesn't fix your problem, something else is going on, so let me know and I will see if I can help you figure it out...

 

-Skittles

Share this post


Link to post
Share on other sites
Sorry Skittles for not explaining this better

 

One of my "main line of products" with "related products attached" was listed in the "Whats New Box" in the left column. When this New Product in the "Whats New Box" is clicked and displayed, the related products attached to this main product are not displayed. The related products are present when the main product is accessed through the main categories list in the left hand column.

 

Also I have another problem :)

 

I can't link to any of my other pages in the admin/catalog/related_products. It shows page 2 or whatever page I click in the address i.e. "admin/optional_related_products.php?attribute_page=2" but it remains on the first page. I had the same problem with attributes page links not working and found this fix. This is the actual code

 

I came across this in another thread...hope it helps!

 

in your catalog\admin\products_attributes.php

 

after this code

$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

 

Add:

CODE

$option_page = (isset($HTTP_GET_VARS['option_page']) ? $HTTP_GET_VARS['option_page'] : '1');

$value_page = (isset($HTTP_GET_VARS['value_page']) ? $HTTP_GET_VARS['value_page'] : '1');

$attribute_page = (isset($HTTP_GET_VARS['attribute_page']) ? $HTTP_GET_VARS['attribute_page'] : '1');

I don't know if this will help or if there is a quick fix for this.

 

Thanks in Advance

 

Thomas0012

Thomas0012,

 

Sorry to take so long to reply. Went on a short holiday... Hubby and I went to Crater Lake, and I took hundreds of pictures with my new digital SLR camera! Of course, now that I'm back, I have to get caught up on client work. :)

 

Okay, first, it shouldn't matter how you get to product_info.php, if there are 'related products' they should be displayed. Check the Related Products in the Admin, and make sure you have products related to the product in question. Remember, relationships are one way. If product A (in the left column) has products B C and D related to it, product B does NOT have product A related to it unless you have specifically entered it. That's why I added the 'Reciprocate' function (by request...) to make that association both ways in one operation.

 

The only other reason I can think of, that the related products aren't showing, is if the What's New link is going to a different file than product_info.php. That would only happen if you've installed a contribution that makes that change, (not that I'm aware of any that do, but I'm only familiar with a small percentage of the contributions.)

 

Second, I'll look into the code you've pointed out, and future releases should have this issue fixed. Sorry we didn't find it before the release.

 

-Skittles

Share this post


Link to post
Share on other sites

Worked perfectly! TY TY

 

swtnhpy,

 

Open [catalog]/includes/modules/optional_related_products.php and find the following code starting at line 22:

 

  $attributes = "
	 SELECT
	 pop_products_id_slave,
	 products_name,
	 products_model,
	 products_price,
	 products_quantity,
	 products_tax_class_id,
	 products_image
	 FROM " .
	 TABLE_PRODUCTS_RELATED_PRODUCTS . ", " .
	 TABLE_PRODUCTS_DESCRIPTION . " pa, ".
	 TABLE_PRODUCTS . " pb
	 WHERE pop_products_id_slave = pa.products_id
	 AND pa.products_id = pb.products_id
	 AND language_id = '" . (int)$languages_id . "'
	 AND pop_products_id_master = '".$HTTP_GET_VARS['products_id']."'
	 AND products_status='1' " . $orderBy;

Replace it with this code:

 

  $attributes = "
	 SELECT
	 rp.pop_products_id_slave,
	 pd.products_name,
	 p.products_model,
	 p.products_price,
	 p.products_quantity,
	 p.products_tax_class_id,
	 p.products_image
	 FROM " .
	 TABLE_PRODUCTS_RELATED_PRODUCTS . " rp, " .
	 TABLE_PRODUCTS_DESCRIPTION . " pd, ".
	 TABLE_PRODUCTS . " p
	 WHERE rp.pop_products_id_slave = p.products_id
	 AND p.products_id = pd.products_id
	 AND language_id = '" . (int)$languages_id . "'
	 AND rp.pop_products_id_master = '".$HTTP_GET_VARS['products_id']."'
	 AND products_status='1' " . $orderBy;

 

The sql statement did not specify which tables the data columns were in. The new sql code above does, and the convention has been changed in keeping with other osCommerce files: using 'p.' instead of 'pb.' and 'pd.' instead of 'pa.'.

 

Future releases will have this updated code.

 

If this doesn't fix your problem, something else is going on, so let me know and I will see if I can help you figure it out...

 

-Skittles

Share this post


Link to post
Share on other sites

OK, I've been working on related products in cart.

 

This needs more testing and code tweaks by people smarter than me, but it does work for me as is.

 

Copy and paste this code into a new file called optional_related_cart.php. Upload this file to (catalog)/includes/modules

 

<?php

/*
 $Id: optional_related_cart.php, ver 1.0 02/05/2007 Exp $

 Based on code from Contribution: Optional Related Products Ver 4.0
 Copyright © 2007 Anita Cross (http://www.callofthewildphoto.com/)

 Based on code from Optional Relate Products, ver 2.0 05/01/2005
 Copyright © 2004-2005 Daniel Bahna (daniel.bahna@gmail.com)

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Released under the GNU General Public License
*/
?>
<?php
//first see if there are any related products to display, if not - show nothing
$productid_array = array();
for ($i=0, $n=sizeof($products);$i<$n; $i++) {
 $productid_array[$i] = $products[$i]['id'];
}

 $orderBy = 'ORDER BY ';
 $orderBy .= (RELATED_PRODUCTS_RANDOMIZE)?'rand()':'pop_order_id, pop_id';
 $orderBy .= (RELATED_PRODUCTS_MAX_DISP)?' limit ' . RELATED_PRODUCTS_MAX_DISP:'';

for ($i=0; $i<$n; $i++) {

 $attributes = "
        SELECT
        pop_products_id_slave,
        products_name,
        products_model,
        products_price,
        products_quantity,
        products_tax_class_id,
        products_image
        FROM " .
        TABLE_PRODUCTS_RELATED_PRODUCTS . ", " .
        TABLE_PRODUCTS_DESCRIPTION . " pa, ".
        TABLE_PRODUCTS . " pb
        WHERE pop_products_id_slave = pa.products_id
        AND pa.products_id = pb.products_id
        AND language_id = '" . (int)$languages_id . "'
        AND pop_products_id_master = '". $products[$i]['id'] ."'
        AND products_status='1' " . $orderBy;
 $attribute_query = tep_db_query($attributes);

 if (mysql_num_rows($attribute_query)==0) {
?>

<?php
 } else {
 //if there are related products, let's show the header
 ?>
<tr>
 <td>
   <table class="productlisting" border="0" cellspacing="0" cellpadding="2" width="100%">
   <tr>
     <td align="left" class="productListing-heading"> <?php echo TEXT_RELATED_PRODUCTS ?></td>
   </tr>
<?php
//now we'll get a list of the products in the cart
$productid_array = array();
for ($i=0, $n=sizeof($products);$i<$n; $i++) {
 $productid_array[$i] = $products[$i]['id'];
}

 $orderBy = 'ORDER BY ';
 $orderBy .= (RELATED_PRODUCTS_RANDOMIZE)?'rand()':'pop_order_id, pop_id';
 $orderBy .= (RELATED_PRODUCTS_MAX_DISP)?' limit ' . RELATED_PRODUCTS_MAX_DISP:'';
//now we'll cycle through the list of products in the cart
for ($i=0; $i<$n; $i++) {

//this is the query 
 $attributes = "
        SELECT
        pop_products_id_slave,
        products_name,
        products_model,
        products_price,
        products_quantity,
        products_tax_class_id,
        products_image
        FROM " .
        TABLE_PRODUCTS_RELATED_PRODUCTS . ", " .
        TABLE_PRODUCTS_DESCRIPTION . " pa, ".
        TABLE_PRODUCTS . " pb
        WHERE pop_products_id_slave = pa.products_id
        AND pa.products_id = pb.products_id
        AND language_id = '" . (int)$languages_id . "'
        AND pop_products_id_master = '". $products[$i]['id'] ."'
        AND products_status='1' " . $orderBy;
 $attribute_query = tep_db_query($attributes);

 if (mysql_num_rows($attribute_query)>0) {
 $count = 0;
}
?>
<tr>
     <td align="left" class="productListing-data">
       <table border="0" cellspacing="0" cellpadding="2" width="100%" align="center">

<?php
   while ($attributes_values = tep_db_fetch_array($attribute_query)) {
//if it's already in the cart, there is no need to display it again, right?
	if (!in_array($attributes_values['pop_products_id_slave'], $productid_array)) {
array_push($productid_array, $attributes_values['pop_products_id_slave']);
//make a list of related products	
     $products_name_slave = ($attributes_values['products_name']);
     $products_model_slave = ($attributes_values['products_model']);
     $products_qty_slave = ($attributes_values['products_quantity']);
     $products_id_slave = ($attributes_values['pop_products_id_slave']);
     if ($new_price = tep_get_products_special_price($products_id_slave)) {
       $products_price_slave = $currencies->display_price($new_price, tep_get_tax_rate($attributes_values['products_tax_class_id']));
     } else {
       $products_price_slave = $currencies->display_price($attributes_values['products_price'], tep_get_tax_rate($attributes_values['products_tax_class_id']));
     }
     echo '' . "\n";
     // show thumb image if Enabled
     if (RELATED_PRODUCTS_SHOW_THUMBS == 'True') {
       echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id_slave) . '">' . "\n"
            . tep_image(DIR_WS_IMAGES . $attributes_values['products_image'], $attributes_values['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"').'</a> ' . "\n";
     }
     $caption = '';
     if (RELATED_PRODUCTS_SHOW_NAME == 'True') {
       $caption .= '<tr><td class="productListing-data" align="left"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id_slave) . '">' .  $products_name_slave . '</a>';
       if (RELATED_PRODUCTS_SHOW_MODEL == 'True') {
         $caption .= sprintf(RELATED_PRODUCTS_MODEL_COMBO, $products_model_slave);
       }
       $caption .= '</td>' . "\n";
     } elseif (RELATED_PRODUCTS_SHOW_MODEL == 'True') {
       $caption .=  '<p>' . $products_model_slave . '</p>' . "\n";
     }
     if (RELATED_PRODUCTS_SHOW_PRICE == 'True') {
       $caption .= '<td class="productListing-data" align="right"> ' . sprintf(RELATED_PRODUCTS_PRICE_TEXT, $products_price_slave) . '</td>' . "\n";
     }
     if (RELATED_PRODUCTS_SHOW_QUANTITY == 'True') {
       $caption .= '<p>' . sprintf(RELATED_PRODUCTS_QUANTITY_TEXT, $products_qty_slave) . '</p>' . "\n";
     }
     echo '<a href="'
					. tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id_slave) . '">'
					. $caption . '</a>' . "\n";
     if (RELATED_PRODUCTS_SHOW_BUY_NOW== 'True') {
       echo '<td class="productListing-data" align="left" width="15%">  <a href="'
					. tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action'))
					. 'action=rp_buy_now&rp_products_id=' . $products_id_slave) . '">'
					. RELATED_PRODUCTS_BUY_NOW_TEXT . '</a></td>';
     }
     echo '</tr>' . "\n";
     $count++;
     if ((RELATED_PRODUCTS_USE_ROWS == 'True') && ($count%RELATED_PRODUCTS_PER_ROW == 0)) {
       echo '</tr>' . "\n";
     }
   }
}

?>
       </tr></table>
		<?php
}
//}
?>
     </td>
   </tr></table>
 </td>

</tr>
<?php
}
}
?>

 

In your file shopping_cart.php, add the following line where you want the related products to appear:

 

<?php include(DIR_WS_MODULES . 'optional_related_cart.php'); ?>

 

(You may need to play around with the formatting of your shopping_cart.php page - sorry mine has been changed so I can't be sure exactly what you have to do)

 

Hope this helps!


Let's make things easier for new osCommerce users http://forums.oscommerce.com/topic/402638-discussion-about-hard-coded-database-tables/?p=1718900  Getting there with osCommerce 2.4! :thumbsup:

Share this post


Link to post
Share on other sites

Just installed this contrib, and it's great. Really to use, does exactly what you expect and pretty simple to install (for which credit goes to the author of the distructions), the only problem I had was in includes/boxes/catalog I had already used a line in that for another contrib (for modifying the sort order) but I managed to jiggle it around til they slotted together nicely, and being something of a newb I was quite pleased with myself when I fixed that :D

Share this post


Link to post
Share on other sites

:'( :'( :'(

 

I just spent 2 hours on this contribution, it is exactly what I need. Unfortunately I experienced almost every error described in this topic including more. Luckily I had my backup so eveything is as before. Only I missed 2 hours of customers. Bad luck.

 

What I need is much simpler than this. I have 3 products that relate to 1 product, that's it. If I would know how to hardcode these relations in the shopping cart (or wherever), then my problem would be solved.

 

I guess if someone can make a contrib as complicated as this one, then what I need wouldn't be so tough :blush:

 

I'll dive into php programming..

Share this post


Link to post
Share on other sites
:'( :'( :'(

 

I just spent 2 hours on this contribution, it is exactly what I need. Unfortunately I experienced almost every error described in this topic including more. Luckily I had my backup so eveything is as before. Only I missed 2 hours of customers. Bad luck.

 

What I need is much simpler than this. I have 3 products that relate to 1 product, that's it. If I would know how to hardcode these relations in the shopping cart (or wherever), then my problem would be solved.

 

I guess if someone can make a contrib as complicated as this one, then what I need wouldn't be so tough :blush:

 

I'll dive into php programming..

 

Why don't you copy the source code and make another instance of your shop for development? You can leave the original for customers and other instance http://url.com/devel you can be testing and, when everything works fine, just overwrite the original with devel instance.

Share this post


Link to post
Share on other sites

good, ,good, module, but i wonder if this module works with sppc contributtion....?

 

any ligth about this... thanks

Share this post


Link to post
Share on other sites
OK, I've been working on related products in cart.

 

This needs more testing and code tweaks by people smarter than me, but it does work for me as is.

 

Copy and paste this code into a new file called optional_related_cart.php. Upload this file to (catalog)/includes/modules

 

<?php

/*
 $Id: optional_related_cart.php, ver 1.0 02/05/2007 Exp $

 Based on code from Contribution: Optional Related Products Ver 4.0
 Copyright © 2007 Anita Cross (http://www.callofthewildphoto.com/)

 Based on code from Optional Relate Products, ver 2.0 05/01/2005
 Copyright © 2004-2005 Daniel Bahna (daniel.bahna@gmail.com)

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Released under the GNU General Public License
*/
?>
<?php
//first see if there are any related products to display, if not - show nothing
$productid_array = array();
for ($i=0, $n=sizeof($products);$i<$n; $i++) {
 $productid_array[$i] = $products[$i]['id'];
}

 $orderBy = 'ORDER BY ';
 $orderBy .= (RELATED_PRODUCTS_RANDOMIZE)?'rand()':'pop_order_id, pop_id';
 $orderBy .= (RELATED_PRODUCTS_MAX_DISP)?' limit ' . RELATED_PRODUCTS_MAX_DISP:'';

for ($i=0; $i<$n; $i++) {

 $attributes = "
        SELECT
        pop_products_id_slave,
        products_name,
        products_model,
        products_price,
        products_quantity,
        products_tax_class_id,
        products_image
        FROM " .
        TABLE_PRODUCTS_RELATED_PRODUCTS . ", " .
        TABLE_PRODUCTS_DESCRIPTION . " pa, ".
        TABLE_PRODUCTS . " pb
        WHERE pop_products_id_slave = pa.products_id
        AND pa.products_id = pb.products_id
        AND language_id = '" . (int)$languages_id . "'
        AND pop_products_id_master = '". $products[$i]['id'] ."'
        AND products_status='1' " . $orderBy;
 $attribute_query = tep_db_query($attributes);

 if (mysql_num_rows($attribute_query)==0) {
?>

<?php
 } else {
 //if there are related products, let's show the header
 ?>
<tr>
 <td>
   <table class="productlisting" border="0" cellspacing="0" cellpadding="2" width="100%">
   <tr>
     <td align="left" class="productListing-heading"> <?php echo TEXT_RELATED_PRODUCTS ?></td>
   </tr>
<?php
//now we'll get a list of the products in the cart
$productid_array = array();
for ($i=0, $n=sizeof($products);$i<$n; $i++) {
 $productid_array[$i] = $products[$i]['id'];
}

 $orderBy = 'ORDER BY ';
 $orderBy .= (RELATED_PRODUCTS_RANDOMIZE)?'rand()':'pop_order_id, pop_id';
 $orderBy .= (RELATED_PRODUCTS_MAX_DISP)?' limit ' . RELATED_PRODUCTS_MAX_DISP:'';
//now we'll cycle through the list of products in the cart
for ($i=0; $i<$n; $i++) {

//this is the query 
 $attributes = "
        SELECT
        pop_products_id_slave,
        products_name,
        products_model,
        products_price,
        products_quantity,
        products_tax_class_id,
        products_image
        FROM " .
        TABLE_PRODUCTS_RELATED_PRODUCTS . ", " .
        TABLE_PRODUCTS_DESCRIPTION . " pa, ".
        TABLE_PRODUCTS . " pb
        WHERE pop_products_id_slave = pa.products_id
        AND pa.products_id = pb.products_id
        AND language_id = '" . (int)$languages_id . "'
        AND pop_products_id_master = '". $products[$i]['id'] ."'
        AND products_status='1' " . $orderBy;
 $attribute_query = tep_db_query($attributes);

 if (mysql_num_rows($attribute_query)>0) {
 $count = 0;
}
?>
<tr>
     <td align="left" class="productListing-data">
       <table border="0" cellspacing="0" cellpadding="2" width="100%" align="center">

<?php
   while ($attributes_values = tep_db_fetch_array($attribute_query)) {
//if it's already in the cart, there is no need to display it again, right?
	if (!in_array($attributes_values['pop_products_id_slave'], $productid_array)) {
array_push($productid_array, $attributes_values['pop_products_id_slave']);
//make a list of related products	
     $products_name_slave = ($attributes_values['products_name']);
     $products_model_slave = ($attributes_values['products_model']);
     $products_qty_slave = ($attributes_values['products_quantity']);
     $products_id_slave = ($attributes_values['pop_products_id_slave']);
     if ($new_price = tep_get_products_special_price($products_id_slave)) {
       $products_price_slave = $currencies->display_price($new_price, tep_get_tax_rate($attributes_values['products_tax_class_id']));
     } else {
       $products_price_slave = $currencies->display_price($attributes_values['products_price'], tep_get_tax_rate($attributes_values['products_tax_class_id']));
     }
     echo '' . "\n";
     // show thumb image if Enabled
     if (RELATED_PRODUCTS_SHOW_THUMBS == 'True') {
       echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id_slave) . '">' . "\n"
            . tep_image(DIR_WS_IMAGES . $attributes_values['products_image'], $attributes_values['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"').'</a> ' . "\n";
     }
     $caption = '';
     if (RELATED_PRODUCTS_SHOW_NAME == 'True') {
       $caption .= '<tr><td class="productListing-data" align="left"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id_slave) . '">' .  $products_name_slave . '</a>';
       if (RELATED_PRODUCTS_SHOW_MODEL == 'True') {
         $caption .= sprintf(RELATED_PRODUCTS_MODEL_COMBO, $products_model_slave);
       }
       $caption .= '</td>' . "\n";
     } elseif (RELATED_PRODUCTS_SHOW_MODEL == 'True') {
       $caption .=  '<p>' . $products_model_slave . '</p>' . "\n";
     }
     if (RELATED_PRODUCTS_SHOW_PRICE == 'True') {
       $caption .= '<td class="productListing-data" align="right"> ' . sprintf(RELATED_PRODUCTS_PRICE_TEXT, $products_price_slave) . '</td>' . "\n";
     }
     if (RELATED_PRODUCTS_SHOW_QUANTITY == 'True') {
       $caption .= '<p>' . sprintf(RELATED_PRODUCTS_QUANTITY_TEXT, $products_qty_slave) . '</p>' . "\n";
     }
     echo '<a href="'
					. tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id_slave) . '">'
					. $caption . '</a>' . "\n";
     if (RELATED_PRODUCTS_SHOW_BUY_NOW== 'True') {
       echo '<td class="productListing-data" align="left" width="15%">  <a href="'
					. tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action'))
					. 'action=rp_buy_now&rp_products_id=' . $products_id_slave) . '">'
					. RELATED_PRODUCTS_BUY_NOW_TEXT . '</a></td>';
     }
     echo '</tr>' . "\n";
     $count++;
     if ((RELATED_PRODUCTS_USE_ROWS == 'True') && ($count%RELATED_PRODUCTS_PER_ROW == 0)) {
       echo '</tr>' . "\n";
     }
   }
}

?>
       </tr></table>
		<?php
}
//}
?>
     </td>
   </tr></table>
 </td>

</tr>
<?php
}
}
?>

 

In your file shopping_cart.php, add the following line where you want the related products to appear:

 

<?php include(DIR_WS_MODULES . 'optional_related_cart.php'); ?>

 

(You may need to play around with the formatting of your shopping_cart.php page - sorry mine has been changed so I can't be sure exactly what you have to do)

 

Hope this helps!

 

that is very helpfull but

i tried but it have not shown nothing... how did you insert this include on your shopping_cart.php

Share this post


Link to post
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

×