Zen Cart Logo
Forums / General Questions / Dynamically testing products in a cart for it's delivery type.

Dynamically testing products in a cart for it's delivery type.

Locked

Views: 1,216

Results 1 to 16 of 16
This thread is locked. New replies are disabled.
23 Sep 2010, 8:11 PM
#1
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Dynamically testing products in a cart for it's delivery type.

Does anyone know if there is a way to dynamically test each item in a shopping cart to see if it's a virtual item or not?

I'm currently using the cart's -> delivery_type method but the only problem I have with this is that when I test to see if a cart's contents is virtual or mixed, it works. But if I delete the item that is causing it register as virtual/mixed, the variable still returns that it's a mixed delivery type which is not the case.

Can anyone help?

23 Sep 2010, 8:28 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Dynamically testing products in a cart for it's delivery type.

If it's reporting that it's mixed when you think they're really virtual, then that suggests that you've got your products configured incorrectly.

23 Sep 2010, 8:38 PM
#3
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Dynamically testing products in a cart for it's delivery type.

DrByte:

If it's reporting that it's mixed when you think they're really virtual, then that suggests that you've got your products configured incorrectly.

That's what I originally thought but I checked and they're properly setup. I'll give an example:

A cart contains two items:

  • One Virtual Delivery Item
  • One Non-Virtual Delivery Item

Clearly this is a mixed cart. But if on the shopping cart page I delete either one, say I deleted the virtual delivery item:

  • One Non-Virtual Delivery Item

The cart will still return that it's mixed delivery that is until I refresh the shopping cart page and then it updates to non-virtual.

23 Sep 2010, 8:49 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Dynamically testing products in a cart for it's delivery type.

What do you mean by "refresh the shopping cart page"?
Deleting an item from the cart does cause a refresh of the page.

24 Sep 2010, 5:48 AM
#5
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Dynamically testing products in a cart for it's delivery type.

It doesn't for me.

I would update the cart using the delete button for the item. The page would reload, then I would still see that the cart contents are mixed and not physical like it should.

I test it by looking at the $_SESSION['cart']->content_type variable. What I was asking for is there another way to test instead of testing this?

24 Sep 2010, 2:17 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Dynamically testing products in a cart for it's delivery type.

What addons do you have installed?
What kinds of customizations have you made to the site?

24 Sep 2010, 7:34 PM
#7
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Dynamically testing products in a cart for it's delivery type.

DrByte:

What addons do you have installed?
What kinds of customizations have you made to the site?

None that would directly interfere with the shopping cart itself. Every mod I made was to the admin but none to the way cookies are handled.

24 Sep 2010, 7:56 PM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Dynamically testing products in a cart for it's delivery type.

cookies?

24 Sep 2010, 8:17 PM
#9
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Dynamically testing products in a cart for it's delivery type.

DrByte:

cookies?

I thought that the $_SESSION['cart'] was stored in a session cookie?

24 Sep 2010, 8:42 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Dynamically testing products in a cart for it's delivery type.

No. $_SESSION['cart'] is a session variable, stored in the session.

The only use of cookies in (uncustomized) Zen Cart is to store the session identifier so your browser can tell the server which session you're using.

24 Sep 2010, 8:43 PM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Dynamically testing products in a cart for it's delivery type.

retched:

It doesn't for me.

I would update the cart using the delete button for the item. The page would reload, then I would still see that the cart contents are mixed and not physical like it should.
I'm puzzled at why it's doing that. It shouldn't be.

24 Sep 2010, 8:50 PM
#12
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Dynamically testing products in a cart for it's delivery type.

DrByte:

I'm puzzled at why it's doing that. It shouldn't be.

Are you having the same issue?

24 Sep 2010, 8:58 PM
#13
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Dynamically testing products in a cart for it's delivery type.

Haven't tried it myself today.

25 Sep 2010, 7:48 PM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Dynamically testing products in a cart for it's delivery type.

So, I just tested this, using a clean fresh v1.3.9f install.

I used the demo data.

I added this to the template just to be sure I'm seeing what I should see: ```

<?php echo 'CART TYPE: ' . $_SESSION['cart']->get_content_type(); ?>

I added the following to my cart:
- Sample of Product General  (this is a physical product), from "Mixed Product Types" category.
- Single Download (virtual product, since it's a download), from "New v1.2->Downloads" category.
- Free Ship & Payment Virtual (virtual product, not a download), from "Free Call Stuff" category.

Adding "Sample of Product General" shows the cart as "physical".
Adding "Single Download" now shows cart as "mixed".
Adding "Free Ship & Payment Virtual" now shows cart as "mixed".
Deleting "Sample of Product General" now shows cart as "virtual".
Deleting "Single Download" now shows cart as "virtual".

I tried the deletes by using both the "delete" button on that row of the shopping cart, as well as by changing quantity to 0 and clicking the "update" button. Results same in both cases.

Exactly as it should.  I'm puzzled as to why you're seeing it do otherwise.  It suggests that you've made alterations to the code.
26 Sep 2010, 5:49 AM
#15
retched avatar

retched

Totally Zenned

Join Date:
Jun 2007
Location:
Bronx, New York, United States
Posts:
949
Plugin Contributions:
3

Re: Dynamically testing products in a cart for it's delivery type.

I just tested with $_SESSION['cart']->get_content_type() and NOW the cart is updating itself properly. Before I was simply testing with $_SESSION['cart']->content_type.

Other than the obligatory, Why would this work that way, is there a difference between two?

26 Sep 2010, 12:19 PM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Dynamically testing products in a cart for it's delivery type.

As I said, the function sets the variable. If you don't run the function, the variable is never set/updated.