janetgot Posted June 5, 2008 Share Posted June 5, 2008 Hi, I'm trying to add extra functionality to the Fast Easy Cross Sell contribution, similar to the Variation to cross sell module http://addons.oscommerce.com/info/2539, which fill in random products if you don't have products selected through the module... however, I'm getting errors (probably because I'm not a great php coder! :rolleyes: ) Here's the code from the original module: <?php/* $Id: xsell_products.php, v1 2002/09/11 osCommerce, Open Source E-Commerce Solutions <http://www.oscommerce.com> Copyright © 2002 osCommerce Released under the GNU General Public License */ /* if product given */ if ($HTTP_GET_VARS['products_id']) { /* obtain the xsell product */ $xsell_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name from " . TABLE_PRODUCTS_XSELL . " xp, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where xp.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and xp.xsell_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_status = '1' order by xp.products_id asc limit " . MAX_DISPLAY_ALSO_PURCHASED); $num_products_xsell = tep_db_num_rows($xsell_query); /* if we equal or exceed the minimal amount of products */ if ($num_products_xsell >= MIN_DISPLAY_ALSO_PURCHASED) { /* put them in the box */ $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(); while ($xsell = tep_db_fetch_array($xsell_query)) { $xsell['products_name'] = tep_get_products_name($xsell['products_id']); $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_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>'); $col ++; if ($col > 2) { $col = 0; $row ++; } } /* if we have not enough products to fill the box */ if ($num_products_xsell < MAX_DISPLAY_ALSO_PURCHASED) { /* add some random products from the same category to fill the box */ $mtm= rand(); $xsell_cat_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $HTTP_GET_VARS['products_id'] . "'"); $xsell_cat_array = tep_db_fetch_array($xsell_cat_query); $xsell_category = $xsell_cat_array['categories_id']; $new_limit = MAX_DISPLAY_ALSO_PURCHASED - $num_products_xsell; $xsell_prod_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc, " . TABLE_PRODUCTS_DESCRIPTION . " pd where pc.categories_id = '" . $xsell_category . "' and p.products_id != '" . $HTTP_GET_VARS['products_id'] . "' and pc.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_status = '1' order by rand($mtm) desc limit " . $new_limit); while ($xsell = tep_db_fetch_array($xsell_prod_query)) { $xsell['products_name'] = tep_get_products_name($xsell['products_id']); $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_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>'); $col ++; if ($col > 2) { $col = 0; $row ++; } } } new contentBox($info_box_contents); } else { /* there are no xsell products registered at all for this product */ $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(); /* fill the box with all random products from the same category */ $mtm= rand(); $xsell_cat_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $HTTP_GET_VARS['products_id'] . "'"); $xsell_cat_array = tep_db_fetch_array($xsell_cat_query); $xsell_category = $xsell_cat_array['categories_id']; $new_limit = MAX_DISPLAY_ALSO_PURCHASED - $num_products_xsell; $xsell_prod_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc, " . TABLE_PRODUCTS_DESCRIPTION . " pd where pc.categories_id = '" . $xsell_category . "' and pc.products_id = p.products_id and p.products_id != '" . $HTTP_GET_VARS['products_id'] . "' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_status = '1' order by rand($mtm) desc limit " . MAX_DISPLAY_ALSO_PURCHASED); while ($xsell = tep_db_fetch_array($xsell_prod_query)) { $xsell['products_name'] = tep_get_products_name($xsell['products_id']); $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_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>'); $col ++; if ($col > 2) { $col = 0; $row ++; } } new contentBox($info_box_contents); } } ?> and here's my boggled code from the Fast Easy Checkout includes/modules/cross_sell_products.php <?php/* $Id: cross_sell_products.php, v1 2002/09/11 osCommerce, Open Source E-Commerce Solutions <http://www.oscommerce.com> Copyright © 2002 osCommerce Released under the GNU General Public License */ if ($HTTP_GET_VARS['products_id']) { $mtm= rand(); $cross_sell_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name, p.products_tax_class_id, products_price from " . TABLE_PRODUCTS_CROSS_SELL . " xp, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where xp.products_id = '" . $HTTP_GET_VARS['products_id'] . "' and xp.cross_sell_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_status = '1' order by rand($mtm) DESC limit " . MAX_DISPLAY_XSELL_PRODUCTS); $num_products_cross_sell = tep_db_num_rows($cross_sell_query); if ($num_products_cross_sell >= 1) { ?> <!-- cross_sell_products //--> <?php $info_box_contents = array(); $info_box_contents[] = array('align' => 'left', 'text' => TEXT_CROSS_SELL_PRODUCTS); new contentBoxHeading($info_box_contents); $row = 0; $col = 0; $info_box_contents = array(); $mtm= rand(); while ($cross_sell = tep_db_fetch_array($cross_sell_query)) { $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=' . $cross_sell['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $cross_sell['products_image'], $cross_sell['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br /><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $cross_sell['products_id']) . '">' . $cross_sell['products_name'] .'</a>'); $col ++; if ($col > 2) { $col = 0; $row ++; } new contentBox($info_box_contents); } else { /* there are no xsell products registered at all for this product */ $info_box_contents = array(); $info_box_contents[] = array('align' => 'left', 'text' => TEXT_CROSS_SELL_PRODUCTS); new contentBoxHeading($info_box_contents); $row = 0; $col = 0; $info_box_contents = array(); /* fill the box with all random products from the same category */ $mtm= rand(); $cross_sell_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $HTTP_GET_VARS['products_id'] . "'"); $cross_sell_array = tep_db_fetch_array($cross_sell_query); $cross_sell_category = $cross_sell_array['categories_id']; $new_limit = MAX_DISPLAY_ALSO_PURCHASED - $num_products_cross_sell; $cross_sell_prod_query = tep_db_query("select distinct p.products_id, p.products_image, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc, " . TABLE_PRODUCTS_DESCRIPTION . " pd where pc.categories_id = '" . $cross_sell_category . "' and pc.products_id = p.products_id and p.products_id != '" . $HTTP_GET_VARS['products_id'] . "' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_status = '1' order by rand($mtm) desc limit " . MAX_DISPLAY_ALSO_PURCHASED); while ($cross_sell = tep_db_fetch_array($cross_sell_prod_query)) { $cross_sell['products_name'] = tep_get_products_name($cross_sell['products_id']); $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=' . $cross_sell['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $cross_sell['products_image'], $cross_sell['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $cross_sell['products_id']) . '">' . $cross_sell['products_name'] . '</a>'); $col ++; if ($col > 2) { $col = 0; $row ++; } } new contentBox($info_box_contents); } ?> my initial error is Parse error: parse error in \includes\modules\cross_sell_products.php on line 43 which is right at the start of the code... if ($col > 2) { $col = 0; $row ++; } new contentBox($info_box_contents); } else { /* there are no xsell products registered at all for this product */ $info_box_contents = array(); $info_box_contents[] = array('align' => 'left', 'text' => TEXT_CROSS_SELL_PRODUCTS); new contentBoxHeading($info_box_contents); If I can get this to work, I can add it to the contibutions, as I think it is a great idea from the XSELL contribution. Any ideas on how to get it going? Thanks, Janet Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.