Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Block shipping options for certain items...?

Block shipping options for certain items...?

Views: 4,462

Results 21 to 36 of 36
30 Aug 2013, 11:04 PM
#21
d0ugparker avatar

d0ugparker

Zen Follower

Join Date:
May 2008
Location:
Near the water, somewhere...
Posts:
129
Plugin Contributions:
0

Block shipping options for certain items...?

***Bump. ***

Ajeh,

I'm reviving this thread because it accomplishes
what I want. The thread is from 2011, which is
pre-1.5.1, and I'm using 1.5.1. I want to be sure
I can use your code in v1.5.1.

If the code works the way I'm reading it, when the
customer orders anything from the master
categories 10, 12, or 22, the Media Mail option
will go away as a USPS shipping option until the
items from those categories are removed from
the shopping cart. That's what I want. My master
category is 9, my sub categories are 14 and 15.
If any items in the cart is from master category
number 9, which can include items from the sub
categories 14 or 15, the Media Mail option will
need to disappear.

So, can I still use your lines of codes with v1.5.1?

Regards,

Doug Parker
Redondo Beach, CA
USA

31 Aug 2013, 2:43 AM
#22
ajeh avatar

ajeh

Oba-san

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

Re: Block shipping options for certain items...?

See if post #21 helps get you closer to what you are trying to do for the new USPS July 28, 2013 J5 code ...
http://www.zen-cart.com/showthread.php?207406-USPS-allow-media-mail-based-on-cart-contents&highlight=USPS+media

You will need to customize it further for your needs, but it should head you in the right direction ...

31 Aug 2013, 5:58 PM
#24
d0ugparker avatar

d0ugparker

Zen Follower

Join Date:
May 2008
Location:
Near the water, somewhere...
Posts:
129
Plugin Contributions:
0

Re: Block shipping options for certain items...?

Thanks for the quick reply. I'll update as needed.

(/|) peace

31 Aug 2013, 9:28 PM
#25
d0ugparker avatar

d0ugparker

Zen Follower

Join Date:
May 2008
Location:
Near the water, somewhere...
Posts:
129
Plugin Contributions:
0

Re: Block shipping options for certain items...?

With minimal :head banging:, I was able to get your code suggestion working with corrections:

// bof: *** CUSTOMIZE FOR MEDIA ***

//echo '<br>Check that ALL products in cart are MEDIA products:' . '<br>';
      $skip_media_parent_categories_id = 9;
// 9 is my parent category
      $skip_media = true;
      //changed from false to true
      // products from cart
      $products = $_SESSION['cart']->get_products();
      $cart_products_id_array = array();
      for ($i=0; $i<sizeof($products); $i++) {
        $cart_products_id_array[] = (int)$products[$i]['id'];
//echo '(int)$products[$i][id]: ' . (int)$products[$i]['id'] . '<br>';
      }

      // products from MEDIA parent category and all sub-categories
      $chk_media = zen_get_categories_products_list($skip_media_parent_categories_id);
      $list_of_products_media_array = array();
      foreach($chk_media as $key => $value) {
        $list_of_products_media_array[] = $key;
//echo '$key: ' . $key . '<br>';
      }
      $cart_vs_media_diff = array_diff($cart_products_id_array, $list_of_products_media_array);
      if (sizeof($cart_vs_media_diff) == sizeof($cart_products_id_array)) {
      // was > 0
        $skip_media = false;
        //changed from true to false
      }
//echo 'SKIP MEDIA? ' . ($skip_media ? 'YES! NOT MEDIA: ' . sizeof($cart_vs_media_diff) : 'NO!') . '<br>';
//echo '$chk_products_incart_list: ' . print_r($cart_products_id_array) . '<br>';
//echo '$list_of_products_media: ' . print_r($list_of_products_media_array) . '<br>';
//echo 'sizeof($cart_vs_media_diff): ' . sizeof($cart_vs_media_diff) . ' NOT MEDIA: ' . print_r($cart_vs_media_diff) . '<br><br>';

// eof: *** CUSTOMIZE FOR MEDIA ***

I think I remember a thread where the opposite of what was desired was being done -- that instead of tracking Media Mail items, it was tracking non-Media Mail items, so the wrong options were being displayed. Undoing that logic resulted in some additional :head banging:.

Finally, be forewarned that there are cases where Media Mail will be the only option, but since it gets dropped, a blank shipping calculator is displayed. For those cases, I've added into the shipping estimator column heading:

Seeing a blank shipping calculator form? Try removing foo and bar -- those require separate orders.

If there are ways to prevent a blank shipping estimator from being presented, I'd like to hear about it, prolly in a separate thread, since the approach here doesn't take into account the number of shipping methods available before dropping the Media Mail option from the list.

Warm regards,

Doug

1 Sep 2013, 9:51 PM
#26
d0ugparker avatar

d0ugparker

Zen Follower

Join Date:
May 2008
Location:
Near the water, somewhere...
Posts:
129
Plugin Contributions:
0

Re: Block shipping options for certain items...?

Additionally, I found that free shipping items will throw
off the logic, and that special tests were needed through
a complicated maze of cart items, including Media Mail
items, non-Media Mail items, mixed Media Mail and non-
Media Mail items, free shipping items, and what the
results of these different combinations created, including
if a warning message was displayed, and whether or not
the calculated USPS Media Mail shipping option was
displayed on the screen.

Should you ever have to debug this kind of logic, don't
base your thought process on what you're stopping from
happening or what it is you're hiding. Instead, base it on
what you're DOING and what you're SHOWING, and the
process saves many more brain cells.

Warm regards,

Doug Parker
Redondo Beach, CA

3 Sep 2013, 5:44 AM
#27
d0ugparker avatar

d0ugparker

Zen Follower

Join Date:
May 2008
Location:
Near the water, somewhere...
Posts:
129
Plugin Contributions:
0

Re: Block shipping options for certain items...?

I got great results on the shopping cart page:

Attachment 13008

but when step 1 of 3 of the checkout process
displays, it's all munged:

Attachment 13009

and when I go forward to step 2 of 3, it's totally
cool again:

Attachment 13010

It appears to be artifacts from the echo command
I used to place the red paragraphs of text on the
previous screen.

Any suggestions on what might be happening? I
tried looking at the template for checkout shipping
default, and investigated what I could do to clear
any output buffers, (ob_clean, ob_flush) but can't
wrap my head around the php there just yet.

Regards,

Doug

3 Sep 2013, 7:07 AM
#28
ajeh avatar

ajeh

Oba-san

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

Re: Block shipping options for certain items...?

The text is displayed nicely originally ... then it becomes goobered ... begegging two questions ...

1 Where have you put what to display your text that shows pretty then goes ugly?

2 IS there an URL and products_id that I can add to the cart and see this live so I can fulled see a couple things I kinda sorta would like to see/experiance/navigate through myself, based on what I am seeing in those great images as those were really helpful ... but to help you I need a little more on this one as I have "suspisions" right now of what to fix ... but I need to know just a touch more that I cannot 100% ask for as I don't 100% know what you did to make the changes, display your text, this that and the other thing based on the context of this thread and your images etc.

And as soon as I can I will try to test out and look into this further once you can provides some of this extra info that would help me to help you ...

21 Sep 2013, 6:19 PM
#29
d0ugparker avatar

d0ugparker

Zen Follower

Join Date:
May 2008
Location:
Near the water, somewhere...
Posts:
129
Plugin Contributions:
0

Re: Block shipping options for certain items...?

Ajeh:

  1. Where have you put what to display your text that shows
    pretty then goes ugly?

***The red body copy should only display on the Shopping Cart
Contents page, not on the top of the Step 1-of-3 checkout page.
Its display should not affect the Step 1-of-3 checkout page.

***The red body copy that displays nicely on the Shopping Cart
Contents image (the first help image) is an echo statement
from

/includes/modules/shipping/usps.php

which has a set of <font><strong></strong></font> tags.
Removing the <strong></strong> and <font color="red">
</font> tag sets doesn't change the munged result on the
followin page. It is inteded to display only on the Shopping
Cart Contents page, and not on the top of the Step 1-of-3
checkout page (the second help image shown). It only appears
when (not surprisingly) there are Media Mail and non-Media
Mail items in the cart.

The only place that the red, echo text exists is in the usps.php
code noted above. What's odd is that I'm not calling the
usps.php code that has that echo statement when the body
copy appears on the second image, and I'm only expecting
it to appear on the Shopping Cart Contents page and not the
Step 1-of-3 page, nor am I expecting the text size on the
Step 1-of-3 page to be displayed larger (the munging).

Can the red body copy be a page artifact from the usps.php
page that needs to be cleared from a display cache? I wouldn't
think it should be displaying on any other page, and should be
wiped from any display cache when the Step 1-of-3 page is
displayed.

Ajeh:

  1. Is there an URL and products_id that I can add to the cart
    and see this live?

w w w . c o d a . o r g SLASH e s t o r e

The products in question are categorized into Media Mail and
non-Media Mail items. Anything under

Categories > Literature

is Media Mail and is in products_id category 1. Anything under

Categories > Chips, Medallions

are non-Media Mail and are in products_id category 9. Add
one literature item and one chip or medallion and let the
munging begin.

I'm guessing I'm breaking a set of font tags somewhere....

The other observation worth noting is that the goobering
only occurs when the the red body copy is displayed and
the user clicks the Go to Checkout button.

***(I just found the subscribe switch so I'll be responding
a bit quicker now.) :-\ ***

Dr Doug

27 Sep 2013, 1:55 AM
#30
d0ugparker avatar

d0ugparker

Zen Follower

Join Date:
May 2008
Location:
Near the water, somewhere...
Posts:
129
Plugin Contributions:
0

Re: Block shipping options for certain items...?

Ajeh,

The red text is echoed in the second //bof //eof section noted in
your code change in this original thread, based on this code. I've
shortened the body copy on the red text for brevity:

if ($skip_media && $type == 'Media MailRM' && (!(sizeof($cart_vs_media_diff) == sizeof($cart_vs_donations_diff)))) { 
  if (sizeof($cart_vs_media_diff) <> 0 ) {     // display the red warning message if there is a mix of M & non-M items
    echo '<font color="red"><strong><br>The Media Mail option is...<snip>...separately from all other items. </strong></font><br><br>';
  }
//	  echo sizeof($cart_products_id_array) . ' ' . sizeof($cart_vs_media_diff) . '<br>';
continue;
}

Dr Doug

27 Sep 2013, 2:05 AM
#31
ajeh avatar

ajeh

Oba-san

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

Re: Block shipping options for certain items...?

See what happens if you add an IF around your echo of:

if ($_GET['main_page'] == 'shopping_cart') {
  echo blah blah blah
}
27 Sep 2013, 2:35 AM
#32
d0ugparker avatar

d0ugparker

Zen Follower

Join Date:
May 2008
Location:
Near the water, somewhere...
Posts:
129
Plugin Contributions:
0

Re: Block shipping options for certain items...?

Interesting.

The munged page clears up its display on the screen, but then it
goes back do displaying a Media Mail option that I still want to
hide from display.

The logic is a bit deeper than my ZC understanding, or I'd attempt
a suggestion for what to do to get both to happen!

Sorry, my mistake. I put the IF around the other IFs, not just the ECHO.
Let me try it again...

Dr Doug

27 Sep 2013, 2:41 AM
#33
d0ugparker avatar

d0ugparker

Zen Follower

Join Date:
May 2008
Location:
Near the water, somewhere...
Posts:
129
Plugin Contributions:
0

Re: Block shipping options for certain items...?

That does the trick!

Thank you, thank you, thank you!

Dr Doug

27 Sep 2013, 2:50 AM
#34
ajeh avatar

ajeh

Oba-san

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

Re: Block shipping options for certain items...?

Thanks for the update that this worked for you ... I was hoping that that would do the trick ... :smile:

9 Apr 2014, 7:22 PM
#35
d0ugparker avatar

d0ugparker

Zen Follower

Join Date:
May 2008
Location:
Near the water, somewhere...
Posts:
129
Plugin Contributions:
0

Re: Block shipping options for certain items...?

Bump to revive needed changes to my own, custom
programming due to the USPS K3 update.

Some of my custom programming is detailed starting
at post #21 of this thread. Since the USPS K3 update,
I'm refining the logic to coincide with USPS's mods,
which has broken my code for whatever reason.

I'm suspecting that the issues I'm having has to do with
the way USPS now labels its categories (Media MailRM?),
but I don't know what those changes actually are. I
reviewed the RTF file on the USPS site regarding the
changes to the categories, but it appears to have been
made only in first class categories and not anything to
do with Media Mail. :-\

The USPS API release notes for the K3 release show no
XML changes to Media Mail, so I'm not sure how I need
to proceed, nor what to be looking for for clues to how
I can solve my custom programming dilemma.

Note, I'm definitely not looking for its solution, only clues
on what to look at or to direct my attention toward so
I can move it to its happy, working conclusion. :-)

Warm regards,

9 Apr 2014, 7:30 PM
#36
ajeh avatar

ajeh

Oba-san

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

Re: Block shipping options for certain items...?

Could you Zip your last USPS shipping module that did work and inclue in the Zip what you have so far on the new USPS March 7, 2014 K3 modules?