This article is about the Interspire Shopping Cart. Don't use it? Check it out!
Go to Interspire.com and Learn More
“Customers Also Purchased” should be on the cart page, right?
The Interspire Shopping Cart has a “Customers Also Bought” feature, but for some reason, they didn’t think to make it functional on the cart page — one of the most useful (and obvious) places to have the feature. This modification will allow you to place the SideProductAlsoBought panel into your theme’s cart.html template, using the %%Panel.SideProductAlsoBought%% placeholder in the template.
Goals of this mod
- Keep the existing “Also Bought/Purchased” functionality working on product pages
- Add “Also Bought/Purchased” functionality to the cart page
- Give an option where it will only display “Also Bought” for the most recently added product
With those goals in mind, I went about implementing a solution, which is below:
Find the following code in /includes/display/SideProductAlsoBought.php:
$query = " SELECT ordprodid FROM [|PREFIX|]order_products WHERE orderorderid IN (SELECT orderorderid FROM [|PREFIX|]order_products WHERE ordprodid='".$GLOBALS['ISC_CLASS_PRODUCT']->GetProductId()."') AND ordprodid != ".$GLOBALS['ISC_CLASS_PRODUCT']->GetProductId()." GROUP BY ordprodid ORDER BY COUNT(ordprodid) DESC ";
Add replace it with this code:
// Begin: Allow users also bought for recently added products
$OnlyRecentlyAdded = false; // make true to only show Also Bought for the product that was just added.
if(isset($GLOBALS['ISC_CLASS_CART'])) {
if($OnlyRecentlyAdded && isset($_REQUEST['suggest'])) {
$cartProduct = $GLOBALS['ISC_CLASS_CART']->api->GetProductInCart($_REQUEST['suggest']);
if(is_array($cartProduct)) {
$this->newCartItem = $_REQUEST['suggest'];
$productId = $cartProduct['product_id'];
}
$queryIds[0] = " ordprodid='".$productId."'";
$queryIds[1] = " ordprodid !=".$productId;
} else {
$cartProducts = $GLOBALS['ISC_CLASS_CART']->api->GetProductsInCart();
if(is_array($cartProducts)) {
foreach($cartProducts as $product) {
$i++;
if(!in_array($product['product_id'], $productIds)) {
$productIds[] = $product['product_id'];
$queryIds[0] .= ' ordprodid=\''.$product['product_id'].'\'';
$queryIds[1] .= ' ordprodid != '.$product['product_id'];
}
if(isset($cartProducts[$i]) && !in_array($cartProducts[$i]['product_id'],$productIds)) {
$queryIds[0] .= ' OR';
$queryIds[1] .= ' AND';
}
}
}
}
} else {
$queryIds[0] = " ordprodid='".$GLOBALS['ISC_CLASS_PRODUCT']->GetProductId()."'";
$queryIds[1] = " ordprodid !=".$GLOBALS['ISC_CLASS_PRODUCT']->GetProductId();
}
$query = "
SELECT ordprodid
FROM [|PREFIX|]order_products
WHERE orderorderid IN (SELECT orderorderid FROM [|PREFIX|]order_products WHERE".$queryIds[0].") AND".$queryIds[1]."
GROUP BY ordprodid
ORDER BY COUNT(ordprodid) DESC
";
// End: Allow users also bought for recently added products
This adds a little load time to the cart.php page, but it will help cross-sell products.
Did this make your life easier? Was this information worth a buck?
Donate & help keep the Interspire mods free on this site!
