Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2012
    Posts
    5
    Plugin Contributions
    0

    Default UPS Shipping Module

    I can get the total number of items in the cart by using:
    $shipping_num_boxes = $_SESSION['cart']->count_contents();

    How can i get the number of items of a specific product (master category #2)?

    Thanks in advance for your help

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: UPS Shipping Module

    You could use:
    Code:
    $chk_the_quantity = $_SESSION['cart']->get_quantity(your_products_id);
    Note: depending on where in the code you are, you may need before that a line for:
    Code:
    global $cart;
    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: v1.5.5]
    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!

  3. #3
    Join Date
    Apr 2012
    Posts
    5
    Plugin Contributions
    0

    Default Re: UPS Shipping Module

    Thanks a million Ajeh.

    That works perfectly for a specific product.

    Is there a way i can get the quantity of all the products in a specific category that are in the cart?

    I have a category (id #2) it has sub categories and in the subcategories there are products listed. I want to get the total of all the products (items) in the cart that fall under all the sub categories of the main category (id #2).

    Thanks a million in advance.

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: UPS Shipping Module

    You cannot pull from the parent category all Products in the subcategories without a lot of customization ... I forget where I have code for something like that writte ... but you can try to hunt for it ...

    Meanwhile, you could get the products from each of the subcategories using the master_categories_id for the Products ... the master_categories_id is the immediate categories_id that the Product belongs to ...

    You would need to setup something like:
    Code:
    // bof: get all of Category 2 Product quantity from master_categories_id 10, 12, 15
    global $cart;
    $chk_cats = 0;
    $chk_cats += $_SESSION['cart']->in_cart_check('master_categories_id','10');
    $chk_cats += $_SESSION['cart']->in_cart_check('master_categories_id','12');
    $chk_cats += $_SESSION['cart']->in_cart_check('master_categories_id','15');
    // eof: get all of Category 2 Product quantity from master_categories_id 10, 12, 15
    Now $chk_cats would hold the counts ...

    NOTE: to get that you should put the code above the line:
    Code:
            for ($i=0; $i<$size; $i++) {
    so it only runs once for that shipping module rather than for each shipping method of that shipping module ...
    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: v1.5.5]
    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!

  5. #5
    Join Date
    Apr 2012
    Posts
    5
    Plugin Contributions
    0

    Default Re: UPS Shipping Module

    Ajeh, Thank you so so much for your help. It works!
    I am sharing below the modification i did with the help of Ajeh and a post by another member. Hopefully, it will help someone else with similar need.

    The main challenge:
    I have two main categories: category 1, which has sub categories and products under each sub; these products are pre-packaged but differ in weight since there is more than one item type, therefore when someone orders say 3 of these items we ship them as 3 boxes. Category 2, on the other hand, has sub categories and products under each sub, but these products we package (up to 12 items per box), therefore when someone orders, say 10 items that ships as one box, if someone order 24 items that ships as two boxes, and so on.

    The original addon UPS module uses the "Max Weight You Will Ship" that you key in under Admin > Configuration >Shipping/Packaging. In our case that yeilds the correct total weight but an inaccurate number of boxes being shipped.

    To remedy that the code below offers a decent solution:-
    1- Reads how many items in the shopping cart (ALL ITEMS)
    2- Reads how many items of Main Category 2 are in the cart (CAT 2 ITEMS)
    3- Packages CAT 2 ITEMS (up to 12 each in a box) - (BOXES of PACKAGED ITEMS)
    4- Calculates ALL ITEMS - CAT 2 ITEMS + BOXES of PACKAGED ITEMS
    5- Finally shows the correct number of boxes we are shipping with averaged weight; thereby giving us a very realistic shipping cost based on UPS rates.

    The final Code I used:

    function quote($method = '') {
    global $_POST, $order, $cart, $shipping_weight, $shipping_num_boxes;

    // Correction from Forum Threads and Ajeh to Fix box count and averages weight
    // check number of products we package (main cat id#2 - all items in sub category 12)
    $chk_cats = 0;
    // the line below gets the total number of items (under master cat id 12)
    $chk_cats += $_SESSION['cart']->in_cart_check('master_categories_id','12');
    // the line below places up to 12 items in a box
    $cnt_cats = ceil($chk_cats / 12);
    // calculate total weight
    $total_weight = $shipping_weight * $shipping_num_boxes;
    // get the total number of items in the cart
    $shipping_num_boxes = $_SESSION['cart']->count_contents();
    // take away cat 2 items and add the number of boxes of packaged items
    $shipping_num_boxes = $shipping_num_boxes - $chk_cats + $cnt_cats;
    // average the weight
    $shipping_weight = $total_weight / $shipping_num_boxes;
    // ... continue with the original UPS Module Code
    if ( (zen_not_null($method)) && (isset($this->types[$method])) ) {
    $prod = $method;
    // BOF: UPS USPS

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: UPS Shipping Module

    WARNING: BE VERY, VERY CAREFUL ...

    You are changing variables that if you are trying to use other shipping modules that use the same variables will be altered do to changes like this in the shipping module ...
    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: v1.5.5]
    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. #7
    Join Date
    Apr 2012
    Posts
    5
    Plugin Contributions
    0

    Default Re: UPS Shipping Module

    Ajeh,
    Is there a way to confine the changes to a specific shipping module? In my case all i use is UPS so it works but i don't want others to be mislead or confused.
    Once again thanks for your help and others in the forum.

  8. #8
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: UPS Shipping Module

    In your case this would not be an issue as you only use UPS and how you change those variables is your own issue ...

    But if someone was to need to use multiple shipping modules such as USPS and UPS ... then it is better to get those variables but then if they need to be changed, change new variables such as:
    Code:
    // calculate total weight
         $total_weight = $shipping_weight * $shipping_num_boxes;
    // get the total number of items in the cart
         $shipping_num_boxes = $_SESSION['cart']->count_contents();
    // take away cat 2 items and add the number of boxes of packaged items
         $shipping_num_boxes = $shipping_num_boxes - $chk_cats + $cnt_cats;
    use something line:
    Code:
    // calculate total weight
         $my_total_weight = $shipping_weight * $shipping_num_boxes;
    // get the total number of items in the cart
         $my_shipping_num_boxes = $_SESSION['cart']->count_contents();
    // take away cat 2 items and add the number of boxes of packaged items
         $my_shipping_num_boxes = $my_shipping_num_boxes - $chk_cats + $cnt_cats;
    Notice how you can use a variable that is globally shared by other files, just do not change their values in your code and use your own variables ...
    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: v1.5.5]
    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!

 

 

Similar Threads

  1. v151 UPS Shipping module - Tweak to show UPS Freight LTL
    By pexter in forum Addon Shipping Modules
    Replies: 0
    Last Post: 13 Jun 2013, 09:37 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. UPS Shipping Module
    By WiccanWitch420 in forum General Questions
    Replies: 1
    Last Post: 21 Oct 2010, 11:41 PM
  4. Replies: 6
    Last Post: 28 Feb 2009, 06:12 AM
  5. UPS Shipping Module - UPS Pickup Method
    By inovermyhead in forum Built-in Shipping and Payment Modules
    Replies: 8
    Last Post: 4 Jun 2008, 01:49 PM

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