The code below is an example, it does work but please don't use it "out of the box" (a.o. because some texts are harcoded and it will mess up your current cross sell layout).
It includes:
- Buy Now buttons
- More Info links
- a quantity input field
- quantity in cart display (optional)
includes\modules\YOUR_TEMPLATE\xsell_products.php (it's an example of the the module file only):
Code:
<?php
/**
* Cross Sell products
*
* Derived from:
* Original Idea From Isaac Mualem [email protected] <mailto:[email protected]>
* Portions Copyright (c) 2002 osCommerce
* Complete Recoding From Stephen Walker [email protected]
* Released under the GNU General Public License
*
* Adapted to Zen Cart by Merlin - Spring 2005
* Reworked for Zen Cart v1.3.0 03-30-2006
*/
// in case admin switches aren't added properly, assume default settings:
if (!defined('MAX_DISPLAY_XSELL')) define('MAX_DISPLAY_XSELL',6);
if (!defined('MIN_DISPLAY_XSELL')) define('MIN_DISPLAY_XSELL',1);
if (!defined('XSELL_DISPLAY_PRICE')) define('XSELL_DISPLAY_PRICE','false');
if (!defined('SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS')) define('SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS',2);
// collect information on available cross-sell products for the current product-id
if (isset($_GET['products_id']) && SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS > 0 ) {
$xsell_query = $db->Execute("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 = '" . $_GET['products_id'] . "'
and xp.xsell_id = p.products_id
and p.products_id = pd.products_id
and pd.language_id = '" . $_SESSION['languages_id'] . "'
and p.products_status = 1
order by xp.sort_order asc limit " . MAX_DISPLAY_XSELL);
$num_products_xsell = $xsell_query->RecordCount();
// don't display if less than the minimum amount set in Admin->Config->Minimum Values->Cross-Sell
if ($num_products_xsell >= MIN_DISPLAY_XSELL && $num_products_xsell > 0) {
?>
<!-- xsell_products //-->
<?php
$row = 0;
$col = 0;
$list_box_contents = array();
$title='';
if ($num_products_xsell < SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS==0) {
$col_width = floor(100/$num_products_xsell);
} else {
$col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS);
}
while (!$xsell_query->EOF) {
$products_price = zen_get_products_display_price($xsell_query->fields['products_id']);
$xsell_query->fields['products_name'] = zen_get_products_name($xsell_query->fields['products_id']);
//$list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsCrossSell centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
//'text' => '<a href="' . zen_href_link(zen_get_info_page($xsell_query->fields['products_id']), 'products_id=' . (int)$xsell_query->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $xsell_query->fields['products_image'], $xsell_query->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br /><a href="' . zen_href_link(zen_get_info_page($xsell_query->fields['products_id']), 'products_id=' . $xsell_query->fields['products_id']) . '">' . $xsell_query->fields['products_name'] . '</a>' . (XSELL_DISPLAY_PRICE=='true'? '<br />'.zen_get_products_display_price($xsell_query->fields['products_id']):'') );
// bof buy now buttons
$myBuyNow = '';
//$flag_show_product_info_in_cart_qty = 1;
$myBuyNow .= zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($xsell_query->fields['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product'), 'post', 'enctype="multipart/form-data"') . "\n";
$myBuyNow .= 'Aantal' . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($xsell_query->fields['products_id'])) . '" maxlength="6" size="4" />' . "\n";
//$myBuyNow .= zen_get_products_quantity_min_units_display($xsell_query->fields['products_id']) . "\n";
$myBuyNow .= zen_draw_hidden_field('products_id', $xsell_query->fields['products_id']);
// '<img alt="Aan winkelwagen toevoegen" class="cart-add" src="' . $template->get_template_dir('my_cart_add.png', DIR_WS_TEMPLATE, $current_page_base,'images') . '/cart-add.gif" />';
//$myBuyNow .= zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT);
$myBuyNow .= zen_image_submit('my_cart_add.png', 'Voeg toe aan winkelwagen.');
$myBuyNow .= '</form>';
//$myBuyNow .= (($flag_show_product_info_in_cart_qty == 1 and $_SESSION['cart']->in_cart($xsell_query->fields['products_id'])) ? '<p class="xsellProductsInCart">' . PRODUCTS_ORDER_QTY_TEXT_IN_CART . $_SESSION['cart']->get_quantity($xsell_query->fields['products_id']) . '</p>' : '');
// eof buy now buttons
$list_box_contents[$row][$col] = array('params' =>'class="grid_layout"',
'text' => '<a class="crossSellImageLink" href="' . zen_href_link(zen_get_info_page($xsell_query->fields['products_id']), 'products_id=' . $xsell_query->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $xsell_query->fields['products_image'], $xsell_query->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>' . "\n" .
'<h4><a href="' . zen_href_link(zen_get_info_page($xsell_query->fields['products_id']), 'products_id=' . $xsell_query->fields['products_id']) . '">' . $xsell_query->fields['products_name'] . '</a></h4>' . "\n" .
'<h3>' . $products_price . '</h3>' . "\n" .
'<a class="crossSellLink" href="' . zen_href_link(zen_get_info_page($xsell_query->fields['products_id']), 'products_id=' . $xsell_query->fields['products_id']) . '">' . '[meer info]' . '</a>' . "\n" .
'<div class="crossSellBuyNow">' .
$myBuyNow . '</div>' . "\n"
);
$col ++;
if ($col > (SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS -1)) {
$col = 0;
$row ++;
}
$xsell_query->MoveNext();
}
// store data into array for display later where desired:
$xsell_data = $list_box_contents;
}
}
?>
The changes are (partly?) commented by "// bof buy now buttons" and "// eof buy now buttons"