Jump to content

PS 1.5 Crosselling Module


Recommended Posts

Is it possible to show in the crosselling module the products that customers who have also bought this product have bought, but not in the same order?


I've tried to update the code this way, but it's not working:


I've tried to get the id_customer of the orders, and then search for all the orders on that customers.



$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
			SELECT o.id_order, o.id_customer
			FROM '._DB_PREFIX_.'orders o
			LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
			WHERE o.valid = 1 AND od.product_id = '.(int)$params['product']->id);

			if (sizeof($orders))
				$list = '';
				$list_c = '';
				foreach ($orders AS $order){
					$list .= (int)$order['id_order'].',';
					$list_c .= (int)$order['id_customer'].',';
				$list = rtrim($list, ',');
				$list_c = rtrim($list_c, ',');
				$orders2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
						SELECT o.id_order
						FROM '._DB_PREFIX_.'orders o
						WHERE o.valid = 1 AND o.id_customer IN ('.$list_c.')');
				if (sizeof($orders2))
					foreach ($orders AS $order){
					$list .= (int)$order['id_order'].',';

				$list = rtrim($list, ',');

				$orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
					SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13
					FROM '._DB_PREFIX_.'order_detail od
					LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
					'.Shop::addSqlAssociation('product', 'p').'
					LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
					LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
					LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
					WHERE od.id_order IN ('.$list.')
						AND pl.id_lang = '.(int)$this->context->language->id.'
						AND cl.id_lang = '.(int)$this->context->language->id.'
						AND od.product_id != '.(int)$params['product']->id.'
						AND i.cover = 1
						AND product_shop.active = 1
					LIMIT '.(int)Configuration::get('CROSSSELLING_NBR').'

Any ideas will be appreciated, thank you!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...