Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Posts
    474
    Plugin Contributions
    2

    Default Restrict Products in Cart Based on Other Products in Cart

    Need some help setting up code so that if Product A,B,or C are added to the cart, the site doesn't allow other products to be added, restricts checkout, and a note indicates the problem.

    I thought it might be doable with some modifications to Dr.Byte's code seen here:
    http://www.zen-cart.com/showthread.p...t=subscription
    by implementing steps 1 and 2, yet so far I have been unsuccessful. Might that post be missing something?

    I am currently using Fast and Easy Ajax Checkout so that throws a loop in the mix. But I would think my restriction should be kicking in before the checkout process is even allowed to begin.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,872
    Plugin Contributions
    96

    Default Re: Restrict Products in Cart Based on Other Products in Cart

    What if something's already in the cart when a customer tries to add A, B or C?

  3. #3
    Join Date
    Jun 2007
    Posts
    474
    Plugin Contributions
    2

    Default Re: Restrict Products in Cart Based on Other Products in Cart

    Same thing. In my head it would operate similar to the out of stock process.

    If Product A is in the cart or added to the cart and Product Z gets added, a note pops up on the shopping cart page saying, "These products need to be ordered separately."

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,872
    Plugin Contributions
    96

    Default Re: Restrict Products in Cart Based on Other Products in Cart

    Put the following code into /includes/extra_cart_actions/one_per_cart.php; you'll need to edit the ONE_PER_CART_PRODUCT_IDS value to reflect the product_ids of your restricted items:
    Code:
    <?php
    /**
     * Extra shopping Cart actions supported.
     *
     * The main cart actions supported by the current shoppingCart class.
     *
     * NOTE: Many of the defines used in this module have been included by
     * class.init_quote.php's inclusion of /includes/quotes_status_array.php.
     *
     */
    define('ONE_PER_CART_PRODUCT_IDS', '14,4,6,11,15'); /*Identify the product_ids of the products that must be ordered separately*/
    define('ERROR_ONE_PER_CART', 'Sorry, but you can\'t add "%s" to an order that already contains another item.');
    define('ERROR_ONE_PER_CART_COMBINE', 'Sorry, but you can\'t add another item to an order that already contains "%s".');
    
    switch ($_GET['action']) {
      case 'add_product': 
        $onePerCartIDs = explode (',', ONE_PER_CART_PRODUCT_IDS);
        $inCartName = '';
        foreach ($onePerCartIDs as $theID) {
          if ($theID == $_POST['products_id']) {
            if ($_SESSION['cart']->count_contents() > 0) {
              $error = true;
              $messageStack->add('product_info', sprintf(ERROR_ONE_PER_CART, zen_get_products_name((int)$_POST['products_id'])));
            }
          } elseif ($_SESSION['cart']->in_cart_mixed($theID) != 0) {
            $inCartName = zen_get_products_name($theID);
          }
        }
        if (!$error && $inCartName != '') {
          $error = true;
          $messageStack->add('product_info', sprintf(ERROR_ONE_PER_CART_COMBINE, $inCartName));
        }
      }
    
      if ($error) {
        unset($_GET['action']);
      }
      break;
    }

  5. #5
    Join Date
    Jun 2007
    Posts
    474
    Plugin Contributions
    2

    Default Re: Restrict Products in Cart Based on Other Products in Cart

    I failed to mention I'm using v1.3.9h

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,872
    Plugin Contributions
    96

    Default Re: Restrict Products in Cart Based on Other Products in Cart

    The code I posted should work for Zen Cart 1.3.9 and 1.5.x ...

 

 

Similar Threads

  1. v139h Updating amounts in cart resets other products in cart?
    By jgold723 in forum General Questions
    Replies: 0
    Last Post: 3 Oct 2012, 03:06 PM
  2. I would like to restrict cart image to products with no attributes
    By member in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 30 Aug 2011, 06:37 AM
  3. Restrict Products based on Country
    By ultra_mao in forum Setting Up Categories, Products, Attributes
    Replies: 14
    Last Post: 19 Jun 2010, 11:01 PM
  4. How can I restrict shipping choices based on kinds of products in the cart?
    By bladerogers in forum Templates, Stylesheets, Page Layout
    Replies: 8
    Last Post: 14 Sep 2009, 03:51 AM

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