Forums / Templates, Stylesheets, Page Layout / Show quantity in cart only when the product is already in shopping cart

Show quantity in cart only when the product is already in shopping cart

Locked

Started by e81ny on 11 Jul 2007, 2:37 AM · Views: 4,708

Results 1 to 16 of 16
This thread is locked. New replies are disabled.
11 Jul 2007, 2:37 AM
#1
e81ny avatar

e81ny

New Zenner

Join Date:
Feb 2007
Location:
New York
Posts:
88
Plugin Contributions:
0

Show quantity in cart only when the product is already in shopping cart

Hi,

I'd like to know what I should do to make the "add to cart" button invisible on product info page when the product is already in the shopping cart?

  1. When the product is not in the shopping cart -> show "add to cart" button

  2. When the product is in the shopping cart -> show a message indicates that this product is already in the cart.

Can this be done?

Thanks for any suggestions!

11 Jul 2007, 2:39 AM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show quantity in cart only when the product is already in shopping cart

I know I made a post on this the other day, as in the last 45 days I think, that would change the add to cart to a delete button when the product is in the cart ...

Not sure where I might have put that ... :unsure:

Pretty sure that was a post and not just a quick fix for someone ... I think ... :blink:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

11 Jul 2007, 1:45 PM
#3
e81ny avatar

e81ny

New Zenner

Join Date:
Feb 2007
Location:
New York
Posts:
88
Plugin Contributions:
0

Re: Show quantity in cart only when the product is already in shopping cart

Ajeh:

I know I made a post on this the other day, as in the last 45 days I think, that would change the add to cart to a delete button when the product is in the cart ...

Not sure where I might have put that ... :unsure:

Pretty sure that was a post and not just a quick fix for someone ... I think ... :blink:

Hi. I tried to look in all the post you made but couldn't find anything related to my question.. Do you remember how you did that (change "add to cart" to "delete" when the product is in the cart) ?

Anybody else??

Thanks in advance.

11 Jul 2007, 1:54 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show quantity in cart only when the product is already in shopping cart

There is a function zen_get_buy_now_button ... that controls the button setting for add to cart so that it changes based on store status, customer authorization, product status such as call for price, sold out etc.

Adding a new case to it that changes the button to a delete or something other than an add to cart vs the other choices was the basic idea ...

This saved having to touch the code in numerous places ... and just using the one function to control it all ...

In this circumstance, the idea was if a product existed in quantity of 1 or greater it would switch to a delete button ...

Adding this code before the default in the last set of case statements should manage this:

// switch to delete button when at least 1 is in the cart
    case ($_SESSION['cart']->get_quantity($product_id) > 0):
      $return_button = '<a href="' . zen_href_link($_GET['main_page'], m zen_get_all_get_params(array('action')) . 'action=remove_product&product_id=' . $product_id) . '">' . zen_image_button(BUTTON_IMAGE_DELETE, BUTTON_IMAGE_DELETE_ALT) . '</a>';
      return $return_button;
      break;

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

12 Jul 2007, 2:49 AM
#5
e81ny avatar

e81ny

New Zenner

Join Date:
Feb 2007
Location:
New York
Posts:
88
Plugin Contributions:
0

Re: Show quantity in cart only when the product is already in shopping cart

If I only want to show a message saying this product is already in your cart, wouldn't that be much easier than swtiching to "delete" button?

Can't we just use something like:
if cart quantity = 1 , then show message "You have this in your cart"
else
show "add to cart" button

Of course the "code" is all wrong; maybe someone can help me put the code together?

Thanks!

12 Jul 2007, 4:14 AM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show quantity in cart only when the product is already in shopping cart

I am just showing you an example ...

You can adjust that to add on text or what have you ... or adjust the existing case statements ...

NOTE: The things in the cart when added already show:
Quantity in Cart: 1

However ... if the product is added with attributes, unless the customer comes in from the shopping_cart where the product includes the attributes it will not show ...

This could be altered if only the products_id was checked without the attribute attached ...

There is also the switch in the Catalog ... Product Type ... Edit Layout button where on the product_info page it shows this only if turned on:

Show Quantity in Shopping Cart
Display Quantity in Current Shopping Cart on Product Info 0= off 1= on

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

13 Jul 2007, 3:06 AM
#7
e81ny avatar

e81ny

New Zenner

Join Date:
Feb 2007
Location:
New York
Posts:
88
Plugin Contributions:
0

Re: Show quantity in cart only when the product is already in shopping cart

I was "playing" with the code and I came up with something like this:

<?php
     if ($_SESSION['cart']->in_cart($_GET['products_id'])) {
    
      echo $display_qty;
      
    } else {  
     
      echo $display_button; 
    }
?> 

It seems to work! It will say "Quantity in Cart: 1" when this product is in the shopping cart. If it's not in the cart, the "Add to Cart" button will show.

Linda, what do you think? Is there any concerns???

Thanks for any feedback!

PS. All product include only one attribute (download only).

13 Jul 2007, 3:16 AM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show quantity in cart only when the product is already in shopping cart

Have you an URL to your site that I could peek at?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

13 Jul 2007, 3:58 PM
#9
e81ny avatar

e81ny

New Zenner

Join Date:
Feb 2007
Location:
New York
Posts:
88
Plugin Contributions:
0

Re: Show quantity in cart only when the product is already in shopping cart

Here it is:

http://www.imagoformosa.com/catalog/

PS. Of course the iPhone and the image of Phil Collins are just samples; they are not my work..

13 Jul 2007, 5:20 PM
#10
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show quantity in cart only when the product is already in shopping cart

From what I can see you are trying to fix Centerboxes such as:
/includes/modules/new_products.php

and alter the code for the link to change to text vs the link ...

The other product_info appears to be working correctly ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

7 Sep 2007, 5:28 PM
#11
e81ny avatar

e81ny

New Zenner

Join Date:
Feb 2007
Location:
New York
Posts:
88
Plugin Contributions:
0

Re: Show quantity in cart only when the product is already in shopping cart

Ajeh,

I have to use attributes since my products are all download only and now the function I wanted (show "item already in cart" on product info page when the product is in the shopping cart) doesn't work anymore...

Yes, I remember you mentioned about that if attributes are used,then it would not work, etc... Is there any way to work around?? :(

8 Sep 2007, 1:39 AM
#12
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show quantity in cart only when the product is already in shopping cart

This will return the quantity in the shopping cart, in theory, of any products_id regardless of attributes or no attributes if you have Product Min/Unit Mixed YES

$_SESSION['cart']->in_cart_mixed((int)$_GET['products_id'])

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

8 Sep 2007, 1:35 PM
#13
e81ny avatar

e81ny

New Zenner

Join Date:
Feb 2007
Location:
New York
Posts:
88
Plugin Contributions:
0

Re: Show quantity in cart only when the product is already in shopping cart

Thanks Ajeh.

I think it is working but now I encounter another problem.

Now when I add a product to cart (for example: product_id=2), the link to the product from the cart page is:

http://www.imagoformosa.com/catalog/index.php?main_page=product_info&products_id=2:e69cb0dec6e16778f4c83cdbac368f23

What settings do I need to change to avoid something like "e69cb0dec6e16778f4c83cdbac368f23" being added after product_id=2 ??

I'm pretty sure the script will work properly if I can control that...

Thank you very much.

8 Sep 2007, 1:38 PM
#14
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show quantity in cart only when the product is already in shopping cart

That is what the (int) is for to change it to 2 instead of the 2 plus the attributes ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

8 Sep 2007, 1:49 PM
#15
e81ny avatar

e81ny

New Zenner

Join Date:
Feb 2007
Location:
New York
Posts:
88
Plugin Contributions:
0

Re: Show quantity in cart only when the product is already in shopping cart

A ha....

I took out the (int) and it works perfectly now...
Thank you very much!

8 Sep 2007, 2:34 PM
#16
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show quantity in cart only when the product is already in shopping cart

Handly little thing that (int) ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!