Zen Cart Logo

Media Mail Option

Locked

Views: 7,989

Results 1 to 20 of 46
This thread is locked. New replies are disabled.
27 Apr 2009, 12:38 PM
#1
ozgirl57 avatar

ozgirl57

New Zenner

Join Date:
Feb 2008
Posts:
3
Plugin Contributions:
0

Media Mail Option

I'm trying to figure out how to add a USPS Media Mail option to my cart for books.

I found this thread which is exactly what I want to do
http://www.zen-cart.com/forum/showthread.php?t=85379&highlight=media+mail
using the following code,

         if ($type == 'MEDIA' && $_SESSION['cart']->in_cart_check('master_categories_id','10') != $_SESSION['cart']->count_contents()) {
            // skip MEDIA when whole cart is not from master_categories_id 10
          } else {
          $methods[] = array('id' => $type,
                             'title' => $title,
                             'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
          } 

but I seem to be doing something wrong as the media mail option shows up for all sales, not just those restricted to the master_category_id. I'm sure I'm inserting the correct master category id, but I'm not sure I'm placing the code in the correct place in the usps.php file.

So could someone please tell me where exactly the code should be placed in the file? :frusty:

Thanks for your help.

27 Apr 2009, 3:56 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Media Mail Option

I added your code to my site and when categories_id 10 products, tested via the master_categories_id is equal to the full count of items I get the Media choice and when they are not equal I do not get the Media choice ...

Make sure that you uploaded your changes to the right directory and that master_categories_id is actually 10 in the products table ...

27 Apr 2009, 4:03 PM
#3
ozgirl57 avatar

ozgirl57

New Zenner

Join Date:
Feb 2008
Posts:
3
Plugin Contributions:
0

Re: Media Mail Option

Thanks for your quick response, but where exactly do I place the code in the file? The file has a lot of code and I've tried placing it at different places sometimes with not very good results. :blush:

Thanks so much for your help.

27 Apr 2009, 4:51 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Media Mail Option

In the USPS shipping module, around line 209, you find the code:

          $methods[] = array('id' => $type,
                             'title' => $title,
                             'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);

So you are adding your code for the IF around that piece of code and changing it ...

         if ($type == 'MEDIA' && $_SESSION['cart']->in_cart_check('master_categories_id','10') != $_SESSION['cart']->count_contents()) {
            // skip MEDIA when whole cart is not from master_categories_id 10
          } else {
          $methods[] = array('id' => $type,
                             'title' => $title,
                             'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
          }

That will allow MEDIA to show only when ALL Products in the shopping cart are using master_categories_id 10 ...

27 Apr 2009, 5:55 PM
#5
ozgirl57 avatar

ozgirl57

New Zenner

Join Date:
Feb 2008
Posts:
3
Plugin Contributions:
0

Re: Media Mail Option

Thank you so much - it works! You are awesome! :clap:

27 Apr 2009, 6:46 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Media Mail Option

Thanks for the update that this is now working for you ... :smile:

5 Dec 2009, 6:03 AM
#7
dapottster avatar

dapottster

New Zenner

Join Date:
Jul 2009
Location:
Crystal Lake, IL
Posts:
50
Plugin Contributions:
0

Re: Media Mail Option

I am trying to get media mailing from USPS to only appear when all products in the cart are from category 21. I used the code:

if ($type == 'MEDIA' && $_SESSION['cart']->in_cart_check('master_categories_id','21') != $_SESSION['cart']->count_contents()) {
            // skip MEDIA when whole cart is not from master_categories_id 21
          } else {
          $methods[] = array('id' => $type,
                             'title' => $title,
                             'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
          }
        }

I just tried it out by putting one CD in my cart and it didn't show up. Does it matter that the CD is actually a sub category of category 21?
Thanks,
Matt

5 Dec 2009, 3:52 PM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Media Mail Option

A master_categories_id is the specific Category that the Product is in where it is set as the master_categories_id of the Product ...

If you edit the Product it will tell you the master_categories_id of that Product ...

You appear to be testing a parent categories_id and that is not going to work ...

6 Dec 2009, 5:53 PM
#9
dapottster avatar

dapottster

New Zenner

Join Date:
Jul 2009
Location:
Crystal Lake, IL
Posts:
50
Plugin Contributions:
0

Re: Media Mail Option

Thanks, so is there a way that I can check a parent category? If not, how can I get it to check each individual category. Right now, if I'm not mistaken, the code is checking if the entire cart is comprised of the selected category. If I have four categories that use media, if I simply duplicate the code and somebody orders one CD from one category and one CD from another, it won't show the media option since the cart is completely comprised of either category. I hope that made sense. Basically, here is my category structure:
21 : Media (parent)
22 : Amazon (child)
29 : Barnes & Noble (child)
52 : Calypso (child)
58 : Steelpan (child)
So if the cart is completely made up of only products from categories 22, 29, 52, and 58 I need media mail to display. I will also be adding more categories under the parent category Media in the future.
Thanks for your help.
-Matt

6 Dec 2009, 6:43 PM
#10
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Media Mail Option

You would either need to write a new function to test based on parent categories_id or you could change the code to read something like:

// test contents for Media Mail
        $skip_media = false;
        $chk_media = 0;
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','22');
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','29');
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','52');
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','58');
        if ($chk_media != $_SESSION['cart']->count_contents()) {
          $skip_media = true;
        }

        $methods = array();
        $size = sizeof($uspsQuote);
        for ($i=0; $i<$size; $i++) {
          list($type, $cost) = each($uspsQuote[$i]);

          // BOF: UPS USPS
          $title = ((isset($this->types[$type])) ? $this->types[$type] : $type);
          if(in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS)))    $title .= $transittime[$type];
          /*
          $methods[] = array('id' => $type,
          'title' => ((isset($this->types[$type])) ? $this->types[$type] : $type),
          'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
          */
          if ($type == 'MEDIA' && $skip_media) {
            // skip Media Mail
          } else {
            $methods[] = array('id' => $type,
                               'title' => $title,
                               'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
          }                             
        }

        $this->quotes['methods'] = $methods;
7 Dec 2009, 11:25 PM
#11
dapottster avatar

dapottster

New Zenner

Join Date:
Jul 2009
Location:
Crystal Lake, IL
Posts:
50
Plugin Contributions:
0

Re: Media Mail Option

That's awesome! It seems like everything works now, and if I need to add more categories I can. You are incredible!:hug:

8 Dec 2009, 1:22 AM
#12
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Media Mail Option

Glad to hear that this works for you ... remember us when you are rich and famous! :smile:

31 Jan 2010, 7:53 AM
#13
debtag avatar

debtag

Zen Follower

Join Date:
Sep 2006
Location:
Oregon
Posts:
207
Plugin Contributions:
0

Re: Media Mail Option

Hi Ajeh!

I was wondering if you would help me with media mail!

I have:

Books (Parent id:4) no child categories

Computer (Parent id:11) with child categories:
Games (id:19)>
1.00 games (id:22)
Educational games (id:25)
Other games (id:24)
Programs (id:20)>
1.00 programs (id:23)

I want media mail to show up when ever there is only one or more item from one of these categories, or a combination of only these categories, but I don't want it to show up if there is anything in the cart that is not one of these categories...for example: if they bought 3 books and 10 cd games, then media mail would show up, but if they bought 3 books, 10 cd games and a basketball, then media mail would not show up.

I am really not savy at all when it comes to code or knowing where it should go, so PLEASE include this in your instructions! Thank you so, so much!
Shipping has been really expensive without the media mail option, as I have turned it off.
:cry:

31 Jan 2010, 3:24 PM
#14
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Media Mail Option

You would use the same thing as what I posted but put in your master_categories_id for as many categories that are allowed in:

        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','22');

What this is doing is counting how many products come from that categories_id ... in this case it is testing for categories_id 22 when that is the master_categories_id ...

If they are added up and do not match the count of all items in the cart, then the Media Mail is skipped ...

31 Jan 2010, 7:29 PM
#15
debtag avatar

debtag

Zen Follower

Join Date:
Sep 2006
Location:
Oregon
Posts:
207
Plugin Contributions:
0

Re: Media Mail Option

Thank you! So is this an example of what it should look like?

$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','22');COLOR=black;[/COLOR]COLOR=black;[/COLOR]COLOR=black;[/COLOR]

and so on?

31 Jan 2010, 11:56 PM
#16
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Media Mail Option

In a word ... no ... :eek:

If you peek at the code in post #10, for the categories_id 22, 4, 11 and 19 that are used as the master_categories_id of the Products in the products table, you should change the code to:

// test contents for Media Mail
        $skip_media = false;
        $chk_media = 0;
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','22');
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','4');
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','11');
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','19');

You need 1 line per categories_id that ARE allowed ...

Now if you have a lot of categories you may want to customize this code even further than it is ...

1 Feb 2010, 12:23 AM
#17
debtag avatar

debtag

Zen Follower

Join Date:
Sep 2006
Location:
Oregon
Posts:
207
Plugin Contributions:
0

Re: Media Mail Option

Ok! Thanks Ajeh!

But...I am a bit confused at what you said, quote: You need 1 line per categories_id not allowed ...

The categories you have listeded in your code you wrote for me ARE the categories*** I want to ALLOW*** for media mail. Those categories I listed are the only categories I have right now that would warrant media mail. So....the code you wrote will allow media mail to show up if they choose ONLY from those categories...is that correct?

I'm so sorry Ajeh...I feel so dumb...I wish I understood code. I only understand a little bit of html and I mean only a little bit! Thank goodness there are people out there who know what they are doing like yourself!!!!

1 Feb 2010, 1:41 AM
#18
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Media Mail Option

Sorry ... my bad ... that one is written for which categories "are allowed" ... I write too many of these things ... :blink:

1 Feb 2010, 4:18 AM
#19
debtag avatar

debtag

Zen Follower

Join Date:
Sep 2006
Location:
Oregon
Posts:
207
Plugin Contributions:
0

Re: Media Mail Option

Ok! I will give it a whirl! :lamo:

Thank you!

1 Feb 2010, 5:12 AM
#20
debtag avatar

debtag

Zen Follower

Join Date:
Sep 2006
Location:
Oregon
Posts:
207
Plugin Contributions:
0

Re: Media Mail Option

Ugh...not working... :no: this is what I've plugged into my usps.php:

// test contents for Media Mail
$skip_media = false;
$chk_media = 0;
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','4');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','19');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','20');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','22');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','24');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','25');
if ($chk_media != $_SESSION['cart']->count_contents()) {
$skip_media = true;
}

Each of the above id's have either computer cds/programs or books. Media mail is showing up ALL THE TIME. Even if there is only one item that is NOT EVEN FROM THE ANY OF THE ABOVE MEDIA ID'S...what am I doing wrong?