Thank you.
Printable View
Thank you.
Since I was translating this to Italian, I thought to edit YOUR_RENAMED_ADMIN/multi_xsell.php in order to make it easy for people to localize it by adding the defines.
I attach a copy for you, if you think could be worth for the next update; in case double check the files - they do work on my Zen Cart.
In thes setup using this I have a superuser (administrator), and a second user profile, for the latter I have enabled the access to catalog>>cross sell, and configuration>>cross sell settings, but when trying to access catalog>>cross sell I get the following:
"Sorry, your security clearance does not allow you to access this resource.
Please contact your site administrator if you believe this to be incorrect.
Sorry for any inconvenience."
No problem in accessing configuration>>cross sell settings
Thank you.
Thank you, I appreciate your patience.
I know a few people have asked how to get the cross sells to show in the shopping cart, so I thought I'd post a solution. I didn't write this from scratch, just made a few changes to an old mod (Upsells/Cross Sells in Shopping Cart). I've only tested this on v1.5.1.
Create a new file: includes/modules/YOUR_TEMPLATE/cart_upsell.php with this code:
Add this to your includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart.php file wherever you want the cross sells to show up:Quote:
<?php
if (!defined('MAX_DISPLAY_XSELL')) define('MAX_DISPLAY_XSELL',6);
if (!defined('MIN_DISPLAY_XSELL')) define('MIN_DISPLAY_XSELL',1);
if (!defined('SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS')) define('SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS',3);
if ($_SESSION['cart']->contents) {
$i = 0;
foreach($_SESSION['cart']->contents as $id => $qty) {
$prod[$i] = zen_get_prid($id);
$i++;
}
$cross_sell = 1;
//check if cross_sell module installed
if (@file_exists(DIR_WS_MODULES . zen_get_module_directory('multi_xsell_products.php'))) {
$c = MAX_DISPLAY_XSELL;
$num = round($c/sizeof($prod));
$extra = $num + 1;
$max = $c;
for ($i = 0; $i < sizeof($prod); $i++) {
if ($i < sizeof($prod) - 1) {
$cross_sell_sort_by = XSELL_SORT_ORDER . $mxsell=="sort_order"?" order by xp.sort_order asc ": " order by rand() ";
$cross_sell_query_raw .= "(select p.products_id, p.products_image
from " . TABLE_PRODUCTS_MXSELL . $cross_sell . " xp, " .
TABLE_PRODUCTS . " p, " .
TABLE_PRODUCTS_DESCRIPTION . " pd
where xp.products_id = '" . $prod[$i] . "'
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 " .
$cross_sell_sort_by." limit " . MAX_DISPLAY_XSELL . ") UNION ";
$c -= $num;
} else {
$c += 2;
$cross_sell_sort_by = XSELL_SORT_ORDER . $mxsell=="sort_order"?" order by xp.sort_order asc ": " order by rand() ";
$cross_sell_query_raw .= "(select p.products_id, p.products_image
from " . TABLE_PRODUCTS_MXSELL . $cross_sell . " xp, " .
TABLE_PRODUCTS . " p, " .
TABLE_PRODUCTS_DESCRIPTION . " pd
where xp.products_id = '" . $prod[$i] . "'
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 " .
$cross_sell_sort_by." limit " . MAX_DISPLAY_XSELL . ")";
}
}
$cross_sell_query = $db->Execute($cross_sell_query_raw);
$db->Execute("create temporary table cross_sell ( products_id int(11), products_image varchar(64) )");
while (!$cross_sell_query->EOF) {
$db->Execute("insert into cross_sell values('" . $cross_sell_query->fields['products_id'] . "', '" . $cross_sell_query->fields['products_image'] . "')");
$cross_sell_query->MoveNext();
}
for ($i = 0; $i < sizeof($prod); $i++) {
$db->Execute("delete from cross_sell where products_id = '" . $prod[$i] . "'");
}
$cross_sell_query_final = "select * from cross_sell limit " . $max;
$cross_sell_final = $db->Execute($cross_sell_query_final);
$db->Execute("drop table cross_sell");
$num_products_cross_sell = $cross_sell_final->RecordCount();
if ($num_products_cross_sell >= MIN_DISPLAY_XSELL) {
$row = 0;
$col = 0;
$list_box_contents = array();
$title = '';
if ($num_products_cross_sell < SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS==0) {
$col_width = floor(100/$num_products_cross_sell);
} else {
$col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS);
}
while (!$cross_sell_final->EOF) {
if (zen_has_product_attributes($cross_sell_final->fields['products_id']) or PRODUCT_LIST_PRICE_BUY_NOW == '0') {
$lc_button = '<br /><a href="' . zen_href_link(zen_get_info_page($cross_sell_final->fields['products_id']), '&products_id=' . $cross_sell_final->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a><br />';
} else {
$lc_button = '<br /><a href="' . zen_href_link(FILENAME_SHOPPING_CART, 'action=buy_now&products_id=' . $cross_sell_final->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT) . '</a>';
}
$cross_sell_final->fields['products_name'] = zen_get_products_name($cross_sell_final->fields['products_id']);
$list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsCrossSell centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => '<div class="listingProductImage" style="margin-top: 5px; margin-bottom: 5px;"><a href="' . zen_href_link(zen_get_info_page($cross_sell_final->fields['products_id']), 'products_id=' . $cross_sell_final->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $cross_sell_final->fields['products_image'], $cross_sell_final->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></div>'. (constant(CROSS_SELL.$cross_sell._DISPLAY_NAME)=='true'? '<div class="itemTitle"><h4 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($cross_sell_final->fields['products_id']), 'products_id=' . $cross_sell_final->fields['products_id']) . '">' . $cross_sell_final->fields['products_name'] . '</a></h4></div>':'').(constant(CROSS_SELL.$cross_sell._DISPLAY_MODEL)=='true'? '<div class="itemModel"><h4 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($cross_sell_final->fields['products_id']), 'products_id=' . $cross_sell_final->fields['products_id']) . '">' . zen_products_lookup($cross_sell_final->fields['products_id'], 'products_model') . '</a></h4></div>':'').(constant(CROSS_SELL.$cross_sell._DISPLAY_PRICE)=='true'? '<div class="price">'.zen_get_products_display_price($cross_sell_final->fields['products_id']).'</div>':'') .(constant(CROSS_SELL.$cross_sell._DISPLAY_BUY_NOW)=='true'? '<div class="listingBuyNowButton">'.$lc_button.'</div>':'') );
$col ++;
if ($col > 2) {
$col = 0;
$row ++;
}
$cross_sell_final->MoveNext();
}
$cross_sell_data = $list_box_contents;
?>
<br class="clearBoth">
<div class="centerBoxWrapper" id="crossSell">
<?php
require($template->get_template_dir('tpl_columnar_display.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_columnar_display.php');
?>
</div>
<?php
}
}
}
?>
That's it!Quote:
<?php require(DIR_WS_MODULES . zen_get_module_directory('cart_upsell.php')); ?>
What a great day. I've been searching for this fix for so long.
Completely appreciate you taking the time to post this solution.
(Might be good to pack for the Plugins section)
Any idea how I might add a line of text above the xsells on the shopping cart page, that says "We thought you might like to add..."?
I'm concerned people might think they're checking out with the item I'm recommending, instead of what they added to cart.
Or even a horizontal rule to separate...
Again, much appreciated!
Sure, just put this in the shopping_cart.tpl file:
That's not the cleanest way to do it, but it will work for now. When I have a chance I will package it up as a mod and add language definitions, etc.Quote:
<h2>You May Also Like...</h2>
<hr/>
<?php require(DIR_WS_MODULES . zen_get_module_directory('cart_upsell.php')); ?>
Brilliant :)