Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Cross Sell (X-Sell) Admin


dreamscape

Recommended Posts

Ok - I am trying to get the xsell_cart.php to use the info_box type layout just like xsell_products.php and I am running into issues.

 

This version of xsell_cart.php works for me (edited for SPPC and Master Products)

<!-- xsell_cart //-->
<?php

// BOF Separate Pricing Per Customer
if(!tep_session_is_registered('sppc_customer_group_id')) {
$customer_group_id = '0';
} else {
 $customer_group_id = $sppc_customer_group_id;
}
global $customer_group_id;

 //Start an array of items being suggested.
 $xsell_contents_array = array();

 //Start to build the HTML that will display the xsell box.
 $xsell_box_contents = '';

 //Go through each item in the cart, and look for xsell products.
 foreach ($products AS $product_id_in_cart) {
// First we need to get the master_product for the product_id_in_cart
$xsell_master_query = tep_db_query("SELECT products_master FROM " . TABLE_PRODUCTS . " WHERE products_id = " . $product_id_in_cart['id'] . "");
$xsell_master = tep_db_fetch_array($xsell_master_query);

//Main XSELL Query
if ($customer_group_id != '0') {
$xsell_query = tep_db_query("SELECT p.products_master, p.products_sort_order, p.products_id, pd.products_name, p.products_image, p.products_tax_class_id, IF(pg.customers_group_price IS NOT NULL, pg.customers_group_price, p.products_price) as products_price FROM  " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_GROUPS . " pg using(products_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_XSELL . " px WHERE px.products_id = " . $xsell_master['products_master'] . " AND px.xsell_id = p.products_id AND px.xsell_id = pd.products_id AND p.products_status = '1' AND pd.language_id = '" . (int)$languages_id . "' AND pg.customers_group_id = '".$customer_group_id."' and find_in_set('" . $customer_group_id . "', products_hide_from_groups) = 0 ORDER BY p.products_sort_order ASC");
} else {
$xsell_query = tep_db_query("SELECT p.products_master, p.products_sort_order, p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id FROM  " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_XSELL . " px WHERE px.products_id = " . $xsell_master['products_master'] . " AND px.xsell_id = p.products_id AND px.xsell_id = pd.products_id AND p.products_status = '1' AND pd.language_id = '" . (int)$languages_id . "' AND find_in_set('" . $customer_group_id . "', products_hide_from_groups) = 0 ORDER BY p.products_sort_order ASC");
}

//Cycle through each suggested product and add to box, if there are none
//go to the next product in the cart.
while ($xsell = tep_db_fetch_array($xsell_query)) {

  //If the xsell item is already being suggested, we don't need
  //to suggest it again.  Keep track of xsell items I've already dealt
  //with.
  if (!in_array($xsell['products_id'], $xsell_contents_array)) {

	//Add this xsell product to the list of xsell products dealt with. 
	array_push($xsell_contents_array, $xsell['products_id']);  

	//If a suggested product is already in the cart, we don't need to
	//suggest it again. 
	if (!$cart->in_cart($xsell['products_id'])) {  

	  //Create the box contents.
	  $xsell_box_contents .= '<tr><td class="smallText">Qty: ' . tep_draw_input_field('cart_quantity[]', '', 'size="4"') . tep_draw_hidden_field('products_id[]',  $xsell['products_id']) . '</td>';
	$xsell_box_contents .= '<td class="smallText" width="' . SMALL_IMAGE_WIDTH . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</td>';
	$xsell_box_contents .= '<td class="smallText">  <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_master']) . '">' . $xsell['products_name'] . '</a></td>';
  if ($xsell_price = tep_get_products_special_price($xsell['products_id'])) {
	$products_price = '<s>' . $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($xsell_price, tep_get_tax_rate($xsell['products_tax_class_id'])) . '</span>';
   } else {
	$products_price = $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id']));
   }
   $xsell_box_contents .= '<td class="smallText" align="right">' . $products_price . '  </td>';
  }  //END OF IF ALREADY IN CART
}  // END OF IF ALREADY SUGGESTED
 }  //END OF WHILE QUERY STILL HAS ROWS
}  //END OF FOREACH PRODUCT IN CART LOOP

//Only draw the table if there are suggested products.
if ($xsell_box_contents != '') {
 echo '<br><br><table class="productListing" width="90%" cellspacing="0" cellpadding="0" align="center"><tr><td colspan="4" class="productListing-heading" align="center">May we suggest:</td></tr><tr><td colspan="4" class="smallText" align="center">Enter Quantity desired, then click "Update"</td></tr>';
 echo $xsell_box_contents . '</table>';
}

?>
<!-- xsell_cart_eof //-->

 

This is what I have so far for the xsell_cart.php using the info box layout - for some reason it won't show all of the xsell products for all of the products in the cart (minus those already listed in xsell or already in the shopping cart) unless I put the closing

 } // end of foreach product in cart loop

after the

 new contentBox($info_box_contents);

bit of code. Unfortunately though, this results in separate entire tables for each of the products in the shopping cart.

 

Here is the code I currently have:

<!-- xsell_cart //-->
<?php

// BOF Separate Pricing Per Customer
if(!tep_session_is_registered('sppc_customer_group_id')) {
$customer_group_id = '0';
} else {
 $customer_group_id = $sppc_customer_group_id;
}
global $customer_group_id;

//Start an array of items being suggested.
$xsell_contents_array = array();

 //Go through each item in the cart, and look for xsell products.
 foreach ($products AS $product_id_in_cart) {
// First we need to get the master_product for the product_id_in_cart
$xsell_master_query = tep_db_query("SELECT products_master FROM " . TABLE_PRODUCTS . " WHERE products_id = " . $product_id_in_cart['id'] . "");
$xsell_master = tep_db_fetch_array($xsell_master_query);

//Main XSELL Query
if ($customer_group_id != '0') {
$xsell_query = tep_db_query("SELECT p.products_master, p.products_id, pd.products_name, p.products_image, p.products_tax_class_id, IF(pg.customers_group_price IS NOT NULL, pg.customers_group_price, p.products_price) as products_price FROM  " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_GROUPS . " pg using(products_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_XSELL . " px WHERE px.products_id = " . $xsell_master['products_master'] . " AND px.xsell_id = p.products_id AND px.xsell_id = pd.products_id AND p.products_status = '1' AND pd.language_id = '" . (int)$languages_id . "' AND pg.customers_group_id = '".$customer_group_id."' and find_in_set('" . $customer_group_id . "', products_hide_from_groups) = 0 ORDER BY p.products_ordered DESC");
} else {
$xsell_query = tep_db_query("SELECT p.products_master, p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id FROM  " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_XSELL . " px WHERE px.products_id = " . $xsell_master['products_master'] . " AND px.xsell_id = p.products_id AND px.xsell_id = pd.products_id AND p.products_status = '1' AND pd.language_id = '" . (int)$languages_id . "' AND find_in_set('" . $customer_group_id . "', products_hide_from_groups) = 0 ORDER BY p.products_ordered DESC");
}

//Check to see if we should show the table at all
$num_products_xsell = tep_db_num_rows($xsell_query);
if ($num_products_xsell > 0) {

	$info_box_contents = array();
	$info_box_contents[] = array('align' => 'left', 'text' => TEXT_XSELL_PRODUCTS);
	new contentBoxHeading($info_box_contents);

	$row = 0;
	$col = 0;
	$info_box_contents = array();
		//Cycle through each suggested product and add to box, if there are none
//go to the next product in the cart.
	while ($xsell = tep_db_fetch_array($xsell_query)) {

		  //If the xsell item is already being suggested, we don't need
  //to suggest it again. Keep track of xsell items I've already dealtwith.
  if (!in_array($xsell['products_id'], $xsell_contents_array)) {

	//Add this xsell product to the list of xsell products dealt with. 
	array_push($xsell_contents_array, $xsell['products_id']);  

	//if a suggested product is already in the cart, we don't need to suggest it again
	if (!$cart->in_cart($xsell['products_id'])) {

	   $xsell['specials_new_products_price'] = tep_get_products_special_price($xsell['products_id']);

	if ($xsell['specials_new_products_price']) {
		$xsell_price = '<s>' . $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</s><br>';
		$xsell_price .= '<span class="productSpecialPrice">' . $currencies->display_price($xsell['specials_new_products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</span>';
	} else {
		$xsell_price = $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id']));
	}

//create contents
	  $info_box_contents[$row][$col] = array('align' => 'center',
											 'params' => 'class="smallText" width="33%" valign="top"',
											 'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_master']) . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_master']) . '">' . $xsell['products_name'] . '</a><br>' . $xsell_price . '<br>Qty: ' . tep_draw_input_field('cart_quantity[]', '', 'size="4"') . tep_draw_hidden_field('products_id[]',  $xsell['products_id']) .'</a>');

									$col ++;
								if ($col > 2) {
									$col = 0;
									$row ++;
								} // end if ($col > 2) 

			}// end IF IN CART ALREADY
		} // end OF IF ALREADY SUGGESTED
	}// END while($xsell = tep_db_fetch_array($xsell_query)) 
}  //END if ($num_products_xsell > 0)  
}// end  OF FOREACH PRODUCT IN CART LOOP


new contentBox($info_box_contents);
?>
<!-- xsell_cart_eof //-->

 

Does anybody see what it is I need to do in order to get the correct products all into one infobox table? It all works properly in the first script - but I wanted to use the info_box_contents script as it shows the products in columns as well.

 

PS - I do still have the permissions error from the above post - anybody out there got any ideas?

 

Hey where did you get this xsell_cart.php from? I got this contribution just so I can add these recommended products to my cart. I used the auto installer to install the contribution but it was missing alot of things. As a test, I made it work for my product page but I don't have the code for the cart. Can you send it to me? I want it to be similar to the products page infobox. Please let me know where you got that code. cuz the code you have doesn't work for me, gives me an error 1054 - Unknown column 'products_master' in 'field list'

 

SELECT products_master FROM products WHERE products_id = 58

 

[TEP STOP]

Thank you in advance,

AE

Link to comment
Share on other sites

I downloaded it in the xsell v2.3 - it was one of the folders in that download as an "addition" if you wanted to install it.

 

Hey where did you get this xsell_cart.php from? I got this contribution just so I can add these recommended products to my cart. I used the auto installer to install the contribution but it was missing alot of things. As a test, I made it work for my product page but I don't have the code for the cart. Can you send it to me? I want it to be similar to the products page infobox. Please let me know where you got that code. cuz the code you have doesn't work for me, gives me an error 1054 - Unknown column 'products_master' in 'field list'

 

SELECT products_master FROM products WHERE products_id = 58

 

[TEP STOP]

~Tracy
 

Link to comment
Share on other sites

My PHP skills are not yet up to par with arrays and I'm hoping someone here can help :)

 

I am setting up two different Xsell boxes, one is just for a specific category. I have everything fine as long as the products products_id is only in one category. Where I am having a problem is how to write the query in such a way that it pulls the array of category id's that the product is in, and then checks those to see if categories_id 87 is in the array.

 

Here is what I have:

$xsell_extracts_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id='" . (int)$HTTP_GET_VARS['products_id'] . "'");
$xsell_results = tep_db_fetch_array($xsell_extracts_query);

if ($xsell_results['categories_id'] == '87') {
//BOF Xsell
  if ( (USE_CACHE == 'true') && !SID) {
   echo tep_cache_also_purchased(3600);
    include(DIR_WS_MODULES . FILENAME_XSELL_EXTRACTS);
  } else {
    include(DIR_WS_MODULES . FILENAME_XSELL_EXTRACTS);
     include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
   }

} else {

  if ( (USE_CACHE == 'true') && !SID) {
   echo tep_cache_also_purchased(3600);
    include(DIR_WS_MODULES . FILENAME_XSELL_PRODUCTS);
  } else {
    include(DIR_WS_MODULES . FILENAME_XSELL_PRODUCTS);
     include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
   }
}// end else
// EOF Xsell

 

Any thoughts on how to determine if 87 is in the array of categories_id numbers?

~Tracy
 

Link to comment
Share on other sites

  • 2 weeks later...

YAY!! Finally figured it out - here is how the working code now looks:

 

<?php
$xsell_extracts_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id='" . (int)$HTTP_GET_VARS['products_id'] . "'");
while ($_xsell_results = tep_db_fetch_array($xsell_extracts_query)) {
        $xsell_results[] = $_xsell_results;
        $categories_id[] = $_xsell_results['categories_id'];
        }

if (in_array('87', $categories_id)) {

//BOF Xsell
  if ( (USE_CACHE == 'true') && !SID) {
   echo tep_cache_also_purchased(3600);
    include(DIR_WS_MODULES . FILENAME_XSELL_EXTRACTS);
  } else {
    include(DIR_WS_MODULES . FILENAME_XSELL_EXTRACTS);
     include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
   }
// EOF Xsell
} else {
//BOF Xsell
  if ( (USE_CACHE == 'true') && !SID) {
   echo tep_cache_also_purchased(3600);
    include(DIR_WS_MODULES . FILENAME_XSELL_PRODUCTS);
  } else {
    include(DIR_WS_MODULES . FILENAME_XSELL_PRODUCTS);
     include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
   }
  }// end else
// EOF Xsell
?>

 

My PHP skills are not yet up to par with arrays and I'm hoping someone here can help :)

 

I am setting up two different Xsell boxes, one is just for a specific category. I have everything fine as long as the products products_id is only in one category. Where I am having a problem is how to write the query in such a way that it pulls the array of category id's that the product is in, and then checks those to see if categories_id 87 is in the array.

 

Here is what I have:

$xsell_extracts_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id='" . (int)$HTTP_GET_VARS['products_id'] . "'");
$xsell_results = tep_db_fetch_array($xsell_extracts_query);

if ($xsell_results['categories_id'] == '87') {
//BOF Xsell
  if ( (USE_CACHE == 'true') && !SID) {
   echo tep_cache_also_purchased(3600);
    include(DIR_WS_MODULES . FILENAME_XSELL_EXTRACTS);
  } else {
    include(DIR_WS_MODULES . FILENAME_XSELL_EXTRACTS);
     include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
   }

} else {

  if ( (USE_CACHE == 'true') && !SID) {
   echo tep_cache_also_purchased(3600);
    include(DIR_WS_MODULES . FILENAME_XSELL_PRODUCTS);
  } else {
    include(DIR_WS_MODULES . FILENAME_XSELL_PRODUCTS);
     include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
   }
}// end else
// EOF Xsell

 

Any thoughts on how to determine if 87 is in the array of categories_id numbers?

~Tracy
 

Link to comment
Share on other sites

Hi Everyone,

 

I have recently installed this contribution in the hope that I can create an infobox in the shopping cart page and have it display cross sell products. I first put the code in the product info page and it worked great. I was able to adjust the appearance and so on. I then took it to the shopping cart with no success can someone tell me what I'm doing wrong? my shopping cart can be found at www.bestmacdiscounts.com/shopping_cart.php. The cross sell product infobox is the box below the first box. Here is the code I'm used for the product info page that worked but didn't work for the shopping cart. Also Below I'll include a code I found in the extras somewhere that was suppose to be for the cart as I wish but doesn't work. I see within that code something called master product? I don't use those. Also I'm not a programmer but the string query have AND between things. I didn't see that with my other query for other infoboxes. If someone can help me rearrange either code to work that would be great. What is it that I need to do to get it to work? Thanks in advance for anyone that can help suggest a solution.

 

AE

 

<?php
/*
$Id: xsell_products.php, v1  2002/09/11
// adapted for Separate Pricing Per Customer v4 2005/02/24

osCommerce, Open Source E-Commerce Solutions
<http://www.oscommerce.com>

Copyright (c) 2002 osCommerce

Released under the GNU General Public License
*/
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_XSELL_PRODUCTS);

$xsell_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name, p.products_tax_class_id, products_price, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price
from " . TABLE_PRODUCTS_XSELL . " xp left join " . TABLE_PRODUCTS . " p on xp.xsell_id = p.products_id
left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "'
left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id 
where xp.products_id = '" . $HTTP_GET_VARS['products_id'] . "'
and p.products_status = '1'
order by sort_order asc limit " . MAX_DISPLAY_XSELL);


if (tep_db_num_rows($xsell_query)>= MIN_SIMILAR_PRODUCTS) {
?>
<!-- xsell_products //-->
 <tr>
      <td>

<?php
    $info_box_contents = array();
    $info_box_contents[] = array('align' => 'left', 'text' => TEXT_XSELL_PRODUCTS);
    new contentBoxHeading($info_box_contents);
?>
<? tep_draw_heading_top_3();?>	
<?php

    $row = 0;
    $col = 0;
    $info_box_contents = array();
    while ($xsell = tep_db_fetch_array($xsell_query)) {
		if (tep_not_null($xsell['specials_new_products_price'])) {
    $xsell_price =  '<s>' . $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</s><br>';
      	$xsell_price .= '<span class="productSpecialPrice">' . $currencies->display_price($xsell['specials_new_products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</span>';
		} else {
			$xsell_price = '<span class="productSpecialPrice">' .  $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</span>';
		}

$xsell['products_name'] = tep_get_products_name($xsell['products_id']);

 $p_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name']. '</a>';

$p_buynow ='<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=buy_now&product_to_buy_id=' . $xsell['products_id'], 'NONSSL') . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $xsell['products_name'] . TEXT_NOW) .'</a>';

  $xsell_reviews_query = tep_db_query("select r.reviews_rating from " . TABLE_REVIEWS . " r, " . TABLE_PRODUCTS . " p where r.products_id = " . (int)$xsell['products_id'] . "");
         $xsell_reviews = tep_db_fetch_array($xsell_reviews_query);
         $xsell_reviews_rating = (($xsell_reviews['reviews_rating'] >= '1') ? tep_image(DIR_WS_IMAGES . 'stars_' . $xsell_reviews['reviews_rating'] . '.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $xsell_reviews['reviews_rating'])) : tep_image(DIR_WS_IMAGES . 'stars_0.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, '0')));

       $info_box_contents[$row][$col] = array('align' => 'center',
                                              'params' => '',
                                              'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell["products_id"]) . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name'], TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT) . '<br>' . $xsell['products_name'] . '<br>' . $xsell_reviews_rating . '<br>' . $xsell_price. '<br>'.$p_buynow.'</a>');

   $col ++;
      if ($col >= 1) {
        $col = 0;
        $row ++;
      }
    }
new contentBox($info_box_contents);
?>
<? tep_draw_heading_bottom_3();?>
           </td>
         </tr>
<!-- xsell_products_eof //-->
<?php
}
?>

 

 

<!-- xsell_cart //-->
<?php

// BOF Separate Pricing Per Customer
if(!tep_session_is_registered('sppc_customer_group_id')) {
$customer_group_id = '0';
} else {
 $customer_group_id = $sppc_customer_group_id;
}
global $customer_group_id;

 //Start an array of items being suggested.
 $xsell_contents_array = array();

 //Start to build the HTML that will display the xsell box.
 $xsell_box_contents = '';

 //Go through each item in the cart, and look for xsell products.
 foreach ($products AS $product_id_in_cart) {
       // First we need to get the master_product for the product_id_in_cart
       $xsell_master_query = tep_db_query("SELECT products_master FROM " . TABLE_PRODUCTS . " WHERE products_id = " . $product_id_in_cart['id'] . "");
       $xsell_master = tep_db_fetch_array($xsell_master_query);

       //Main XSELL Query
       if ($customer_group_id != '0') {
       $xsell_query = tep_db_query("SELECT p.products_master, p.products_sort_order, p.products_id, pd.products_name, p.products_image, p.products_tax_class_id, IF(pg.customers_group_price IS NOT NULL, pg.customers_group_price, p.products_price) as products_price FROM  " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_GROUPS . " pg using(products_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_XSELL . " px WHERE px.products_id = " . $xsell_master['products_master'] . " AND px.xsell_id = p.products_id AND px.xsell_id = pd.products_id AND p.products_status = '1' AND pd.language_id = '" . (int)$languages_id . "' AND pg.customers_group_id = '".$customer_group_id."' and find_in_set('" . $customer_group_id . "', products_hide_from_groups) = 0 ORDER BY p.products_sort_order ASC");
       } else {
       $xsell_query = tep_db_query("SELECT p.products_master, p.products_sort_order, p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id FROM  " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_XSELL . " px WHERE px.products_id = " . $xsell_master['products_master'] . " AND px.xsell_id = p.products_id AND px.xsell_id = pd.products_id AND p.products_status = '1' AND pd.language_id = '" . (int)$languages_id . "' AND find_in_set('" . $customer_group_id . "', products_hide_from_groups) = 0 ORDER BY p.products_sort_order ASC");
       }

       //Cycle through each suggested product and add to box, if there are none
       //go to the next product in the cart.
       while ($xsell = tep_db_fetch_array($xsell_query)) {

         //If the xsell item is already being suggested, we don't need
         //to suggest it again.  Keep track of xsell items I've already dealt
         //with.
         if (!in_array($xsell['products_id'], $xsell_contents_array)) {

               //Add this xsell product to the list of xsell products dealt with. 
               array_push($xsell_contents_array, $xsell['products_id']);  

               //If a suggested product is already in the cart, we don't need to
               //suggest it again. 
               if (!$cart->in_cart($xsell['products_id'])) {  

                 //Create the box contents.
                 $xsell_box_contents .= '<tr><td class="smallText">Qty: ' . tep_draw_input_field('cart_quantity[]', '', 'size="4"') . tep_draw_hidden_field('products_id[]',  $xsell['products_id']) . '</td>';
               $xsell_box_contents .= '<td class="smallText" width="' . SMALL_IMAGE_WIDTH . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</td>';
               $xsell_box_contents .= '<td class="smallText">  <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_master']) . '">' . $xsell['products_name'] . '</a></td>';
         if ($xsell_price = tep_get_products_special_price($xsell['products_id'])) {
               $products_price = '<s>' . $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($xsell_price, tep_get_tax_rate($xsell['products_tax_class_id'])) . '</span>';
          } else {
               $products_price = $currencies->display_price($xsell['products_price'], tep_get_tax_rate($xsell['products_tax_class_id']));
          }
          $xsell_box_contents .= '<td class="smallText" align="right">' . $products_price . '  </td>';
         }  //END OF IF ALREADY IN CART
       }  // END OF IF ALREADY SUGGESTED
 }  //END OF WHILE QUERY STILL HAS ROWS
}  //END OF FOREACH PRODUCT IN CART LOOP

//Only draw the table if there are suggested products.
if ($xsell_box_contents != '') {
 echo '<br><br><table class="productListing" width="90%" cellspacing="0" cellpadding="0" align="center"><tr><td colspan="4" class="productListing-heading" align="center">May we suggest:</td></tr><tr><td colspan="4" class="smallText" align="center">Enter Quantity desired, then click "Update"</td></tr>';
 echo $xsell_box_contents . '</table>';
}

?>
<!-- xsell_cart_eof //-->

Thank you in advance,

AE

Link to comment
Share on other sites

  • 2 weeks later...

Hi all,

 

I installed this xsell contribution. Everything is fine but when I click on the "Buy Now" button it brought up shopping cart page and said "your shopping cart is empty". Do you know why?

You can try the fix described here to see if it works: buy fix

Absinthe Original Liquor Store

Link to comment
Share on other sites

Hi, I just want to let you know, that I've tested the latest version v2_6 from 4 Feb 2009. The buy now button works just fine, both with Display Cart After Adding Product set to true or false. That is with the Ultimate SEO. The cache is working fine, saving few more queries, therefore I can only suggest upgrading. I had to change few bits to make it work even slightly better:

includes/modules/ line 22 change from

$xsell_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name, p.products_tax_class_id, products_price, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, specials_new_products_price

to:

$xsell_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name, p.products_tax_class_id, products_price, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price

otherwise it will show special price even if the product on special is currently off

 

In admin, I wanted to see active products only, therefore I added p.products_status = 1 to the db_query in admin/xsell.php line 181:

$products_query_raw = 'select p.products_id, p.products_model, p.products_status, p.products_price, p.products_tax_class_id, p.products_image, pd.products_name, p.products_id from '.TABLE_PRODUCTS.' p, '.TABLE_PRODUCTS_DESCRIPTION.' pd where p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = "'.(int)$languages_id.'" and pd.products_name like "%' . tep_db_input($search) . '%" order by pd.products_name asc';}else{$products_query_raw = 'select p.products_id, p.products_model, p.products_status, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_id from '.TABLE_PRODUCTS.' p, '.TABLE_PRODUCTS_DESCRIPTION.' pd where p.products_status = 1 and p.products_id = pd.products_id and pd.language_id = "'.(int)$languages_id.'" order by pd.products_name asc';}

also, I've commented some lines out, as the code had funny behaviour and cross sell products were added as they had mind on its own:

//        tep_db_query('delete from ' . TABLE_PRODUCTS_XSELL . ' where xsell_id = "'.$_GET['add_related_product_ID'].'" and products_id = "'.$temp_prod.'"'); 

and further down:

// insert reciprocable x-sell products
/*            $sort_start_query2 = tep_db_query('select sort_order from ' . TABLE_PRODUCTS_XSELL . ' where products_id = "'.$temp.'" order by sort_order desc limit 1');
           $sort_start2 = tep_db_fetch_array($sort_start_query2);
           $sort2 = (($sort_start2['sort_order'] > 0) ? $sort_start2['sort_order'] : '0');
           $sort2++;
           $insert_array = array();
           $insert_array = array('products_id' => $temp,
                                 'xsell_id' => $_GET['add_related_product_ID'],
                                 'sort_order' => $sort2);
           tep_db_perform(TABLE_PRODUCTS_XSELL, $insert_array);*/

do the above change only if the admin part is not working properly.

 

Cosmetic change is on line 305, code:

<td class="smallText" valign="top"><?php echo $products_split->display_count($products_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_CUSTOMERS); ?></td>

should be:

<td class="smallText" valign="top"><?php echo $products_split->display_count($products_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>

 

That's about all, if you want to have xsell box below the also purchased, just switch these two lines in product_info (STEP 5 - instructions):

      echo tep_cache_also_purchased(3600);
     echo tep_cache_xsell_products(3600); //added for Xsell

Absinthe Original Liquor Store

Link to comment
Share on other sites

This is a little update, the buy_now button works fine but not on php 5.3.1! It works fine on my other server with php 5.2.8. What it does on 5.3.1, it is working fine if (tep_has_product_attributes($HTTP_GET_VARS['product_to_buy_id'])) = it is redirected to a product's page - tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['product_to_buy_id'])). However if product has no attributes, it is NOT added to cart - the cart is shown, but it is not added.

 

I have also noticed a small typing error in instruction, step 14 it reads:

// BOE: XSell
       if (isset($HTTP_GET_VARS['product_to_buy_id'])) {
         $parameters = array('action', 'pid', 'products_to_but_id');   <- see the mistake?
	} else {
         $parameters = array('action', 'pid', 'products_id');
	}
// EOE: XSell

I'm positive, it should be:

// BOE: XSell
       if (isset($HTTP_GET_VARS['product_to_buy_id'])) {
         $parameters = array('action', 'pid', 'product_to_buy_id');
	} else {
         $parameters = array('action', 'pid', 'products_id');
	}
// EOE: XSell

 

However it has no influence on the NEVERENDING buy_now button problem. I have a temporary fix, but that only works if Display Cart After Adding Product is set to True in admin. It involves changing the $text = in xsell_products.php as follows:

$text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] .'</a><br>' . $xsell_price. '<br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'action=buy_now&products_id=' . $xsell['products_id'], 'NONSSL') . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $xsell['products_name'] . TEXT_NOW) .'</a>';

 

If I'll find a solution, I'll post it. I'm not going to upgrade this contribution at the moment, but if someone does, please make sure to include fixes mentioned.

Absinthe Original Liquor Store

Link to comment
Share on other sites

  • 1 month later...

howdy, so yeah, i have this contrib installed, and although i am specifying xsell products in the admin, what appears in the product info box is not what i provided, just "customers also bought". am i using the wrong contrib?

Link to comment
Share on other sites

  • 2 weeks later...

Version 2.7.1 uploaded.

 

Fixing bug with reciprocal links. Now works this way:

  • You may cross products to each other (turn on all checkboxes);
  • You may choose one product and cross it to the second (turn on only first checkbox);
  • You may choose one product and cross the second product to it (turn on only second checkbox).

 

Freely contact me through PM.

Link to comment
Share on other sites

Hello I just installed 2.7.1 and I am getting this error.

 

Warning: include(includes/modules/FILENAME_XSELL_PRODUCTS) [function.include]: failed to open stream: No such file or directory in /home/ehaggle/public_html/fancifulu.com/product_info.php  on line 298

Warning: include(includes/modules/FILENAME_XSELL_PRODUCTS) [function.include]: failed to open stream: No such file or directory in /home/ehaggle/public_html/fancifulu.com/product_info.php on line 298

Warning: include() [function.include]: Failed opening 'includes/modules/FILENAME_XSELL_PRODUCTS' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ehaggle/public_html/fancifulu.com/product_info.php on line 298

 

 

any ideas on how to fix this

 

 

thanks

 

lexxie

Link to comment
Share on other sites

Hello I just installed 2.7.1 and I am getting this error.

 

Warning: include(includes/modules/FILENAME_XSELL_PRODUCTS) [function.include]: failed to open stream: No such file or directory in /home/ehaggle/public_html/fancifulu.com/product_info.php  on line 298

Warning: include(includes/modules/FILENAME_XSELL_PRODUCTS) [function.include]: failed to open stream: No such file or directory in /home/ehaggle/public_html/fancifulu.com/product_info.php on line 298

Warning: include() [function.include]: Failed opening 'includes/modules/FILENAME_XSELL_PRODUCTS' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/ehaggle/public_html/fancifulu.com/product_info.php on line 298

 

any ideas on how to fix this

 

 

thanks

 

lexxie

You miss STEP 3 of installation instruction.

Edited by RusNN
Link to comment
Share on other sites

Hi!

 

is there a way, in product_info.php, to only show XSELL PRODUCTS and if there is none, then show NEW PRODUCTS instead ?

 

thank you

Of course! But you should do some coding yourself. I don't know what NEW PRODUCTS do you have on product_info.php, but if you want to display, say default new_product.php module from catalog/includes/modules directory you should change catalog/includes/modules/xsell_products.php.

 

1. FOUND this line

if ($HTTP_GET_VARS['products_id']) {

 

ADD BEFORE:

$has_xsell_products = false;

 

2. FOUND this line

if ($num_products_xsell > 0) {

 

ADD AFTER:

$has_xsell_products = true;

 

3. proceed to the very end and ADD BEFORE last ?> tag:

if(!$has_xsell_products) include(DIR_WS_MODULES . FILENAME_NEW_PRODUCTS);

 

That's all. Doesn't tested, but hypothetically must work.

 

Note: In this way you modify module xsell to show your new products.

 

There is another way - modify product_info.php to show up new products if no xsells found. This way you should do one more query to database to check is there a xsells for the product or not and request appropriate module. The query may be exactly the same as the main xsell query. In one word, you should do the same check twice - one time in product_info and second - on xsell_products module. This is not a good way. You also may modify xsell_product module so, you need not ask the query in it (using query from product_info.php).

Edited by RusNN
Link to comment
Share on other sites

Thank you for the quick reply!

YES that was exactly what I was looking for, works like a charm!

it all makes sense when you see it this way, I was only at product_info.php stuck and lost :)

 

thanx again!

 

 

Of course! But you should do some coding yourself. I don't know what NEW PRODUCTS do you have on product_info.php, but if you want to display, say default new_product.php module from catalog/includes/modules directory you should change catalog/includes/modules/xsell_products.php.

 

1. FOUND this line

if ($HTTP_GET_VARS['products_id']) {

 

ADD BEFORE:

$has_xsell_products = false;

 

2. FOUND this line

if ($num_products_xsell > 0) {

 

ADD AFTER:

$has_xsell_products = true;

 

3. proceed to the very end and ADD BEFORE last ?> tag:

if(!$has_xsell_products) include(DIR_WS_MODULES . FILENAME_NEW_PRODUCTS);

 

That's all. Doesn't tested, but hypothetically must work.

 

Note: In this way you modify module xsell to show your new products.

 

There is another way - modify product_info.php to show up new products if no xsells found. This way you should do one more query to database to check is there a xsells for the product or not and request appropriate module. The query may be exactly the same as the main xsell query. In one word, you should do the same check twice - one time in product_info and second - on xsell_products module. This is not a good way. You also may modify xsell_product module so, you need not ask the query in it (using query from product_info.php).

Link to comment
Share on other sites

Version 2.7.2 uploaded.

 

Version fixes another bug with reciprocal links when you must check at least one link to product to save your reciprocal links in database. Now it works properly.

 

Freely contact me through PM.

Link to comment
Share on other sites

My PHP version is 5.2.9 and I have no problem with buy_now button. Unfortunatelly I have no chanses to test it on latest PHP version. But! I have a slightly modified buy_now button. It works in a form with POST method to prevent spiders to click on it. This is unusual modification which is never posted before. And I am afraid I can't post it too due to very more changes to my shop that prevents to write down instructions for how to modify buy_now button to POST method.

Link to comment
Share on other sites

Thanks, back to square one! <_<

Lets try to install POST buy_now button?

 

Find in catalog\includes\modelus\xsell_products.php

       $text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] .'</a><br>' . $xsell_price. '<br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=buy_now&product_to_buy_id=' . $xsell['products_id'], 'NONSSL') . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $xsell['products_name'] . TEXT_NOW) .'</a>';

REPLACE with

       $text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $xsell['products_image'], $xsell['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $xsell['products_id']) . '">' . $xsell['products_name'] .'</a><br>' . $xsell_price. '<br><form name="buy_now_' . $xsell['products_id'] . '" method="post" action="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=buy_now', 'NONSSL') . '"><input type="hidden" name="product_to_buy_id" value="' . $xsell['products_id'] . '">' . tep_image_submit('button_buy_now.gif', TEXT_BUY . $xsell['products_name'] . TEXT_NOW) . '</form>';

 

FIND in catalog\includes\application_top.php

// BOE: XSell
       if (isset($HTTP_GET_VARS['product_to_buy_id'])) {
         $parameters = array('action', 'pid', 'products_to_but_id');
	} else {
         $parameters = array('action', 'pid', 'products_id');
	}
// EOE: XSell

REPLACE with

// BOF: XSell
       if (isset($HTTP_POST_VARS['product_to_buy_id'])) {
         $parameters = array('action', 'pid', 'products_to_buy_id');
       } else {
         $parameters = array('action', 'pid');
       }
// EOF: XSell

 

 

FIND in catalog\includes\application_top.php

// BOF: XSell
     case 'buy_now' :        if (isset($HTTP_GET_VARS['product_to_buy_id'])) {
							if (tep_has_product_attributes($HTTP_GET_VARS['product_to_buy_id'])) {
							  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['product_to_buy_id']));
							} else {
							  $cart->add_cart($HTTP_GET_VARS['product_to_buy_id'], $cart->get_quantity($HTTP_GET_VARS['product_to_buy_id'])+1);
							}
                             } elseif (isset($HTTP_GET_VARS['products_id'])) {
// EOF: XSell

REPLACE with

// BOF: XSell
     case 'buy_now' :        if (isset($HTTP_POST_VARS['product_to_buy_id'])) {
                               if (tep_has_product_attributes($HTTP_POST_VARS['product_to_buy_id'])) {
                                 tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_POST_VARS['product_to_buy_id']));
                               } else {
                                 $cart->add_cart($HTTP_POST_VARS['product_to_buy_id'], $cart->get_quantity($HTTP_POST_VARS['product_to_buy_id'])+1);
                               }
                             } elseif (isset($HTTP_GET_VARS['products_id'])) {
// EOF: XSell

 

Seems that's all, but I found a little potential bug in my own code on working shop. Everything works OK, but additional testing are welcome. Test carefuly before apply to working shop. And take in memory, that all my buy_now buttons are on forms. That comes from that contrib and need to rework product_info so, that in your result html page there are no to <form> tags one followed by other <form>. Or your POST can't work.

 

Don't hesitate to write me about any bugs/suggestions/qustions/etc.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...