Categories
Interspire

Add 'Customers Also Purchased' to the Cart Page on Interspire Shopping Cart

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

  1. Keep the existing “Also Bought/Purchased” functionality working on product pages
  2. Add “Also Bought/Purchased” functionality to the cart page
  3. 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!

By Zack Katz

Zack Katz is the founder of GravityKit and TrustedLogin. He lives in Leverett, Massachusetts with his wife Juniper.

4 replies on “Add 'Customers Also Purchased' to the Cart Page on Interspire Shopping Cart”

Hi,
Thanks for this MOD. I’m facing some problems implementing this, when i add some products to cart appear a blank page, is something i’m doing wrong? I saw the code is missing the { keys…
I need to ask you something outside of this post: I’ve made some changes in ISC code to hide unavailable variations, eg. if the quantity of variation is 0 the variation dont appear in variation list, this mod i do correctely.
Now i’m facing another problem, when i dont have any variations available, i want to show a message telling Unavailable and Hide Add to Cart button, i saw the full code of display/ProductDetails but i cant implementing this… Have you any ideas?
Thanks for your work…

@Mozack: You’re right to look in includes/display/ProductDetails.php. That’s where you would set up that PHP logic. Unfortunately, Interspire is much more…manual in these things than software like WordPress. That’s because Interspire templates are so differently processed.

You’d have to run through each variation and see if any had availability, if not, then hide them…you get the idea.

Hi Zack,
Thanks for your answer. As i told, i add 1 line of code to pass only available variables. I’ve opened the file includes/classes/class.product.php and after the line 304 i add this code: vcstock > 0 AND. Everything work great. Now only the available variations are shown in product page.
I think this is a user friendly problem of InterSpire Shopping Cart if you have a lot of products and always the customers goes to your store and when they try to choose a size of a product that is unavailable they always will see the message but just when they click on size they want… Thats a bad idea (in my opinion).
The actual problem is: When all variables are unavailable (all of them are hidden by the code) how to hide the add to cart button and show the unavailable message? This code dont disable the variation, only hide it in product page… And that’s the problem.
I saw all piece os code in productdetails.php and i think the point is around line 199 but there are just 2 statements:
1 – Product is saleable
2 – Product active/inactive variations
It means that here we should get again the variables with vcstock > 0 to show anf if =0 show the unavailable message.
Well, i’m not a good programmer, i can only check the code and make some little changes in it 🙂
Thanks for your mods and your answer…
Mozack
 

Hi again,
Ok, the problem with { keys was resolved… Thanks for this mod.
If you can, please answer me to the other question….
Thanks
 

Comments are closed.