Zen Cart Logo
Forums / Addon Shipping Modules / USPS allow media mail based on cart contents?

USPS allow media mail based on cart contents?

Views: 6,380

Results 21 to 35 of 35
4 Aug 2013, 6:42 PM
#21
ajeh avatar

ajeh

Oba-san

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

USPS allow media mail based on cart contents?

How about something like this:

          if (preg_match('#First\-Class.*(?!GXG|International)#i', $type)) {
            $cnt_first ++;
          }

[B]// USPS customize for filtering displayed methods and costs
echo 'USPS $type: ' . $type . '<br>';

// bof: Media Check
// test contents for Media Mail
  $skip_media = false;
  $chk_media = 0;

/* ----------------------- here is where you can add more media mail categories in the future ....
Just copy and paste the following line including semicolon into the correct numerical order and replace the words at the end with the category number

$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','category number goes here');

*/

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

  // skip Media if shopping cart does not hold *only* Products allowed to go Media based on master_categories_id
  if ($chk_media != $_SESSION['cart']->count_contents()) {
    $skip_media = true;
  }

//  if ($type == 'Media MailRM' && $skip_media) {
  if (preg_match('#Media Mail#i', $type) && $skip_media) { // bof: if $skip_media
  // skip Media Mail
//  echo 'USPS Skip Media ' . '<br>';
  } else {
[/B]          if ($this->usps_countries == 'US' && MODULE_SHIPPING_USPS_FIRST_CLASS_FILTER_US == 'True' && preg_match('#First\-Class#i', $type) && $cnt_first > 1) continue;

          $methods[] = array('id' => $type_rebuilt,
                             'title' => $title,
                             'cost' => $cost,
                            );
[B]  } // eof: if $skip_media [/B]
        } 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

      if (sizeof($methods) == 0) return false;
4 Aug 2013, 6:57 PM
#22
geckomafia avatar

geckomafia

New Zenner

Join Date:
Apr 2013
Location:
Southgate, KY
Posts:
9
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

OK that's weird .... This section is exactly what I had as a comment, even weirder, his categories are 77,78,79 ....

/* ----------------------- here is where you can add more media mail categories in the future ....
Just copy and paste the following line including semicolon into the correct numerical order and replace the words at the end with the category number

$chk_media += $_SESSION['cart']->in_cart_check('master_categories_id','category number goes here');

*/

anyway, I'll give this a try later, for now, I need to pack for a trip.

4 Aug 2013, 8:01 PM
#23
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

Sounds good let us know how it works out for you ...

14 Aug 2013, 5:27 AM
#24
daffy avatar

daffy

Zen Follower

Join Date:
Jul 2008
Posts:
114
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

I'm trying to do the same thing. I turned Media Mail on in the shipping module - and carefully inserted the exact code above into the usps.php module. I have two book categories in numerical order as instructed.

But it's only partially working and then the cart bombs during checkout.
I did some screen captures for you.
Here is page 1 of the shopping cart: you can see the extra codes in the middle there.
Attachment 12890

Here is page 2 of the checkout: there are extra codes in the upper left corner, even though the shipping options in the middle are correct:

And here is page 3 of the checkout where the checkout bombs. It's mostly a white screen. I had selected priority mail at this point, wondering if I would get a different result but I get a white screen for any shipping option that is selected:

I'm using the most recent version of the USPS module.
Thank you for all your help.

14 Aug 2013, 8:38 AM
#25
daffy avatar

daffy

Zen Follower

Join Date:
Jul 2008
Posts:
114
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

Well, maybe I fixed it. I removed this bit of code at the top:

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

And now it seems to be working fine. I get media mail if it's ALL books, but if I add something other than books then media mail is removed.
I'm very happy with this, thank you. I owe you a cup of coffee!!

14 Aug 2013, 1:45 PM
#26
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

Yes, the echo is there to help you determine what $type USPS is on, but you cannot have that echo on during the checkout as that will cause the screen not to display ...

Just commenting it out will stop that ...

Thanks for the update that this is now working for you ... and the coffee is always appreciated ... :cool:

16 Aug 2013, 8:22 AM
#27
blessisaacola avatar

blessisaacola

Totally Zenned

Join Date:
Feb 2004
Location:
Georgia, USA
Posts:
1,875
Plugin Contributions:
1

Re: USPS allow media mail based on cart contents?

daffy:

Well, maybe I fixed it. I removed this bit of code at the top:

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

> 
> And now it seems to be working fine. I get media mail if it's ALL books, but if I add something other than books then media mail is removed. 
> I'm very happy with this, thank you.  I owe you a cup of coffee!!

Can you please kindly zip your file and attach it to this post. I'd love to test it as well because we want to offer Medial for CD, DVD and Books categories. Thanks!
24 Oct 2013, 6:43 PM
#28
skinflintmusic avatar

skinflintmusic

New Zenner

Join Date:
Oct 2013
Location:
United States
Posts:
4
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

BlessIsaacola:

Can you please kindly zip your file and attach it to this post. I'd love to test it as well because we want to offer Medial for CD, DVD and Books categories. Thanks!

I am with blessicaala on this..
I have a shop and for the life of me, I cannot get this to work.
my shop is located here - http://shop.skinflintmusic.com
I have a bunch of parent catagories with sub catagories.. I want parent catagories (including the sub catagories) to allow media mail only when the cart has media mail items in it, anything else you cant do media mail. I have NO IDEA where to place this code. I am using the usps module from july 2013, and my version of zen cart is 1.5.1
could antone place a working usps file so we can use it?
I am not a programmer and this just confuses me and i cant get this to work at all.
Thanks alot
Dave
ps.. losing alot of money till i get this working, cause everyone is just choosing media mail...

24 Oct 2013, 6:55 PM
#29
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

When you say Parent Category and SubCategories ...

How many SubCategories are in the Parent Category?

Are ALL the Products in the SubCategories Media Mail?

If you started from the Parent Category and ALL of the SubCategories in that Parent Category only contain Products that can use Media Mail?

26 Oct 2013, 12:36 AM
#30
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: USPS allow media mail based on cart contents?

skinflintmusic:

ps.. losing alot of money till i get this working, cause everyone is just choosing media mail...
Looking at this from another angle: how often IS media-mail a valid choice for the majority of your customers? If it isn't normally suitable, why not turn that choice off and deal with the occasional difference with some sort of rebate that encourages the customer to come back and buy again?

30 Oct 2013, 5:31 PM
#31
skinflintmusic avatar

skinflintmusic

New Zenner

Join Date:
Oct 2013
Location:
United States
Posts:
4
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

DrByte:

Looking at this from another angle: how often IS media-mail a valid choice for the majority of your customers? If it isn't normally suitable, why not turn that choice off and deal with the occasional difference with some sort of rebate that encourages the customer to come back and buy again?

I am a music store selling audio cds and vinyl records, but we also sell band merch like t shirts and stuff..

30 Oct 2013, 5:36 PM
#32
skinflintmusic avatar

skinflintmusic

New Zenner

Join Date:
Oct 2013
Location:
United States
Posts:
4
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

Ajeh:

When you say Parent Category and SubCategories ...

How many SubCategories are in the Parent Category?

Are ALL the Products in the SubCategories Media Mail?

If you started from the Parent Category and ALL of the SubCategories in that Parent Category only contain Products that can use Media Mail?

Hi Ajeh, I thought i responded to you but not sure..
I am a record and cd online store..
I have all my catagories as master catagories except the master catagory called vinyl, which has subcatagories of all vinyl records also.. if you go to my store at http://shop.skinflintmusic.com
you will see my catagories..
there are only 2 master catagories that cannot use media mail if a customer adds one of those to the shopping cart, the catagories are merchendise and package deals..
so if a customer just picks something from the vinyl catagory, they can choose media mail, but if they also add something from package deals or merchandise into their cart, media mail will not be an option..

31 Oct 2013, 6:32 PM
#33
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

You can customize the code:
/includes/modules/shipping/usps.php

with the custom code in RED:

      $cnt_first = 0;

[B]// bof: check for Non MEDIA Products
$chk_cat = 0;
$chk_cats = $_SESSION['cart']->in_cart_check('master_categories_id','11');
$chk_cats += $_SESSION['cart']->in_cart_check('master_categories_id','12');
// eof: check for Non MEDIA Products
[/B]
      for ($i=0; $i<$PackageSize; $i++) {
          if ($this->usps_countries == 'US' && MODULE_SHIPPING_USPS_FIRST_CLASS_FILTER_US == 'True' && preg_match('#First\-Class#i', $type) && $cnt_first > 1) continue;

[B]// bof: check for Non MEDIA Products
//echo 'Display $type: ' . $type . ' $chk_cats: ' . $chk_cats . '<br>';
if ($type == 'Media MailRM' && $chk_cats > 0) {
  // do not show media
} else {
[/B]          $methods[] = array('id' => $type_rebuilt,
                             'title' => $title,
                             'cost' => $cost,
                            );
[B]}
// eof: check for Non MEDIA Products
[/B]        } else {

Now if anything for master_categories_id 11 or 12 are in the Order, Media will not show ...

8 Nov 2013, 6:53 PM
#34
skinflintmusic avatar

skinflintmusic

New Zenner

Join Date:
Oct 2013
Location:
United States
Posts:
4
Plugin Contributions:
0

Re: USPS allow media mail based on cart contents?

Thank You Ajeh, I will try this and let you know..
you should maybe make this part of usps, but just rem it out, and if people want to use it they can unrem it.

9 Nov 2013, 1:44 AM
#35
ajeh avatar

ajeh

Oba-san

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

Re: USPS allow media mail based on cart contents?

As you can see ... how to apply this has changed from one release to another of USPS and could change again ... so it is not always the best thing to just toss into the code as often times the customization required is a lot different from one person's needs to the next ...