Zen Cart Logo
Forums / Addon Shipping Modules / USPS allow media mail based on cart contents?

USPS allow media mail based on cart contents?

Views: 6,380

Results 1 to 20 of 35
7 Apr 2013, 10:07 PM
#1
geckomafia avatar

geckomafia

New Zenner

Join Date:
Apr 2013
Location:
Southgate, KY
Posts:
9
Plugin Contributions:
0

USPS allow media mail based on cart contents?

Sorry to resurrect a 3 year old closed thread :blush:, but I am having trouble with Media Mail similar to the issue here

http://www.zen-cart.com/showthread.php?126077-Media-Mail-Option

Before I go further, I should mention I am doing this for someone else, and don't have direct access to the files, until the site owner sends them to me.

I downloaded the file in the Zip from reply/post #32, but it was Dated January 4 2010, and the one I am editing is January 2 2011. I found the block for Media Mail and pasted it where I thought I should, and the owner replied with:

"Initial tests are a bit troubled, I'm afraid. Here's what I saw occur:

  • When I added a media-mail-OK product and only had that in my cart, it showed two USPS shipping methods when I checked the shipping estimator

  • When I added another non-media-mail-OK product to the cart, it showed only one USPS method

The problems were...

  • It didn't name the USPS methods properly; and,

  • It showed each of them as having the same value ($3, which is the handling mark-up I've configured to be added to the baseline USPS system's rate quote) which implied that they were both getting evaluated as $0"


Here is what I pasted into his file, with a little before and after.

TEXT_SHIPPING_WEIGHT . ')';
break;
default:
$show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($usps_shipping_weight,2) . TEXT_SHIPPING_WEIGHT . ')';
break;
}
}
// EOF: UPS USPS

// ----- My paste starts here

// bof: Media Check
// test contents for Media Mail
$skip_media = false;
$chk_media = 0;

/* ----------------------- here is where you can add more media mail categories in the future ....
Just copy and paste the following line including semicolon into the correct numerical order and replace the words at the end with the category number

$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','category number goes here');

*/

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

if ($chk_media != $_SESSION['cart']->count_contents()) {
$skip_media = true;
}
//echo '<br>IN USPS I SEE ' . $chk_media . ' count: ' . $_SESSION['cart']->count_contents() . ' Skip Media: ' . ($skip_media == true ? 'YES' : 'NO') . '<br>';
$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 {
$cost = preg_replace('/[^0-9.]/', '', $cost);
$methods[] = array('id' => $type,
'title' => $title,
'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_USPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_USPS_HANDLING) );
}
}
// eof: Media Check

// ----- Paste ends here

// BOF: UPS USPS
$this->quotes = array('id' => $this->code,
'module' => $this->title . $show_box_weight);
// EOF: UPS USPS

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

// fix new trademark and reg 01-02-2011

Any help is greatly appreciated.

7 Apr 2013, 11:14 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

You really need to start with the Current USPS shipping as the old ones are not designed for the new Jaunary 27, 2013 rates ...
http://www.zen-cart.com/downloads.php?do=file&id=1292

8 Apr 2013, 4:33 AM
#3
geckomafia avatar

geckomafia

New Zenner

Join Date:
Apr 2013
Location:
Southgate, KY
Posts:
9
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

I think I found it ....

2 mistakes on my part. First I sent the file before editing the category IDs to reflect the ones in his store. :blush: So it never would have filtered media mail in the first place. :no:

Also I was calculating the cost before and during the if ..... :blush:

      $cost = preg_replace('/[^0-9.]/', '',  $cost);
      $methods[] = array('id' => $type,
                         'title' => $title,
                         'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_USPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_USPS_HANDLING) );

      if ($type == 'MEDIA' && $skip_media) {

// skip Media Mail
} else {
$cost = preg_replace('/[^0-9.]/', '', $cost);
$methods[] = array('id' => $type,
'title' => $title,
'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_USPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_USPS_HANDLING) );

The good news is .... I'm 99% certain that I got it!! :yes:

Good ole php :yuck:

8 Apr 2013, 4:41 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: USPS allow media mail based on cart contents?

Glad you figured out your concern. But if you keep using the obsolete 2011 version then you won't get 2013 prices properly. Hence Ajeh's advice to use an up-to-date module.

8 Apr 2013, 2:13 PM
#5
geckomafia avatar

geckomafia

New Zenner

Join Date:
Apr 2013
Location:
Southgate, KY
Posts:
9
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

DrByte:

Glad you figured out your concern. But if you keep using the obsolete 2011 version then you won't get 2013 prices properly. Hence Ajeh's advice to use an up-to-date module.

Ok, so I'm looking at the updated module. Should I place my code before the lines:

    // COST
    // clean out invalid characters

so the end of my paste should look like:

if ($type == 'MEDIA' && $skip_media) {
// skip Media Mail
} else {
// COST
// clean out invalid characters
$cost = preg_replace('/[^0-9.]/', '', $cost);
//echo 'USPS $cost: ' . $cost . ' $handling: ' . $handling . ' $hiddenCost: ' . $hiddenCost . ' $shipping_num_boxes: ' . $shipping_num_boxes . ' $usps_handling_fee: ' . $usps_handling_fee . '<br>';
// add handling for shipping method costs for extra services applied
$cost = ($cost + $handling + $hiddenCost) * $shipping_num_boxes;
// add handling fee per Box or per Order
$cost += (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box') ? $usps_handling_fee * $shipping_num_boxes : $usps_handling_fee;

Is this correct?

8 Apr 2013, 2:45 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

You might try using it here:

[B]if ($type == 'MEDIA' && $skip_media) {
// skip Media Mail
} else {
[/B]        if ((($method == '' && in_array($type, $types)) || $method == $type) && $usps_shipping_weight <= $maxweight && $usps_shipping_weight > $minweight) {
          $methods[] = array('id' => $type,
                             'title' => $title,
                             'cost' => $cost,
                            );
        }
[B]}[/B]
16 Apr 2013, 5:21 PM
#7
jaheadlee avatar

jaheadlee

New Zenner

Join Date:
Jul 2012
Posts:
10
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

Ajeh:

You might try using it here:

[B]if ($type == 'MEDIA' && $skip_media) {
// skip Media Mail
} else {
[/B]
if ((($method == '' && in_array($type, $types)) || $method == $type) && $usps_shipping_weight <= $maxweight && $usps_shipping_weight > $minweight) {
$methods[] = array('id' => $type,
'title' => $title,
'cost' => $cost,
);
}
[B]}[/B]


Oooh!!:ohmy:  I too have this issue with adding a test for media mail eligibility.  In the old USPS addon it worked fine with this code:

	  // bof: test for media mail eligible
		$cart_count = $_SESSION['cart']->count_contents();
		$chk_products = 0;

// $chk_products += $_SESSION['cart']->in_cart_check('product_media_mail_eligible','1');
$chk_products += $_SESSION['cart']->in_cart_check('products_type','7');
$chk_products += $_SESSION['cart']->in_cart_check('products_type','2');
// the above 2 lines better checkto see if product type is music or book, and add 1 to chk_products if so. This determine
// media mail eligible. I hope JAH 12/19/2012
if ($type == "MEDIA" && $cart_count > 0 && $chk_products == $cart_count) {
// echo 'We made it to the methods stuff ' . $type;
$methods[] = array('id' => $type,
'title' => $title,
'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? $usps_handling_fee * $shipping_num_boxes : $usps_handling_fee) );
} else {
if($type != "MEDIA") {
// echo ' we are not media mail we are ' . $type;
$methods[] = array('id' => $type,
'title' => $title,
'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? $usps_handling_fee * $shipping_num_boxes : $usps_handling_fee) );
//skip the method
} else {
// echo 'we ARE MEDIA MAIL AND SHOULDN"T DO ANYTHING!!!' . $type;
}
}


So I added it (I think) where ajeh suggested and now I get double quotes for every USPS shipping type.  And although my test should not show Media Mail, it still does.  Clearly where I've put it is not right.  This is one of several tests i do (another is testing the weight to see which Priority Mail package is appropriate).  I'm gonna start with this. 

Yes, I'm a little late on getting my act together, but until today I hadn't realized how much it had changed, as all my customers requested Priority Mail or Media -- until today.   So now I'm in a crunch.  

Thanks a bunch!!
16 Apr 2013, 5:28 PM
#8
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

Could you zip your file:
/includes/modules/shipping/usps.php

from the server and post it so we can see the whole thing on what you have?

16 Apr 2013, 9:03 PM
#9
jaheadlee avatar

jaheadlee

New Zenner

Join Date:
Jul 2012
Posts:
10
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

Ajeh:

Could you zip your file:
/includes/modules/shipping/usps.php

from the server and post it so we can see the whole thing on what you have?

Sure. I did figure out why I was getting double -- I had left the

        if ((($method == '' && in_array($type, $types)) || $method == $type) && $usps_shipping_weight <= $maxweight && $usps_shipping_weight > $minweight) {
          $methods[] = array('id' => $type,
                             'title' => $title,
                             'cost' => $cost,
                            );

after my code, which of course simply does the same thing as my code -- so it happens twice. But fixing that I still can't get it to eliminate media mail. I notice at the "top" of the file is a specific section for "customized code to change $this->enabled to false"(line 193) - I tried to put this in there as well, but it wasn't successful either. I think I need to rewrite this to separate out the cost calculation from the determination of eligibility for media mail as the usps.php file has significantly changed. Looking forward to your input -- thanks!

16 Apr 2013, 9:50 PM
#10
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

Your code is a little confusing ...

Could you describe the conditions of when you DO want Media to show and the conditions when you DO NOT want Media to show?

6 May 2013, 5:22 PM
#11
jaheadlee avatar

jaheadlee

New Zenner

Join Date:
Jul 2012
Posts:
10
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

Sorry for not answering -- I got sidetracked with a whole other issue that was more crucial.

What I am trying to do is this: I have 2 product types that are eligible to be shipped USPS media mail (2 and 7 -- CDs and books). If the order has any other items, even if some of them are 2 and/or 7, it must be sent by something other than media mail. Only if the entire order is 2 and/or 7 can it be shipped media mail. The code from before checked each item's product type, counting items vs. media mail eligible items, and if those #'s were equal then media mail quote was needed; otherwise not. I will admit that I didn't come up with this code or its placement in the old usps.php file myself, just based it on forum posts. This module has been reorganized and it is not clear to me now where the checking needs to go. I will have a similar problem figuring out where to put my code to figure out which Priority Mail flat rate to quote -- I did a weight check to only get the size box that was appropriate for the order, and so that code willl also need to be ported into the new module. So, where should that be and what are the variables that will allow me to look up the order's items?

Thanks so much -- sorry for the long delay again!

7 May 2013, 3:14 AM
#12
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

I believe you are looking for the wrong text for MEDIA ... it should be something like:

                if  ($type == "Media MailRM" && $chk_products != $cart_count) {
                  // skip MEDIA

I do not believe you need the test for if the $cart_count is > 0 as there isn't shipping if the count isn't > 0 ...

More or less you can shrink that code down to:

//echo 'USPS $type: ' . $type . ' $cost: ' . $cost . ' - $_SESSION[cart]->total: ' . $_SESSION['cart']->total . ' $handling: ' . $handling . ' $hiddenCost: ' . $hiddenCost . ' $usps_handling_fee: ' . $usps_handling_fee . ' $shipping_num_boxes: ' . $shipping_num_boxes . ' $title: ' . $title . '<br /><br />';
//echo 'USPS $type: ' . $type . ' $cost: ' . $cost . ' $title: ' . $title . '<br /><br />';
//echo 'USPS $type: ' . $type . ' $usps_shipping_weight: ' . $usps_shipping_weight . ' $minweight: ' . $minweight . ' $maxweight: ' . $maxweight . '<br>';
        if ((($method == '' && in_array($type, $types)) || $method == $type) && $usps_shipping_weight <= $maxweight && $usps_shipping_weight > $minweight) {

                $cart_count = $_SESSION['cart']->count_contents();
                $chk_products = 0;
    //            $chk_products += $_SESSION['cart']->in_cart_check('product_media_mail_eligible','1');
          $chk_products += $_SESSION['cart']->in_cart_check('products_type','7');
          $chk_products += $_SESSION['cart']->in_cart_check('products_type','2');
                if  ($type == "Media MailRM" && $chk_products != $cart_count) {
                  // skip MEDIA
                  echo 'SKIPING $type: ' . $type . '<br>';
                } else {
                   echo 'show media $type: ' . $type . ' count: ' . $cart_count . ' $chk_products: ' . $chk_products . '<br>';
                 // show shipping methods
          $methods[] = array('id' => $type,
                             'title' => $title,
                             'cost' => $cost,
                            );
          }
        }
      }

      if (sizeof($methods) == 0) return false;
4 Aug 2013, 4:12 AM
#13
geckomafia avatar

geckomafia

New Zenner

Join Date:
Apr 2013
Location:
Southgate, KY
Posts:
9
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

OK, my customer just upgraded to USPS Version Date 2013-07-28, and now the media mail options are not working. It appears that the module has been drastically changed, and I have no idea where to put my code now.

I'm confused ....

the code that was working is this:

// bof: Media Check
// test contents for Media Mail
$skip_media = false;
$chk_media = 0;

    $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','77');
    $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','78');
    $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','79');
    if ($chk_media != $_SESSION['cart']->count_contents()) {
      $skip_media = true;
    }

//echo '<br>IN USPS I SEE ' . $chk_media . ' count: ' . $_SESSION['cart']->count_contents() . ' Skip Media: ' . ($skip_media == true ? 'YES' : 'NO') . '<br>';

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

// fix new trademark and reg 01-02-2011
//$type = str_replace('<sup>&reg;</sup>', '<sup>®</sup>', $type);
//$type = str_replace('<sup>&trade;</sup>', '<sup>™</sup>', $type);

      // 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];
              
	  if ($type == 'MEDIA' && $skip_media) {

// skip Media Mail
} else {
$cost = preg_replace('/[^0-9.]/', '', $cost);
$methods[] = array('id' => $type,
'title' => $title,
'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_USPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_USPS_HANDLING) );
}
}
// eof: Media Check

4 Aug 2013, 4:30 AM
#14
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

Instead of testing for MEDIA ... try using:
Media MailRM

4 Aug 2013, 6:09 AM
#15
geckomafia avatar

geckomafia

New Zenner

Join Date:
Apr 2013
Location:
Southgate, KY
Posts:
9
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

Ajeh:

Instead of testing for MEDIA ... try using:
Media MailRM

so here is what I have, and where I placed it:

  // Show box weight if enabled
  $show_box_weight = '';
  if (in_array('Display weight', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) {
    switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
      case (0):
        $show_box_weight = '';
        break;
      case (1):
        $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')';
        break;
      case (2):
        $show_box_weight = ' (' . number_format($usps_shipping_weight * $shipping_num_boxes,2) . TEXT_SHIPPING_WEIGHT . ')';
        break;
      default:
        $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')  (' . $this->pounds . ' lbs, ' . $this->ounces . ' oz' . ')';
        break;
    }
  }

//*********************************************************************************************

// bof: Media Check
// test contents for Media Mail
$skip_media = false;
$chk_media = 0;

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


    if ($chk_media != $_SESSION['cart']->count_contents()) {
      $skip_media = true;
    }

//echo '<br>IN USPS I SEE ' . $chk_media . ' count: ' . $_SESSION['cart']->count_contents() . ' Skip Media: ' . ($skip_media == true ? 'YES' : 'NO') . '<br>';

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

// fix new trademark and reg 01-02-2011
//$type = str_replace('<sup>&reg;</sup>', '<sup>®</sup>', $type);
//$type = str_replace('<sup>&trade;</sup>', '<sup>™</sup>', $type);

      // 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];
              
	  if ($type == 'Media MailRM' && $skip_media) {

// skip Media Mail
} else {
$methods[] = array('id' => $type_rebuilt,
'title' => $title,
'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_USPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_USPS_HANDLING) );
}
}
// eof: Media Check

//*********************************************************************************************

  $this->quotes = array('id' => $this->code,
                        'module' => $this->title . $show_box_weight,
                        'methods' => $methods,
                        'tax' => $this->tax_class > 0 ? zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']) : null,

and here is the result no matter what the contents of the cart are.

Shipping quotes are based on the address information you selected:
OHIO 45015 UNITED STATES
Available Shipping Methods Rates
United States Postal Service () $0.00

4 Aug 2013, 2:48 PM
#16
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

Look for this section of the code:

          if ($this->usps_countries == 'US' && MODULE_SHIPPING_USPS_FIRST_CLASS_FILTER_US == 'True' && preg_match('#First\-Class#i', $type) && $cnt_first > 1) continue;

          $methods[] = array('id' => $type_rebuilt,
                             'title' => $title,
                             'cost' => $cost,
                            );

You want to control whether or not the code:

          $methods[] = array('id' => $type_rebuilt,
                             'title' => $title,
                             'cost' => $cost,
                            );

actually runs ...

If you add this code above the IF and the $methods[], you can see what $type you are on before you try to use any custom code:

echo 'USPS $type: ' . $type . '<br>';

Adding that code would give you:

[B]echo 'USPS $type: ' . $type . '<br>';
[/B]          if ($this->usps_countries == 'US' && MODULE_SHIPPING_USPS_FIRST_CLASS_FILTER_US == 'True' && preg_match('#First\-Class#i', $type) && $cnt_first > 1) continue;

          $methods[] = array('id' => $type_rebuilt,
                             'title' => $title,
                             'cost' => $cost,
                            );

Now, start building your custom code ...

Do not add old USPS code, just your custom code ...

4 Aug 2013, 5:01 PM
#17
geckomafia avatar

geckomafia

New Zenner

Join Date:
Apr 2013
Location:
Southgate, KY
Posts:
9
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

Just to verify, I build my custom code between these two lines?

echo 'USPS $type: ' . $type . '<br>';

      if ($this->usps_countries == 'US'  .....
4 Aug 2013, 5:13 PM
#18
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

That is correct ...

You do not need parts of the code you are showing like:

$methods = array();
        $size = sizeof($uspsQuote);
        for ($i=0; $i<$size; $i++) {
          list($type, $cost) = each($uspsQuote[$i]);
		
// fix new trademark and reg 01-02-2011
//$type =  str_replace('&lt;sup&gt;&amp;reg;&lt;/sup&gt;',  '<sup>®</sup>', $type);
//$type =  str_replace('&lt;sup&gt;&amp;trade;&lt;/sup&gt;',  '<sup>™</sup>', $type);

          // 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];

NOTE: there might be another piece, but mainly that section of code belonged to USPS and is not your "custom code" ...

4 Aug 2013, 5:20 PM
#19
geckomafia avatar

geckomafia

New Zenner

Join Date:
Apr 2013
Location:
Southgate, KY
Posts:
9
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

Thanks, I'll work on this later tonight.

4 Aug 2013, 6:31 PM
#20
geckomafia avatar

geckomafia

New Zenner

Join Date:
Apr 2013
Location:
Southgate, KY
Posts:
9
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

So, I trimmed my code down, and here is what I came up with:

          if (preg_match('#First\-Class.*(?!GXG|International)#i', $type)) {
            $cnt_first ++;
          }
//************************************************************************************************
echo 'USPS $type: ' . $type . '<br>';
// bof: Media Check
// test contents for Media Mail
        $skip_media = false;
        $chk_media = 0;
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','68');
		$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','70');
        if ($chk_media != $_SESSION['cart']->count_contents()) {
          $skip_media = true;
        }
echo '<br>IN USPS I SEE ' . $chk_media . ' Media items, and' . ' total items = ' . $_SESSION['cart']->count_contents() . ' Skip Media: ' . ($skip_media == true ? 'YES' : 'NO') . '<br>' . '<br>';
       
	   
	   
          
		  if ($type == 'MEDIA MailRM' && $skip_media) {
// skip Media Mail
          } /*else {
            $cost = preg_replace('/[^0-9.]/', '',  $cost);
            $methods[] = array('id' => $type,
                               'title' => $title,
                               'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_USPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_USPS_HANDLING) );
          }*/
        
// eof: Media Check

		 
//***********************************************************************************************
          if ($this->usps_countries == 'US' && MODULE_SHIPPING_USPS_FIRST_CLASS_FILTER_US == 'True' && preg_match('#First\-Class#i', $type) && $cnt_first > 1) continue;

this gives me rates, but does not filter/skip media mail when non media items are in the cart.

my popup looks like this:

USPS $type: Media MailRM

IN USPS I SEE 1 Media items, and total items = 2 Skip Media: YES

USPS $type: Standard PostRM

IN USPS I SEE 1 Media items, and total items = 2 Skip Media: YES

USPS $type: Priority MailTM

IN USPS I SEE 1 Media items, and total items = 2 Skip Media: YES

USPS $type: Media MailRM

IN USPS I SEE 1 Media items, and total items = 2 Skip Media: YES

Estimate Shipping Costs
Total Items: 2 Weight: 2lbs Amount: $0.00
Country:
State/Province:
Post/Zip Code:
Update
Shipping quotes are based on the address information you selected:
CALIFORNIA 90210 UNITED STATES
Available Shipping Methods Rates
United States Postal Service (Media Mail®) $4.33
United States Postal Service (Standard Post®) $14.20
United States Postal Service (Priority Mail™) $18.70

What confuses me is this:

	```

if ($type == 'MEDIA MailRM' && $skip_media) {
// skip Media Mail
}

In my last version this code worked correctly, but it looks like it does nothing ....

To me it seems like something should be there to remove the media mail as an option.

What am I missing?