Guest Posted March 20, 2006 Posted March 20, 2006 Hi All, Has anyone sucessfully added "Customers who bought this also Purchased:" to the shopping cart, (just as you will find on amazon.com)? Or at the very least has anyone managed to turn the infobox off ONLY if their is nothing to show in the box??? Post 9 on this page http://www.oscommerce.com/forums/index.php?showtopic=165889&hl= alludes to this mod, but for PHP phobics there is no verbatim coding :blink: THANKS! x
boxtel Posted March 20, 2006 Posted March 20, 2006 Hi All, Has anyone sucessfully added "Customers who bought this also Purchased:" to the shopping cart, (just as you will find on amazon.com)? Or at the very least has anyone managed to turn the infobox off ONLY if their is nothing to show in the box??? Post 9 on this page http://www.oscommerce.com/forums/index.php?showtopic=165889&hl= alludes to this mod, but for PHP phobics there is no verbatim coding :blink: THANKS! x yes, I have but I use the also purchased pre-selection contrib for performance reasons. even then I am not sure I keep it in this form. Treasurer MFC
Guest Posted March 20, 2006 Posted March 20, 2006 yes, I have but I use the also purchased pre-selection contrib for performance reasons. even then I am not sure I keep it in this form. Thanks for the reply. I have found the mod you mention here: http://www.oscommerce.com/community/contributions,3294 What I would like (and many others I am sure!) is a step by step guide to the changes required or a code example for us to follow. I originally read your comments on the post I mentioned previously and I quote "well, also purchased expects a product id in the url (GET) and when in the shopping cart that is not present. Instead it gets the products id's from the cart object. So you need to decide which product in the cart you wish to process this on and set that as the $_GET['products_id'] so that the module will process correctly. If you want to do all products in the cart then you need to revise the also purchased box because currently it only takes 1 product and for very good (performance) reasons." This does make some sense but I as I am note sure of the exact coding guidance would be appreciated! Many Thanks (again!) Barry
boxtel Posted March 21, 2006 Posted March 21, 2006 Thanks for the reply. I have found the mod you mention here: http://www.oscommerce.com/community/contributions,3294 What I would like (and many others I am sure!) is a step by step guide to the changes required or a code example for us to follow. I originally read your comments on the post I mentioned previously and I quote "well, also purchased expects a product id in the url (GET) and when in the shopping cart that is not present. Instead it gets the products id's from the cart object. So you need to decide which product in the cart you wish to process this on and set that as the $_GET['products_id'] so that the module will process correctly. If you want to do all products in the cart then you need to revise the also purchased box because currently it only takes 1 product and for very good (performance) reasons." This does make some sense but I as I am note sure of the exact coding guidance would be appreciated! Many Thanks (again!) Barry the preselection contrib basically takes the huge join query offline and runs it periodically. it fills a result table which can then be used online with greater speed. It also makes it true "also purchased" as the osc original only considers also purchased if purchased in the same order. This version does not care in which order the other product was purchased as long as it was done by the same person. so the result table is a simple product id to also purchased id table which makes for very easy querying. in the original also purchased module, it uses the product id from the GET array as in : where products_id = $_GET['products_id'] which implies that that module only produces something if the products id is in the url, product_info.php for instance. But that limits the whole use of that module as shopping_cart.php and order_confirmation.php do not have that in their url. So what I do (with ap preselection) is pass an array with product_id's to that module and if I do not have the module create that array with the products id from $_GET as in : if (!isset($ap_array)) { $ap_array = array(); $ap_array[] = $_GET['products_id']; } then in the rest of the module I use that array to process the logic rather than the get variable. this way I can fill the $ap_array with id's from the cart or the order or whatever, call the module and it uses those id's. If I do not define the $ap_array but still call the module, the module itself will take the products_id from get and define the array. then you create a query which uses all data from the array to get the also purchased info from all of them. In shopping_cart.php I fill the $ap_array in the normal existing products loop with : $ap_array[] = $products[$i]['id']; then later I call the module with : <td><?php include(DIR_WS_MODULES . 'also_purchased.php');?></td> and the module itself looks like this (do not simply copy, just as a reference): <?php if (!isset($ap_array)) { $ap_array = array(); $ap_array[] = $_GET['products_id']; } $n = sizeof($ap_array); if ($n > 0) { $max_colums = 3; $max_search = 3; $mtm= rand(); $ap_query_string = "select distinct ap.ap_id, p.products_price, p.products_retail_price, p.products_image, p.products_model, pd.products_name from ap_preselection ap, products_description pd, products p where ("; for ($i=0; $i<$n; $i++) { if ($i>0) $ap_query_string .= " or "; $ap_query_string .= " ap.products_id = '" . $ap_array[$i] . "'"; } $ap_query_string .= ") and ("; for ($i=0; $i<$n; $i++) { if ($i>0) $ap_query_string .= " and "; $ap_query_string .= " ap.ap_id != '" . $ap_array[$i] . "'"; } $ap_query_string .= ") and "; $ap_query_string .= "p.products_id = ap.ap_id and pd.products_id = ap.ap_id and p.products_quantity > 0 and p.products_price > 0 and pd.language_id = '" . $languages_id . "' and p.products_status = '1' order by rand($mtm) DESC limit " . $max_search; $ap_query = tep_db_query($ap_query_string ); $num_products_ordered = tep_db_num_rows($ap_query); if ($num_products_ordered >= 1) { $prod_width = 100/$num_products_ordered; switch (basename($PHP_SELF)) { case 'shopping_cart.php' : $location = 'products in your basket';break; case 'order_confirmation.php' : $location = 'products in your order';break; case 'product_info.php' : $location = 'this product';break; } echo '<table width="100%"><tr><td align="center" class="feat">Customers who bought '.$location.' also purchased...</td></tr></table>'; $tbl_bg = '#FFFFFF'; $row = 0; $col = 0; $info_box_contents = array(); while ($orders = tep_db_fetch_array($ap_query)) { $lc_text = '<table width="100%" align="center" class="borderWhite" style="background-color: #ffffff;"> <tr height="130px"><td align="center" class="smalltext">' . '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['ap_id']) . '">' . tep_image(DIR_WS_PRODUCT_IMAGES . $orders['products_image'], $orders['products_name']) . '</a>' . '</td></tr>'; $lc_text .= '<tr><td class="vsmalltext" valign="top" align="center">'; $lc_text .= '[' . $orders['products_model'] . ']</td></tr>'; $lc_text .= '<tr height="50px"><td valign="top" align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['ap_id']) . '">' . $orders['products_name'] . '</a></td></tr>'; $lc_text .= '<tr height="33">'; $lc_text .= '<td align="center" valign="middle"> <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action','zx','azx','yx','x','y','msg','sort','lng','language','currency')) . 'action=buy_now&products_id=' . $orders['ap_id'], 'NONSSL') . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a></td>'; $lc_text .= '</tr>'; $lc_text .= '<tr><td valign="top" align="center">'; $lc_text .= price_info($orders, true, true); $lc_text .= '</td></tr>'; $lc_text .= '</table>'; $info_box_contents[$row][$col] = array('align' => 'center', 'params' => 'width="' . $prod_width . '%" valign="top" style="background-color: #FFFFFF;"', 'text' => $lc_text); $col ++; if ($col >= $max_colums) { $col = 0; $row ++; } } new contentBox($info_box_contents, '#ffffff'); echo '<tr><td>' . tep_draw_separator('pixel_trans.gif', '100%', '10') . '</td></tr>'; } } ?> Treasurer MFC
Recommended Posts
Archived
This topic is now archived and is closed to further replies.