Zen Cart Logo
Forums / All Other Contributions/Addons / Assorted Wine Crates

Assorted Wine Crates

Views: 1,762

Results 1 to 14 of 14
21 Jun 2012, 5:48 AM
#1
mr_lunch avatar

mr_lunch

New Zenner

Join Date:
Aug 2008
Posts:
9
Plugin Contributions:
0

Assorted Wine Crates

(Forgive me if there's already a thread for this contribution -- I couldn't find it with a search)

I've recently had the need to limit shipping to boxes of 6 or 12 items. Fortunately there's a contrib by georgfly for exactly this purpose. However, I did find a bug and thought I'd post a solution here for anyone else needing it. I'm currently testing it on ZC 1.5.0 -- looking good so far.

At the end of the classes/observers/class.weinkartons_amount.php file, in the case statement there is the following:

case 'NOTIFY_HEADER_START_CHECKOUT_SHIPPING':
case 'NOTIFY_HEADER_START_CHECKOUT_PAYMENT':
case 'NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION':
    if ($prodincase > 0 && $bigcase > 0) {
        if($prodincase % $bigcase != 0 && $_SESSION['cart']->count_contents() != $smallcase) {
            zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
        }
    }

However, at this stage of the switch $prodincase hasn't been declared, so checkout pages were not redirecting if there was a conflict. I've replaced the above with this:

case 'NOTIFY_HEADER_START_CHECKOUT_SHIPPING':
case 'NOTIFY_HEADER_START_CHECKOUT_PAYMENT':
case 'NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION':
    if($_SESSION['cart']->count_contents() % $bigcase !=0 && $_SESSION['cart']->count_contents() % $smallcase !=0){
        zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
    }

A big thanks to georgfly for providing the contrib in the first place.

21 Jun 2012, 7:06 AM
#2
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Assorted Wine Crates

Could you point me to the download of this add-on pls...

I wrote my own module for wine boxes some years ago (but it was clunky) and would like to see this one.

20 years a Zencart User

21 Jun 2012, 7:14 AM
#3
mr_lunch avatar

mr_lunch

New Zenner

Join Date:
Aug 2008
Posts:
9
Plugin Contributions:
0

Re: Assorted Wine Crates

Current download location is http://www.zen-cart.com/downloads.php?do=file&id=1309 listed under the Product Types category.

I think I just found another bug. Around line 62 of the original file is:

        if ($prodincase > 0 && $bigcase > 0) {
          if($prodincase % $bigcase != 0 && $prodincase != $smallcase) {
            $_SESSION['valid_to_checkout'] = false;
            $messageStack->add('shopping_cart', sprintf(TEXT_ORDER_UNDER_MIN_AMOUNT, $bigcase, $smallcase) . '<br />', 'caution');
          }
        }

Which I've changed to:

        $morethanbigcase = $prodincase % $bigcase;
        if ($prodincase > 0 && $bigcase > 0) {
          if($morethanbigcase != 0 && $morethanbigcase != $smallcase) {
            $_SESSION['valid_to_checkout'] = false;
            $messageStack->add('shopping_cart', sprintf(TEXT_ORDER_UNDER_MIN_AMOUNT, $bigcase, $smallcase) . '<br />', 'caution');
          }
        }
21 Jun 2012, 7:54 AM
#4
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Assorted Wine Crates

Thanks a ton for the heads-up, and for your revisions. Much appreciated...

20 years a Zencart User

24 Jul 2012, 2:27 AM
#5
georgfly avatar

georgfly

New Zenner

Join Date:
Apr 2011
Posts:
10
Plugin Contributions:
0

Re: Assorted Wine Crates

Thanks for your bug-fixes. The first one must indeed be a bug (i have modified this code slightly before i used it in my own shop, and 'accidently' gotten rid of it without ever realizing it...).
For the second one, I guess it depends on what you need. My intention was to either allow customer to purchase a single case with 6 bottles, OR only multiples of 12 (I would not allow to purchase one case of 12 and one case of 6 in the same order). I havent tested it, but I seems you also want to allow mixed orders (multiples of 12 AND a single case of 6). Anyway, thanks for the fixes.

24 Jul 2012, 6:33 AM
#6
mr_lunch avatar

mr_lunch

New Zenner

Join Date:
Aug 2008
Posts:
9
Plugin Contributions:
0

Re: Assorted Wine Crates

No worries. Actually I found another bug, but was too busy to post a fix. From memory it was that the code after:

      case 'NOTIFY_HEADER_START_CHECKOUT_SHIPPING':
      case 'NOTIFY_HEADER_START_CHECKOUT_PAYMENT':
      case 'NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION':

...wasn't taking into consideration that there might be non-wine category items in the cart. Basically, we have to count everything again. So I've incorporated the following (from around line 69 in the original file):

      case 'NOTIFY_HEADER_START_CHECKOUT_SHIPPING':
      case 'NOTIFY_HEADER_START_CHECKOUT_PAYMENT':
      case 'NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION':
      // COUNT ALL WINE-CASE ITEMS IN CART
      $prodincase = 0;
      $mycart = $_SESSION['cart'];
      $myprodids = $mycart->get_product_id_list();
      $myprodids = explode(', ', $myprodids);
      foreach($myprodids as $myprodid) {
        $myprodpaths = zen_get_product_path($myprodid);
        $myprodpaths = explode('_', $myprodpaths);
        $iswine = false;
        foreach($myprodpaths as $myprodpath){
          foreach($winecats as $winecat){
            if ($winecat == $myprodpath){
              $iswine = true;
            }
          }
        }
      	if ($iswine){
          $prodincase = $prodincase + $mycart->get_quantity($myprodid);
      	}
      }

		$morethanbigcase = $prodincase % $bigcase;
      	
        if ($prodincase > 0 && $bigcase > 0) {
          if($morethanbigcase != 0 && $morethanbigcase != $smallcase) {
			zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
          }
        }
        break;
      default:
        break;
    }
  }
}
?>
15 Mar 2013, 2:31 AM
#7
deel avatar

deel

New Zenner

Join Date:
Jan 2013
Location:
Eustis, Florida, United States
Posts:
84
Plugin Contributions:
0

Re: Assorted Wine Crates

Does anyone know where I can download this for 1.5? I tried installing the version here http://www.zen-cart.com/downloads.php?do=file&id=1309 but when I tried to login I got a white screen so just reverted. Oh, maybe the fixes above will help? Appreciate your input and I will try the above things.

I am also looking to use it for a pack with either 10, 18, 20, 26 or 28 items. Could someone point me as to what I would need to amend and where to have this mod work do this?

15 Mar 2013, 4:13 AM
#8
mr_lunch avatar

mr_lunch

New Zenner

Join Date:
Aug 2008
Posts:
9
Plugin Contributions:
0

Re: Assorted Wine Crates

It's been months since I looked at this, but you'd want to look for anywhere $bigcase and $smallcase is mentioned in the observer class. Probably worth replacing those with an array for your needs.

16 Mar 2013, 2:27 AM
#9
deel avatar

deel

New Zenner

Join Date:
Jan 2013
Location:
Eustis, Florida, United States
Posts:
84
Plugin Contributions:
0

Re: Assorted Wine Crates

Sorry, this is relatively new to me so what would I need to enter to define an array? The pack sizes I need are 10, 18, 20, 26 and 28. Do you know if it is possible to set a price for each of those pack sizes?

23 Mar 2013, 3:22 AM
#10
deel avatar

deel

New Zenner

Join Date:
Jan 2013
Location:
Eustis, Florida, United States
Posts:
84
Plugin Contributions:
0

Re: Assorted Wine Crates

How do I define an array?

31 Mar 2013, 11:30 PM
#11
mr_lunch avatar

mr_lunch

New Zenner

Join Date:
Aug 2008
Posts:
9
Plugin Contributions:
0

Re: Assorted Wine Crates

Info on how to create an array is in the PHP docs:

http://www.php.net/manual/en/function.array.php

You might choose to follow the code above and add a long list of box sizes instead of stepping through an array. Up to you :)

12 Jun 2013, 5:32 PM
#12
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Assorted Wine Crates

Question regarding this add-on.. Can this add-on be used to create custom cases of products that can ONLY be purchased as part of a special custom case. In other words the products in the specified categories for this add-on cannot otherwise be purchased individually and are only available as options for these special packages (cases).

Not clear if this is part of the module's current codebase or if a modification is needed to add this kind of functionality..

What would really answer my question is to see this add-on in action..

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

13 Jun 2013, 12:40 AM
#13
mr_lunch avatar

mr_lunch

New Zenner

Join Date:
Aug 2008
Posts:
9
Plugin Contributions:
0

Re: Assorted Wine Crates

The module has a list of categories which will have the case requirement imposed on them. Any products in those categories must be in an appropriate quantity to fit in one of the defined case sizes. I haven't tried it, but I imagine that there would be no issue with linking the products to a different category, freeing them from the constraint. Your best bet is probably to test it in a development environment first.

13 Jun 2013, 1:29 AM
#14
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Assorted Wine Crates

mr_lunch:

The module has a list of categories which will have the case requirement imposed on them. Any products in those categories must be in an appropriate quantity to fit in one of the defined case sizes. I haven't tried it, but I imagine that there would be no issue with linking the products to a different category, freeing them from the constraint. Your best bet is probably to test it in a development environment first.

I actually don't want to free them from the constraint.. I just want to make sure that the products with the case requirement CANNOT be purchased individually.. In other words the ONLY way to purchase the products with the case requirement is for them to be part of a case (bundled) product..

From what you have just posted it sounds like this is exactly how this add-on works.. I won't be using it for wine but for products which are created from other products and I want to make sure these products can only be purchased as part of this bundled product.. (in this case it's jewelry - charm bracelets) The reason I don't want to use attributes is that each of these product components has specific descriptions and may have attributes of it's own (ie: heart charm with a choice of metals and stones).. Using this add-on will allow for all of that..

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.