Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2012
    Posts
    9
    Plugin Contributions
    0

    Default disallow certain product combinations (in cart)

    Hi,

    I want to block certain product from being added to cart (based on existing cart's content). So, I thought I'll do this via an observer, that when triggered, looks at the cart's content and marks it as invalid for checkout. However... it doesn't seem to be working. Any thoughts about what I'm doing wrong?

    My code is similar to (in this case I want to see an error when adding product id 1 IF there are other products in cart already):

    class order_restrict extends base
    {
    function __construct() {
    global $zco_notifier;

    $zco_notifier->attach($this, array('NOTIFIER_CART_ADD_CART_END'));
    }


    function update(&$class, $eventID, $paramsArray = array())
    {
    global $messageStack;

    switch ($eventID)
    {
    case 'NOTIFIER_CART_ADD_CART_END':
    $cart = $_SESSION['cart'];
    $product1_id = zen_get_uprid(1, '');
    $products = $cart->get_products();

    if (sizeof($products)>1 && $cart->in_cart($product1_id) )
    {
    $_SESSION['valid_to_checkout'] = false;
    $messageStack->add('shopping_cart', TEXT_CANT_ADD_THIS, 'error');
    $_SESSION['cart_errors'] .= TEXT_CANT_ADD_THIS. '<br />';
    }
    break;

    default:
    break;
    }
    }
    }


    thanks!

  2. #2
    Join Date
    Oct 2012
    Posts
    9
    Plugin Contributions
    0

    Default Re: disallow certain product combinations (in cart)

    My code works fine, the problem is that NOTIFIER_CART_ADD_CART_END is not received when adding an item to the cart (via actionBuyNow). Why?

  3. #3
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: disallow certain product combinations (in cart)

    1. $zco_notifier->attach() should be $this->attach() since you're using a notifier hook that exists inside a class.

    2. Your auto_loader entry point needs to be something greater than like 190 or so. I usually suggest people use 200 or greater, but 190 works too.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  4. #4
    Join Date
    Oct 2012
    Posts
    9
    Plugin Contributions
    0

    Default Re: disallow certain product combinations (in cart)

    Yes, I used 190 and, before posting, I tried $this->attach($this, array('NOTIFIER_CART_ADD_CART_END')), too. Either way I don't get that notification. I subscribed to pretty much all of them. While I did add products, all I got was:

    Got event: NOTIFIER_CART_GET_PRODUCTS_START
    Got event: NOTIFIER_CART_GET_PRODUCTS_END
    Got event: NOTIFIER_CART_COUNT_CONTENTS_START
    Got event: NOTIFIER_CART_GET_QUANTITY_START
    Got event: NOTIFIER_CART_GET_QUANTITY_END_QTY
    Got event: NOTIFIER_CART_GET_QUANTITY_START
    Got event: NOTIFIER_CART_GET_QUANTITY_END_QTY
    Got event: NOTIFIER_CART_COUNT_CONTENTS_END
    Got event: NOTIFIER_CART_SHOW_TOTAL_START
    Got event: NOTIFIER_CART_SHOW_TOTAL_END
    Got event: NOTIFIER_CART_GET_PRODUCTS_START
    Got event: NOTIFIER_CART_GET_PRODUCTS_END
    Got event: NOTIFIER_CART_COUNT_CONTENTS_START
    Got event: NOTIFIER_CART_GET_QUANTITY_START
    Got event: NOTIFIER_CART_GET_QUANTITY_END_QTY
    Got event: NOTIFIER_CART_GET_QUANTITY_START
    Got event: NOTIFIER_CART_GET_QUANTITY_END_QTY
    Got event: NOTIFIER_CART_COUNT_CONTENTS_END
    Got event: NOTIFIER_CART_COUNT_CONTENTS_START
    Got event: NOTIFIER_CART_GET_QUANTITY_START
    Got event: NOTIFIER_CART_GET_QUANTITY_END_QTY
    Got event: NOTIFIER_CART_GET_QUANTITY_START
    Got event: NOTIFIER_CART_GET_QUANTITY_END_QTY
    Got event: NOTIFIER_CART_COUNT_CONTENTS_END
    Got event: NOTIFIER_CART_COUNT_CONTENTS_START
    Got event: NOTIFIER_CART_GET_QUANTITY_START
    Got event: NOTIFIER_CART_GET_QUANTITY_END_QTY
    Got event: NOTIFIER_CART_GET_QUANTITY_START
    Got event: NOTIFIER_CART_GET_QUANTITY_END_QTY
    Got event: NOTIFIER_CART_COUNT_CONTENTS_END
    Got event: NOTIFIER_CART_COUNT_CONTENTS_START
    Got event: NOTIFIER_CART_GET_QUANTITY_START
    Got event: NOTIFIER_CART_GET_QUANTITY_END_QTY
    Got event: NOTIFIER_CART_GET_QUANTITY_START
    Got event: NOTIFIER_CART_GET_QUANTITY_END_QTY
    Got event: NOTIFIER_CART_COUNT_CONTENTS_END

    Anyway, using NOTIFIER_CART_COUNT_CONTENTS_END is sufficient for my workflow. But why am I not getting NOTIFIER_CART_ADD_CART_ is odd...

 

 

Similar Threads

  1. v150 Ceon shipping module: remove shipping options for certain product combinations?
    By irish_1985 in forum Addon Shipping Modules
    Replies: 2
    Last Post: 28 Oct 2012, 02:18 AM
  2. Any way to lock out certain combinations in Attributes?
    By bozeman1941 in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 17 Oct 2011, 06:33 PM
  3. addon product attributes combinations
    By dennykb-d in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 10 Dec 2010, 12:05 AM
  4. Disallow delivery of a certain item to international destinations.
    By rpain in forum Built-in Shipping and Payment Modules
    Replies: 0
    Last Post: 30 Jun 2009, 06:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR