Zen Cart Logo
Forums / Addon Shipping Modules / Media Mail restriction mod to new, 3-7-14 usps module, any help?

Media Mail restriction mod to new, 3-7-14 usps module, any help?

Views: 11,611

Results 1 to 20 of 62
23 Mar 2014, 12:39 AM
#1
linniedarling avatar

linniedarling

New Zenner

Join Date:
Feb 2014
Location:
Austin, TX USA
Posts:
52
Plugin Contributions:
0

Media Mail restriction mod to new, 3-7-14 usps module, any help?

Hi,

I have a new ZC that I'm about to launch. Some of my products qualify for Media Mail and some do not. It is probable that my customers may choose a mix.

I would like to restrict the display of the Media Mail option to ship if non-qualifying products exist in the cart or display Media Mail as a shipping option if only qualifying products are in the cart.

There is an old forum discussion dated 2009 about adding a category filter within the usps.php module to do just this:

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

A solution similar to this would work just fine. However, the code within the usps.php has changed considerably since 2009. I can see that things are organized a bit differently and my attempts to read the code to find a suitable insertion point are failing.

Can anyone give me a start on this? I'm not new to programming but am completely unfamiliar with php.

many thanks!

23 Mar 2014, 1:04 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

Are all of your Media Products in one specific master_categories_id or are they in multiple master_categories_id?

If not, are they all in a few master_categories_id?

If not, how are these Media Products identified?

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!]
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!

23 Mar 2014, 1:30 PM
#3
linniedarling avatar

linniedarling

New Zenner

Join Date:
Feb 2014
Location:
Austin, TX USA
Posts:
52
Plugin Contributions:
0

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

Hi Ajeh,

I have a limited number of level categories that have Media Mail product candidates, probably 12. Eventually that might grow to 20 but no more. These categories only have Media Mail candidates and no other type of product. In other words my shop is organized in a way that excluding categories is probably the way to go (as opposed to products using, say, a keyword).

Moreover there are only two higher level categories, meaning these 12 product carrying categories live under one of two higher level categories.

thanks!

23 Mar 2014, 1:40 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

Let's say your master_categories_id are 10, 12 an 15 ...

You would add the code in **RED **around line 390:

[B]// bof: test contents for Media Mail
        $skip_media = false;
        $chk_media = 0;
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','10');
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','12');
        $chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','15');
        if ($chk_media != $_SESSION['cart']->count_contents()) {
          $skip_media = true;
        }
// eof: test contents for Media Mail
[/B]
      for ($i=0; $i<$PackageSize; $i++) {

then, add the code in RED:

//$show_hiddenCost =  ' $hiddenCost: ' . $hiddenCost;
$show_hiddenCost = '';
[B]// bof: test contents for Media Mail
          if ($type == 'MEDIA' && $skip_media) {
            // skip Media Mail
          } else {
[/B]          $methods[] = array('id' => $type_rebuilt,
                             'title' => $title . $show_hiddenCost,
                             'cost' => $cost,
                            );
[B]          }
// eof: test contents for Media Mail
[/B]

This should then stop Media unless all Products in the cart are Media ...

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!]
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!

23 Mar 2014, 3:51 PM
#5
linniedarling avatar

linniedarling

New Zenner

Join Date:
Feb 2014
Location:
Austin, TX USA
Posts:
52
Plugin Contributions:
0

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

I added the code mod for my categories but it's not working - nothing's broken either but Media Mail still appears on non-eligible items. I've refreshed and tried on several other browsers with clearing cache too.

Would attach the php file but says file invalid. I've double checked the three insertion points and I'm pretty sure I have not made a mistake.

any help on this?

Here's my URL: http://192.185.60.92/~linbo/

and my cats:

// bof: test contents for Media Mail
$skip_media = false;
$chk_media = 0;
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','27');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','28');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','29');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','30');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','31');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','82');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','83');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','85');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','86');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','87');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','88');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','89');
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','391');
if ($chk_media != $_SESSION['cart']->count_contents()) {
$skip_media = true;
}
// eof: test contents for Media Mail

thanks!

23 Mar 2014, 4:45 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

Did you also do this part of the code:

[B]// bof: test contents for Media Mail
          if ($type == 'MEDIA' && $skip_media) {
            // skip Media Mail
          } else {
[/B]          $methods[] = array('id' => $type_rebuilt,
                             'title' => $title . $show_hiddenCost,
                             'cost' => $cost,
                            );
[B]          }
// eof: test contents for Media Mail[/B]

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!]
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!

23 Mar 2014, 4:50 PM
#7
linniedarling avatar

linniedarling

New Zenner

Join Date:
Feb 2014
Location:
Austin, TX USA
Posts:
52
Plugin Contributions:
0

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

OK I added this line

print_r($type_rebuilt);

immediately underneath the

// eof test contents for Media Mail

And this is what printed. So Media Mail is not being filtered out.

First-Class Mail ParcelMedia MailRMStandard PostRMPriority MailTMPriority Mail ExpressTMFirst-Class Mail Parcel

I wish I knew php better. It looks like the array needs to see if Media Mail is part of the group and then return a stripped version to the $type or $type_rebuilt array.

I also noticed that the code patch references $type and not $type_rebuilt.

23 Mar 2014, 4:52 PM
#8
linniedarling avatar

linniedarling

New Zenner

Join Date:
Feb 2014
Location:
Austin, TX USA
Posts:
52
Plugin Contributions:
0

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

Hi Ajeh,

Yes, I added the first piece with my own category ids, the second piece a bit later on, and then the close paren with comment. Identical to what you posted.

Is there a restriction on uploading php code as attachments? I cannot get usps.php to attach - keeps saying invalid file

here is a larger snip of the second code mod area:

// USPS customize for filtering displayed methods and costs
//echo '<br />USPS info: ' . '<br />$type: ' . $type . '<br />$type_rebuilt: ' . $type_rebuilt . '<br />$title: ' . $title . ' $cost: ' . $cost . '<br />';

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

      // ADDITIONAL CUSTOMIZED CONDITIONS CAN GO HERE TO MANAGE $type_rebuilt or $title on $methods

// switch comment marks to show $hiddenCost: from quote title
//$show_hiddenCost = ' $hiddenCost: ' . $hiddenCost;
$show_hiddenCost = '';

// bof: test contents for Media Mail
if ($type == 'MEDIA' && $skip_media) {
// skip Media Mail
} else {

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

// eof: test contents for Media Mail

    } else {

//echo 'MISSING! USPS $type: ' . $type . (in_array($type, $this->typeCheckboxesSelected) ? ' YES' : ' NO') . ' $method: ' . $method . ' $usps_shipping_weight: ' . $usps_shipping_weight . ' $minweight: ' . $minweight . ' $maxweight: ' . $maxweight . '<br>';
}
} // end for $i to $PackageSize

thanks

23 Mar 2014, 5:04 PM
#9
ajeh avatar

ajeh

Oba-san

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

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

My bad ... I forgot that the current USPS shipping module now has:
Media MailRM vs MEDIA

Change the IF to use **Media MailRM **...

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!]
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!

23 Mar 2014, 5:11 PM
#10
linniedarling avatar

linniedarling

New Zenner

Join Date:
Feb 2014
Location:
Austin, TX USA
Posts:
52
Plugin Contributions:
0

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

aha! that did the trick!

You are most awesomeness personified! thank you.

23 Mar 2014, 6:39 PM
#11
ajeh avatar

ajeh

Oba-san

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

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

Glad that this is working for you now ...

Thanks for the kudos and support we really appreciate it a lot ... coffee and donuts keep the Zen Cart Team humming right along ... :cool:

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!]
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!

20 Sep 2014, 9:41 AM
#12
regjimbob avatar

regjimbob

New Zenner

Join Date:
Jul 2014
Location:
Florida
Posts:
11
Plugin Contributions:
0

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

I was trying to get the Media Mail restrictions to work as well and added the code per the instructions above.

I am using the latest version Version: 2014-09-07 K5

And instead of using Media MailRM, I had to use Media Mail Parcel

I used the print_r($type_rebuilt);
that linniedarling suggested and it output:
First-Class Mail ParcelMedia Mail ParcelPriority MailTM

So I guess that's what you all were doing and it seems to have worked for me.
I am not that good with PHP at all (took me 2 hours just to get this working)
So if anyone could double check to make sure

20 Sep 2014, 1:04 PM
#13
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,102
Plugin Contributions:
56

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

regjimbob:

I was trying to get the Media Mail restrictions to work as well and added the code per the instructions above.

I am using the latest version Version: 2014-09-07 K5

And instead of using Media MailRM, I had to use Media Mail Parcel

I used the print_r($type_rebuilt);
that linniedarling suggested and it output:
First-Class Mail ParcelMedia Mail ParcelPriority MailTM

So I guess that's what you all were doing and it seems to have worked for me.
I am not that good with PHP at all (took me 2 hours just to get this working)
So if anyone could double check to make sure
Yes, the USPS changed the name of Media Mail from Media MailRM to Media Mail Parcel going from the 3/7 to 9/7 implementations.

20 Sep 2014, 1:06 PM
#14
ajeh avatar

ajeh

Oba-san

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

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

Yes, you need to use:

$type == 'Media Mail Parcel'

USPS renamed it on the September 7, 2014 changes ...

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!]
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!

20 Sep 2014, 1:07 PM
#15
ajeh avatar

ajeh

Oba-san

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

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

Dontcha hate when you get interrupted when posting only to find your answer posted 2 minutes before your own ... :cool:

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!]
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!

20 Sep 2014, 1:15 PM
#16
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,102
Plugin Contributions:
56

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

Tee-hee, it happens to me all the time!

7 Oct 2014, 3:23 PM
#17
buildingblocks avatar

buildingblocks

Totally Zenned

Join Date:
Jun 2008
Posts:
629
Plugin Contributions:
0

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

Hi

I have added this modification to my shop. My media related items are located within sub-categories of the parent category

EX:

books (id 342)

  • cookbooks (id 24)
  • childrens books (id 52)
  • old school books (id 72)

I have 32 sub categories in the books category but that sub category amount will probably increase over time. Is there a way to add the parent category ID 342 in such a way that all its sub categories would be included without having to add the ID for each subcategory manually?

using

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

doesn't work so I need to add the sub cat id instead

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

If it's possible it would be good because I have a feeling a few months from now if I add a new sub cat I will probably forget to edit the usps.php file.

thanks

7 Oct 2014, 3:58 PM
#18
ajeh avatar

ajeh

Oba-san

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

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

You could use this code in **RED **to count how many products are in the cart for that parent categories_id:

// see below use of $chk_cart
// eof: example to block USPS Priority MailTM Small Flat Rate Box when anything from master_categories_id 12 or 15 are in the cart

[B]// bof: skip Products in any subcategory for parents_id 3
      $subcategories_array = array();
      $chk_cat = '3'; // parent categories_id
      $chk_cart = 0;
      zen_get_subcategories($subcategories_array, $chk_cat);
      for ($i=0, $n=sizeof($subcategories_array); $i<$n; $i++ ) {
        $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id', $subcategories_array[$i]);
      }
//echo 'USPS products in parent category 3: ' . $chk_cart . '<br>';
// eof: skip Products in any subcategory for parents_id 3
[/B]
      for ($i=0; $i<$PackageSize; $i++) {

Just change the $chk_cat to your parent categories_id 342 and $chk_cart will have the quantity that is in the 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!]
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 Oct 2014, 4:24 PM
#19
buildingblocks avatar

buildingblocks

Totally Zenned

Join Date:
Jun 2008
Posts:
629
Plugin Contributions:
0

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

thank you

ohhh I'm sorry, I forgot that some books are in sub sub cats too. Would that significantly change the code you provided?

For instance

books (id 342)

  • cookbooks (id 24)
  • childrens books (id 52)
  • old school books (id 72)
  • crafts and hobbies (id 97)
    -- a sub sub cat (id 231)
    -- a sub sub cat (id 321)
    -- a sub sub cat (id 523)
7 Oct 2014, 4:30 PM
#20
ajeh avatar

ajeh

Oba-san

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

Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?

If you need to calculate the Products in the Shopping Cart for both a Parent Category and then additional categories, beneath the code that I gave you to calculate the Products from all categories within a parent category, you can add the additional categories you need with:

$chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','231');
$chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','321');
$chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','523');

to combine the products that match ...

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!]
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!