-
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.p...ia-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!
-
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?
-
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!
-
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:
Code:
// 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
for ($i=0; $i<$PackageSize; $i++) {
then, add the code in RED:
Code:
//$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
This should then stop Media unless all Products in the cart are Media ...
-
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!
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Did you also do this part of the code:
Code:
// 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
-
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.
-
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
-
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 ...
-
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.
-
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:
-
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
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Quote:
Originally Posted by
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.
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Yes, you need to use:
Code:
$type == 'Media Mail Parcel'
USPS renamed it on the September 7, 2014 changes ...
-
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:
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Tee-hee, it happens to me all the time!
-
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
-
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:
Code:
// 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
// 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
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 ...
-
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)
-
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:
Code:
$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 ...
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
ok, I will worry about the sub sub cats in a bit
To start I have added:
PHP Code:
// 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
// bof: skip Products in any subcategory for parents_id 486
$subcategories_array = array();
$chk_cat = '486'; // 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 486: ' . $chk_cart . '<br>';
// eof: skip Products in any subcategory for parents_id 486
for ($i=0; $i<$PackageSize; $i++) {
I also have this code in place
PHP Code:
$show_hiddenCost = '';
// 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
} else {
{
When I add a non media item, media mail is still offered. When I add a book from a sub cat and a non media item, media mail is still offered. Have I done something wrong? Should I be combining the code with what was posted in post #4?
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
You never set:
$skip_media
so you need an IF or something to set that once you get the results ...
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Quote:
Originally Posted by
Ajeh
You never set:
$skip_media
so you need an IF or something to set that once you get the results ...
yeah...so I'm lost lol. I have tried multiple variations most of which broke things. This one is the latest one I tried which doesn't break my cart but doesn't offer media for anything. I'm sure this must look like a lame attempt
PHP Code:
// bof: skip Products in any subcategory for parents_id 486
$subcategories_array = array();
$chk_cat = '486'; // 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]);
}if ($chk_media != $_SESSION['cart']->count_contents()) {
$skip_media = true;}
//echo 'USPS products in parent category 486: ' . $chk_cart . '<br>';
// eof: skip Products in any subcategory for parents_id 486
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
I used $chk_cart and you are using $chk_media ...
Something like this:
Code:
// bof: skip Products in any subcategory for parents_id 486
$subcategories_array = array();
$chk_cat = '486'; // 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]);
}
if ($chk_cart != $_SESSION['cart']->count_contents()) {
$skip_media = true;
}
//echo 'USPS products in parent category 486: ' . $chk_cart . '<br>';
// eof: skip Products in any subcategory for parents_id 486
might work better ...
NOTE: I do not know if that is your code or your copy and paste that made your IF test look so odd ...
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Quote:
Originally Posted by
Ajeh
I used $chk_cart and you are using $chk_media ...
Something like this:
Code:
// bof: skip Products in any subcategory for parents_id 486
$subcategories_array = array();
$chk_cat = '486'; // 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]);
}
if ($chk_cart != $_SESSION['cart']->count_contents()) {
$skip_media = true;
}
//echo 'USPS products in parent category 486: ' . $chk_cart . '<br>';
// eof: skip Products in any subcategory for parents_id 486
might work better ...
NOTE: I do not know if that is your code or your copy and paste that made your IF test look so odd ...
Awesome, that works great! Adding media items from sub cats and sub sub cats are offered media shipping option. Mixing media and non media items are not offered media shipping option. Adding only non media items are not offered media shipping option. Thank you so much for your help with this.
Not sure what it is that looks odd but I'm sure it must be something I did. Is it the 'if' not starting on a new line that is wrong?
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Code is usually written where the IF would be on its own lines and not bunched up in there ...
Glad that this is now working for you ... :smile:
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Hi,
I'm fairly new to ZenCart and all the way new to php. However, I do have some experience in coding (just a bit) so it doesn't all look like a complete foreign language to me. I'm trying to set up this same thing - exclude media mail as a shipping option for just one category of items in my shop. However, it doesn't seem to be working. What I've done so far is add the recommended code to usps.php; uploaded the modified file to my server under includes / modules / shipping, and verified that the file there is the custom one; and even reinstalled the USPS module afterward, because I wasn't sure if I needed to or not (I know you need to when USPS releases a new version). Still it doesn't seem to work.
Here is what I have added in the .php:
// 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
// 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
for ($i=0; $i<$PackageSize; $i++) {
Then further down:
$show_hiddenCost = '';
// 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,
);
}
// eof: test contents for Media Mail
//echo 'setting insurance: ' . $usps_insurance_charge . '<br>';
} else {
My category ID (it's merch, a.k.a. shirts and whatnot) does appear to be 65:
http://i1337.photobucket.com/albums/...ps584780c5.jpg
What am I missing? The code seems straightforward to me - if category is 65 for any product in the cart (and it is in my tests), then disable the media mail option. But in both estimate shipping and actual checkout, media mail is still coming up.
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Should also note, I tried changing each instances of chk_media to chk_cart and reinstalling again, but that had no effect either.
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Are there only Products in Category 65?
Are you using the current USPS October 30, 2014 K6 version?
http://www.zen-cart.com/showthread.p...ovember-2-2014
This is also a good time to ensure that you are subscribed to the News & Announcements forum:
http://www.zen-cart.com/forumdisplay...-Announcements
And it never hurts to test the correct USPS module is on the server:
Go to your Zen Cart Admin and go to Tools ... Developers Tool Kit ...
In the bottom input box enter:
usps.php
Then, select Catalog ... click SEARCH ...
What comes up on the paths to the files and the lines for:
* @version $Id: usps.php
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Thanks for the quick response -
I have products in category 65 and others. I did a few tests to see how it would behave - checking out one product in another category; then checking out one product from 65; then a combined checkout with a product from each category. In all cases I got a media mail option.
Yes, I'm using the current USPS module. I just installed the newest one this morning before I tackled this project.
The last question might get to the problem, I don't know. This is what came back:
/home2/unspeak4/public_html/purchase/includes/languages/english/modules/shipping/usps.php
Line #12 : * @version $Id: usps.php 2014-09-07 ajeh Version K5 $
/home2/unspeak4/public_html/purchase/includes/modules/shipping/usps.php
Line #14 : * @version $Id: usps.php 2014-10-30 ajeh Version K6 $
I actually only installed to modules / shipping - should the same file go under languages / english / modules / shipping as well?
EDIT - Never mind, I see that I didn't install the languages... .php file, but it's a different file entirely with a lot less in it. Going to load it now just in case that's part of my problem...
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
The shipping language file only contains define statements ...
The code file that goes in the /includes/modules/shipping directory has all of the code in it ...
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Well, I did update the file at languages / english / modules / shipping with the new version, and reinstalled again for good measure. However, the shipping behavior is the same - still getting media mail as an option even when items from cat #65 are in my cart.
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
You said ...
Code:
I have products in category 65 and others.
Does this mean that you have mixed Categories and Products into categories_id 65?
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Quote:
Originally Posted by
Ajeh
You said ...
Code:
I have products in category 65 and others.
Does this mean that you have mixed Categories and Products into categories_id 65?
Sorry, this is where my newness to ZenCart is probably a liability, because I'm not sure what you mean. My shop is set up very simply - the 5 categories you see in the screenshot posted previously are the only ones I've got. When I drill down into cat #65, I have a bunch of products listed there, but no other categories or sub-categories. I'm actually not sure how to make a sub-category but I don't seem to have any, regardless. And I'm just assuming that the Merch category has master_categories_id = 65, because that's the ID that shows on screen next to that category. I don't know how to check the database to verify the actual value at the field level.
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
I also notice this tiny message when I go into my categories/products:
NOTE: Category has SubCategories
Products cannot be added
I'm not sure if that means I'm already inside a master category, and am viewing sub-categories..? This is a bit confusing.
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
A Category holds Products or Categories ... never both ...
If your Category 65 has both Categories and Products, you need to either move the Products to their own Category, which would then become its master_categories_id or you need to move the Categories in there out to be their own Categories ...
Have you an URL to your site where we can peek at the layout of your Categories/Products?
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
For testing purposes, I've also tried adding a specific product ID that I am using to play with. I modified the first section of code as follows:
// bof: test contents for Media Mail
$skip_media = false;
$chk_cart = 0;
$chk_cart += $_SESSION['cart']->in_cart_check('products_id','219');
$chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','65');
if ($chk_cart != $_SESSION['cart']->count_contents()) {
$skip_media = true;
}
// eof: test contents for Media Mail
219 being a hooded sweatshirt in the store. When I go to checkout with this item, it's still allowing media mail even though both the product ID and the category ID seem like it should be excluded.
I feel like I must be missing something dumb somewhere, because this seems so simple in what it's doing.
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Quote:
Originally Posted by
Ajeh
A Category holds Products or Categories ... never both ...
Oh - well as far as I can tell, it only holds products.
Quote:
If your Category 65 has both Categories and Products, you need to either move the Products to their own Category, which would then become its master_categories_id or you need to move the Categories in there out to be their own Categories ...
Have you an URL to your site where we can peek at the layout of your Categories/Products?
Certainly - it's located at http://www.unspeakableaxerecords.com/purchase
Here is category 65: http://www.unspeakableaxerecords.com...index&cPath=65
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Remove this line:
Code:
$chk_cart += $_SESSION['cart']->in_cart_check('products_id','219');
If I have ONLY Product from categories_id 65 in the cart, you want to see Media, correct?
If I have Products in the cart and none are in categories_id 65, you do NOT want to see Media, correct?
And if I have a Product from categories_id 65 and something from another categories_id in the cart, you do NOT want to see Media, correct?
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Quote:
Originally Posted by
Ajeh
Remove this line:
Code:
$chk_cart += $_SESSION['cart']->in_cart_check('products_id','219');
If I have ONLY Product from categories_id 65 in the cart, you want to see Media, correct?
If I have Products in the cart and none are in categories_id 65, you do NOT want to see Media, correct?
And if I have a Product from categories_id 65 and something from another categories_id in the cart, you do NOT want to see Media, correct?
It's the other way around - if any product from 65 is in the cart, by itself or combined with another product, then I do NOT want to see Media. If non-category 65 products are in the cart, then Media is fine.
-
Re: 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:
Code:
//if ($chk_media != $_SESSION['cart']->count_contents()) {
if ($chk_media > 0) {
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Perfect! Thank you, it's working now.
-
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:
-
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?
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Look around line 702 and add:
Code:
$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:
Code:
// 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:
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Thank you! Worked like a charm!
-
Re: Media Mail restriction mod to new, 3-7-14 usps module, any help?
Glad that all is working now! :smile:
-
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
-
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
Code:
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;
-
USPS override 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.
PHP Code:
// 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.
-
Re: USPS override 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)?
-
Re: USPS override help?
Quote:
Originally Posted by
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.
-
Re: USPS override 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):
Code:
$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([\'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)\'], ', 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.
-
Re: USPS override help?
Quote:
Originally Posted by
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):
Code:
$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([\'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)\'], ', 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!
-
Re: USPS override 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
PHP Code:
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.
-
Re: USPS override 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
Code:
$chk_cart += $_SESSION['cart']->get_quantity('148') > 0; // Soothamide
to
Code:
$chk_cart += $_SESSION['cart']->get_quantity('148'); // Soothamide
As get_quantity, return 0 if it doesn't find the product in the cart.
-
Re: USPS override help?
Good eyes, @brittainmark!
-
Re: USPS override help?
Quote:
Originally Posted by
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
Code:
$chk_cart += $_SESSION['cart']->get_quantity('148') > 0; // Soothamide
to
Code:
$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.
-
Re: USPS override 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.
-
Re: USPS override help?
... and the file is present in /includes/classes/observers/auto.usps_overrides.php?
-
Re: USPS override help?
Quote:
Originally Posted by
lat9
... and the file is present in /includes/classes/observers/auto.usps_overrides.php?
Ah. You nailed it. The file was in the wrong location. When I moved it, it's being executed. I'm not sure why I thought it was supposed to be where I had it, but that was clearly wrong. Thank you very much!
-
Re: USPS override help?
Whew, I was running out of ideas. Glad that it's ... finally ... working.