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.