Post by elderblei » Thu Jan 08, 2009 11:13 am

Hi, first of all thanks for this great open script. These past weeks I've been modding my Open Cart installation to suit my specific needs, but I found no answer to this:

Is there a way to hide products (from Category list, search results or anywhere else) wich were already added to the cart?

That's because I want to run a store with thounsands of unique items. So all the products will have a "1" quantity and it will be much less confusing for the customer not to see again the products he already "purchased".

Best regards and thanks in advance!

Newbie

Posts

Joined
Sun Nov 23, 2008 1:23 am

Post by elderblei » Sun Jan 11, 2009 9:23 pm

Hi again, folks. At least tell me if this is possible at all.

Thanks again and best regards.

Newbie

Posts

Joined
Sun Nov 23, 2008 1:23 am

Post by bruce » Sun Jan 11, 2009 9:34 pm

It is possible but not as a store configuration option. You will have to change some of the code.

On each of the controllers that get product data to display on a page, you will have to remove any items that have been selected in the shopping cart ( $cart->getProducts() ) from the $results array returned by the "normal" query.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by elderblei » Mon Jan 12, 2009 2:44 am

Hi Bruce! Thanks so much for your answer. I'm not a coder, though, so I don't know how to do that (but I understand the logics behind your idea).

By the way, I've already been playing with the category controller and added the p.quantity > 0 just as you mentioned here:

http://forum.opencart.com/index.php/topic,950.0.html

I discovered from that that the stock is modified only after the checkout process. That's why I needed another solution to hide the products which are in the cart.

My $results in the category controller now reads like this:

Code: Select all

$results = $database->getRows($database->splitQuery("select * from product p left join product_description pd on (p.product_id = pd.product_id) left join product_to_category p2c on (p.product_id = p2c.product_id) left join image i on (p.image_id = i.image_id) where status = '1' and language_id = '" . (int)$language->getId() . "' and p2c.category_id = '" . (int)end(explode('_', $request->get('path'))) . "' and p.date_available < now() and p.status = '1' and p.quantity > 0 order by p.sort_order, pd.name", ($request->has('path') ? $session->get('category.' . $request->get('path') . '.page') : $session->get('category.page')), $config->get('config_max_rows')));
Please, can you tell me how can I correctly implement the $cart->getProducts() trick within this controller?

I'll be really grateful. Thank you very much for your time and best regards.

Newbie

Posts

Joined
Sun Nov 23, 2008 1:23 am

Post by bruce » Mon Jan 12, 2009 5:09 pm

Ok, for the category controller...

add the following to the top of the index() function along with the other similar declarations.

Code: Select all

		$cart      =& $this->locator->get('cart');
under the product results line put the following. Note that I have replaced unrelated code elements with ...

Code: Select all


				$results = ...
				//  experiment
				$cart_products = $cart->getProducts();
				$cart_product_ids = array();
				foreach ($cart_products as $prod)
				{
					//  get just the productID's
					$cart_product_ids[] = $prod['product_id'];
				}

				foreach ($results as $result)
				{
					...
					// if the product is not in the cart, allow it into the final result set.
					if (!in_array($result['product_id'], $cart_product_ids))
					{
						$product_data[] = array(
							...
						);
					}
				}

You should be able to duplicate this process in the Latest/Featured/Specials modules if you want to.

Cheers

Bruce

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by elderblei » Mon Jan 26, 2009 4:36 am

Hi Bruce, it worked smoothly. Thank you very much for your solution. I had to battle a little with the script but that was because I'm not a developer.

Again, thanks for the answer and best regards.

Newbie

Posts

Joined
Sun Nov 23, 2008 1:23 am
Who is online

Users browsing this forum: No registered users and 4 guests