Zen Cart Logo
Forums / General Questions / Accessing $order->products array when not logged in for custom shipping module

Accessing $order->products array when not logged in for custom shipping module

Locked

Views: 947

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
10 Jun 2009, 5:30 AM
#1
malx avatar

malx

New Zenner

Join Date:
Feb 2009
Posts:
15
Plugin Contributions:
0

Accessing $order->products array when not logged in for custom shipping module

Hi,

Zen Cart 1.3.8, clean install. Currently only running locally on my development machine.

I have written a shipping mod that uses as part of its calculation the cubic volume of the products in the shopping cart. I couldn't find anywhere to put the volume property so I've added a new field to the products table and changed all the required admin pages so I can maintain these values.

In my mod I'm looping through all the products in my order to get the total volume of the order i.e.

		
// Get details from the order
// Go through products and work out total volume
foreach ($order->products as $key => $product) {
	$product_id = $product['id'];
	$sql = "SELECT volume FROM " . DB_PREFIX . "products WHERE $product_id = products_id";
	$rec = $db->Execute($sql);
	$total_volume += $product['qty'] * $rec->fields['volume'];
}

This works fine (if not the smartest way but I couldn't work out how to get the volume into the order) if I'm logged in, but if I'm only a guest I don't have access to the $order->products array.

Anyone have an idea how to get to it, or another option for getting the sum of all the custom fields of the products in the cart?

Thanks,
Anthony.

10 Jun 2009, 6:00 AM
#2
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Accessing $order->products array when not logged in for custom shipping module

use data from the array $_SESSION['cart']->contents

take a look through the file inlcudes/classes/shopping_cart.php to see what's in the array.

10 Jun 2009, 11:24 AM
#3
malx avatar

malx

New Zenner

Join Date:
Feb 2009
Posts:
15
Plugin Contributions:
0

Re: Accessing $order->products array when not logged in for custom shipping module

Thanks for that Neville. I did see the cart in the session, but I only had one product with an ID of 1 and it hadn't clicked that it the array subscript was the product key :) Thanks again for pointing me in the right direction.

Anthony.