Forums / Addon Shipping Modules / Access cart conents from shipping module

Access cart conents from shipping module

Locked

Views: 851

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
7 Aug 2010, 10:04 PM
#1
ayrscott avatar

ayrscott

New Zenner

Join Date:
Aug 2010
Location:
Fredericksburg, VA
Posts:
3
Plugin Contributions:
0

Access cart conents from shipping module

I have just recently started using Zen Cart and have been pretty impressed thus far. I had been using OsCommerce for projects like this in the past but decided to make the switch to Zen finally.

Anyhow before we decided on ZenCart I had written a script to do some custom shipping calculations according to the particular part numbers, quantities and zip code the items were being shipped to and it worked out very well.

Now that we have ZenCart up and running I'm trying to port this code over as a shipping module and am stuck at the part where I retrieve the parts currently in the cart to determine the shipping rate. I looked at some of the other modules that came with my base install and they seem to return a flat rate based on a basic set of criteria or quote a rate by an estimated number of boxes and weight per box. While I'm sure this works great for most people I'd really like to be able to retrieve the cart information (qty & id mainly) from inside the quote function of the module I've created from hacking up the flat rate module :laugh:

Sorry if this is answered on the forums already. The number of results I got was astronomical when searching as the terms being used here are pretty general/far reaching.

9 Aug 2010, 5:57 AM
#2
ayrscott avatar

ayrscott

New Zenner

Join Date:
Aug 2010
Location:
Fredericksburg, VA
Posts:
3
Plugin Contributions:
0

Re: Access cart conents from shipping module

Just wanted to post here and mention that I did a little more digging after posting the other day and found the easiest way to do this is simply using a copy of the cart class that's in the session variables. If there is a better way to do this please feel free to correct me.

    # Retrieve the list of parts in our cart so we can get their product ID for shipping calculations
    $ship_cart = $_SESSION['cart'];
    $ship_products = $ship_cart->get_products();

    # Create a variable to store our data for part ID's and qtys
    $parts_to_ship = array();
    foreach($ship_products as $key => $values){
      $parts_to_ship[$values['product_id']] = $values['quantity'];
    }