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...