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,610

Results 41 to 60 of 62
15 Nov 2014, 5:26 PM
#41
ajeh avatar

ajeh

Oba-san

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

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

If you do not want to see Media when 1 or more Products from categories_id 65 is in the cart, then change the IF:

[B]//[/B]if ($chk_media != $_SESSION['cart']->count_contents()) {
[B]if ($chk_media > 0) {[/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!

15 Nov 2014, 5:31 PM
#42
dalecooper avatar

dalecooper

New Zenner

Join Date:
Nov 2014
Location:
Athens, GA
Posts:
25
Plugin Contributions:
0

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

Perfect! Thank you, it's working now.

15 Nov 2014, 6:08 PM
#43
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?

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

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!

28 Jun 2017, 11:16 PM
#44
seattleannie avatar

seattleannie

Zen Follower

Join Date:
Oct 2005
Posts:
151
Plugin Contributions:
0

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

Hi Ajeh,

I just found this thread today. This is exactly the problem I am working on. I am creating a 1.5.5e site, which has the USPS module (USPS_2016_0107_K8). My client sells a variety of types (and weights) of items, including books. She would like the media shipping option to only appear when ONLY books are being purchased. Mixed type purchases do not qualify for media mail, according to the USPS website. All my clients books are in one sub-category together, which should make this easier, I would guess. But as I read through this thread, I got confused - perhaps because I am working with newer versions of Zen Cart and the USPS module. I made the recommended edits, but resulted in (apparently) excluding media mail from appearing in ALL situations. First, I put a non-media item in cart. No media shipping option appeared = good. Then, added a book to the same cart. Still no media option = also good. Then, I removed the non-media item from my cart so I had just a book in my cart. Still no media option appeared. Could you, perhaps, take a fresh look at this in the 1.5.5e Zen Cart and latest USPS module files and give me some instructions to accomplish my goal of media mail only appearing when ONLY items from the Books category are in the cart?

29 Jun 2017, 1:30 PM
#45
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?

Look around line 702 and add:

$show_hiddenCost = '';
// bof: test contents for Media Mail
$skip_media = false;
$chk_media = 0;
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','65');
if ($chk_media != $_SESSION['cart']->count_contents()) {
$skip_media = true;
}
// eof: test contents for Media Mail

Then add:

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

See if that helps ... :smile:

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!

29 Jun 2017, 7:43 PM
#46
seattleannie avatar

seattleannie

Zen Follower

Join Date:
Oct 2005
Posts:
151
Plugin Contributions:
0

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

Thank you! Worked like a charm!

29 Jun 2017, 8:42 PM
#47
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 all is working now! :smile:

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!

17 Aug 2022, 10:10 PM
#48
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?

Updated to latest USPS (2022-08-07 K11e_) but having an issue with limiting Media Mail Parcel

I would like to only allow Media Mail Parcel when a product from category 45 is in the cart.
If another product is added that is not from category 35, then don't show Media Mail Parcel

Noticed auto.usps_overrides.php

if (stripos($p1, 'Media Mail') !== false) {
$chk_media = 0;
$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id', '45');
if ($chk_media == $_SESSION['cart']->count_contents()) {
$p2 = true;
}

Not understanding what to do

$p2 = false; (Should I change this to True? )


usps.php - Do I still need to add this? I added it to line 565


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

--------------------------------------------------------
And this code? Not sure if the is needed since the auto.usps_overrides.php takes care of it? Add it in the Customization area?

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

18 Aug 2022, 11:18 AM
#49
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?

The auto-loaded observer will take care of that; no need to provide additional edits to the usps.php shipping module. You'll change the observer's checking clause to read

            case 'NOTIFY_USPS_UPDATE_OR_DISALLOW_TYPE':
                // -----
                // Disallow "Media Mail" unless all products in the cart have a master_categories_id of '45'.
                //
                if (stripos($p1, 'Media Mail') !== false) {
                    if ($_SESSION['cart']->in_cart_check('master_categories_id', '45') !== $_SESSION['cart']->count_contents()) {
                         $p2 = false;
                    }
                }
                break;
7 Aug 2023, 7:42 PM
#50
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

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

I see what's going on with the override, in general. But I don't know how the services are defined any more.

For example, I've tried this code with the text "Small Flat Rate Box" and "USPS Priority MailTM Small Flat Rate Box" and "USPS Priority MailRM Small Flat Rate Box," and it isn't working with any of those. I recall when the designation changed from TM to RM, but neither of those appears to be correct any more.

                // Disallow Small Flat Rate Box             
                if (stripos($p1, 'Small Flat Rate Box') !== false) {
                   $chk_cart = 0;
                   $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','1'); // golden paste
                   $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','2'); // spicees
                   $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','3'); // accessories
                   $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','5'); // livestock feed   
                   $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','10'); // oils
                   $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','11'); // pet products
                   $chk_cart += $_SESSION['cart']->get_quantity('148') > 0; // Soothamide
                   if ($chk_cart == $_SESSION['cart']->count_contents() ) {
                      $p2 = false;
                    }

I feel like I'm missing something obvious, sigh.

7 Aug 2023, 11:41 PM
#51
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?

Helene, that looks like it should work. There's a specific naming convention for auto-loaded observer-class modules.

What's the name of the auto.*.php class file and the name of the class (i.e. class ClassName)?

8 Aug 2023, 7:33 PM
#52
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

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

lat9:

Helene, that looks like it should work. There's a specific naming convention for auto-loaded observer-class modules.

What's the name of the auto.*.php class file and the name of the class (i.e. class ClassName)?

It's the overrides file for the USPS customization. The Class is zcObserverUspsOverrides and the file is auto.usps_overrides.php.

Sorry, I thought I was asking in the thread for the USPS module, didn't notice I was elsewhere.

9 Aug 2023, 3:20 AM
#53
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?

Helene, edit /includes/modules/shipping/usps.php to locate its install function. You'll see a section of code like the following (which is K11i):

        $db->Execute(
            "INSERT INTO " . TABLE_CONFIGURATION . "
                (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added)
             VALUES
                ('Shipping Methods (Domestic and International)',  'MODULE_SHIPPING_USPS_TYPES',  '0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, .21875, 0.00, 0, 4, 0.00, 0, 4, 0.00, 0, 66, 0.00, 0, 4, 0.00, 0, 4, 0.00, 0, 20, 0.00, 0, 20, 0.00, 0, 66, 0.00, 0, 4, 0.00, 0, 70, 0.00, 0, 70, 0.00', '<b><u>Checkbox:</u></b> Select the services to be offered<br><b><u>Minimum Weight (lbs)</u></b>first input field<br><b><u>Maximum Weight (lbs):</u></b>second input field<br><br>USPS returns methods based on cart weights.  These settings will allow further control (particularly helpful for flat rate methods) but will not override USPS limits', 6, 0, 'zen_cfg_usps_services([[B]\'Media Mail Parcel\', \'USPS Ground AdvantageTM\', \'Priority MailRM\', \'Priority MailRM Flat Rate Envelope\', \'Priority MailRM Legal Flat Rate Envelope\', \'Priority MailRM Padded Flat Rate Envelope\', \'Priority MailRM Small Flat Rate Box\', \'Priority MailRM Medium Flat Rate Box\', \'Priority MailRM Large Flat Rate Box\', \'Priority Mail ExpressRM\', \'Priority Mail ExpressRM Flat Rate Envelope\', \'Priority Mail ExpressRM Legal Flat Rate Envelope\', \'First-Class MailRM International Letter\', \'First-Class MailRM International Large Envelope\', \'First-Class Package International ServiceTM\', \'Priority Mail InternationalRM\', \'Priority Mail InternationalRM Flat Rate Envelope\', \'Priority Mail InternationalRM Small Flat Rate Box\', \'Priority Mail InternationalRM Medium Flat Rate Box\', \'Priority Mail InternationalRM Large Flat Rate Box\', \'Priority Mail Express InternationalRM\', \'Priority Mail Express InternationalRM Flat Rate Envelope\', \'USPS GXGTM Envelopes\', \'Global Express GuaranteedRM (GXG)\'[/B]], ', now())"
        );

Don't pay attention to the various ' elements (they're needed for the database insert), but those strings identify the various USPS shipping methods supported by the shipping module.

9 Aug 2023, 6:46 PM
#54
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

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

lat9:

Helene, edit /includes/modules/shipping/usps.php to locate its install function. You'll see a section of code like the following (which is K11i):

    $db->Execute(
        "INSERT INTO " . TABLE_CONFIGURATION . "
            (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added)
         VALUES
            ('Shipping Methods (Domestic and International)',  'MODULE_SHIPPING_USPS_TYPES',  '0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, 70, 0.00, 0, .21875, 0.00, 0, 4, 0.00, 0, 4, 0.00, 0, 66, 0.00, 0, 4, 0.00, 0, 4, 0.00, 0, 20, 0.00, 0, 20, 0.00, 0, 66, 0.00, 0, 4, 0.00, 0, 70, 0.00, 0, 70, 0.00', '<b><u>Checkbox:</u></b> Select the services to be offered<br><b><u>Minimum Weight (lbs)</u></b>first input field<br><b><u>Maximum Weight (lbs):</u></b>second input field<br><br>USPS returns methods based on cart weights.  These settings will allow further control (particularly helpful for flat rate methods) but will not override USPS limits', 6, 0, 'zen_cfg_usps_services([[B]\'Media Mail Parcel\', \'USPS Ground AdvantageTM\', \'Priority MailRM\', \'Priority MailRM Flat Rate Envelope\', \'Priority MailRM Legal Flat Rate Envelope\', \'Priority MailRM Padded Flat Rate Envelope\', \'Priority MailRM Small Flat Rate Box\', \'Priority MailRM Medium Flat Rate Box\', \'Priority MailRM Large Flat Rate Box\', \'Priority Mail ExpressRM\', \'Priority Mail ExpressRM Flat Rate Envelope\', \'Priority Mail ExpressRM Legal Flat Rate Envelope\', \'First-Class MailRM International Letter\', \'First-Class MailRM International Large Envelope\', \'First-Class Package International ServiceTM\', \'Priority Mail InternationalRM\', \'Priority Mail InternationalRM Flat Rate Envelope\', \'Priority Mail InternationalRM Small Flat Rate Box\', \'Priority Mail InternationalRM Medium Flat Rate Box\', \'Priority Mail InternationalRM Large Flat Rate Box\', \'Priority Mail Express InternationalRM\', \'Priority Mail Express InternationalRM Flat Rate Envelope\', \'USPS GXGTM Envelopes\', \'Global Express GuaranteedRM (GXG)\'[/B]], ', now())"
    );
> Don't pay attention to the various **\'** elements (they're needed for the database insert), but those strings identify the various USPS shipping methods supported by the shipping module.

Thank you, that's what I needed!
9 Aug 2023, 7:22 PM
#55
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

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

Cindy, what am I missing here? The logic is obvious but it isn't working. For example, in the sample included in auto.usps_overrides.php, $p1 should be (or at least include) the string 'Media Mail,' isn't that correct? So in my addition using 'Priority MailRM Small Flat Rate Box,' $p1 should be (or include) that string. But it clearly does not, since the conditional statement is failing.

I corrected my code to read

      if (stripos($p1, 'Priority MailRM Small Flat Rate Box') !== false) {   
                 $chk_cart = 0;
                 $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','1'); // golden paste
                 $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','2'); // spices
                 $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','3'); // accessories
                 $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','5'); // livestock feed   
                 $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','10'); // oils
                 $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','11'); // pet products
                 $chk_cart += $_SESSION['cart']->get_quantity('148') > 0; // Soothamide
                 if ($chk_cart > 0) {
                   $p2 = false;
                 }  
               }
               break;

since I want to exclude that shipping method if anything in the cart falls in the specified categories. But this is still permitting a customer to choose a small flat rate box for items in those categories.

10 Aug 2023, 10:06 AM
#56
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
507
Plugin Contributions:
1

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

Hi Helen,
have you checked that $p1 is as you expect? Either using a debugging tool that will allow you to see the value of $p1 or by adding a line to the code to echo the value of $p1 so you can confirm you have the correct string.

Also don't think it is the issue, but you could change

$chk_cart += $_SESSION['cart']->get_quantity('148') > 0; // Soothamide

to

$chk_cart += $_SESSION['cart']->get_quantity('148'); // Soothamide

As get_quantity, return 0 if it doesn't find the product in the cart.

Mark Brittain
http:\innerlightcrystals.co.uk\sales\

10 Aug 2023, 1:58 PM
#57
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?

Good eyes, @brittainmark!

10 Aug 2023, 7:29 PM
#58
helenewallis avatar

helenewallis

Totally Zenned

Join Date:
Jun 2016
Location:
Suffolk VA
Posts:
625
Plugin Contributions:
0

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

brittainmark:

Hi Helen,
have you checked that $p1 is as you expect? Either using a debugging tool that will allow you to see the value of $p1 or by adding a line to the code to echo the value of $p1 so you can confirm you have the correct string.

Also don't think it is the issue, but you could change

$chk_cart += $_SESSION['cart']->get_quantity('148') > 0; // Soothamide

> to 
> 
> ```
$chk_cart += $_SESSION['cart']->get_quantity('148'); // Soothamide

As get_quantity, return 0 if it doesn't find the product in the cart.

I attempted to use echo to see $p1, but it isn't showing up. In fact, I'm not certain the file is even being seen, because nothing I do to it, including deliberate syntax errors, make any difference.

Thank you for the modification on the Soothamide line. But that isn't the problem. It isn't ever getting executed.

12 Aug 2023, 9:46 AM
#59
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
507
Plugin Contributions:
1

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

I assume that if you go to the cart, the UPS postage option is there.
If that is true, I assume that you viewed the page source to look for the echo you put in.
To check the observer is being loaded. If you put a syntax error into auto.usps_overrides.php you should get a white screen when trying to check out. (the auto.usps_overrides.php should be present in includes/classes/observers) if you are not getting a white screen, then the file is not being loaded.

Sorry not in the US so I do not have an account to test.

Mark Brittain
http:\innerlightcrystals.co.uk\sales\

12 Aug 2023, 12:49 PM
#60
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?

... and the file is present in /includes/classes**/observers**/auto.usps_overrides.php?