Archives for 

Shopping Cart

Add ‘Customers Also Purchased’ to the Cart Page on Interspire Shopping Cart

“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.

Related posts:

  1. Preview Hidden Products in Interspire Shopping Cart
  2. Generate CSS Body Classes in Interspire Shopping Cart
  3. How to Add an `Edit Product` Link for Interspire Shopping Cart