Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    15
    Plugin Contributions
    0

    database error 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.

    Code:
    		
    // 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.

  2. #2
    Join Date
    Sep 2004
    Location
    Western Massachusetts
    Posts
    2,945
    Plugin Contributions
    5

    Default 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.
    Neville
    An assumption is what you arrive at when you get tired of thinking...

  3. #3
    Join Date
    Feb 2009
    Posts
    15
    Plugin Contributions
    0

    Default 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.

 

 

Similar Threads

  1. accessing array value in for loop
    By jeffiec in forum Code Collaboration
    Replies: 16
    Last Post: 26 Jul 2016, 08:48 PM
  2. v139h UPS Shipping Module for Oversized Products when Shipping
    By trailerworld in forum Addon Shipping Modules
    Replies: 2
    Last Post: 20 Nov 2012, 09:11 PM
  3. Shipping Estimator does not work for me when not logged in
    By speedraceratl in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 22 Aug 2009, 06:14 PM
  4. Fedex Shipping Module error 1054 only when customore is logged in
    By palmyrapantry in forum Addon Shipping Modules
    Replies: 3
    Last Post: 14 Jun 2009, 10:11 PM
  5. Replies: 17
    Last Post: 11 Dec 2008, 06:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR