Zen Cart Logo
Forums / General Questions / "Display Cart After Adding Product" - Only if Stock is Less than 1

"Display Cart After Adding Product" - Only if Stock is Less than 1

Views: 768

Results 1 to 4 of 4
5 Jan 2013, 11:30 PM
#1
gaffettape avatar

gaffettape

Zen Follower

Join Date:
May 2009
Posts:
433
Plugin Contributions:
0

"Display Cart After Adding Product" - Only if Stock is Less than 1

Hi,

In my ZC admin I have "Allow customer to checkout even if there is insufficient stock" set to true, and "Show Sold Out Image instead of Add to Cart Button" set to false. With this configuration customers can checkout even is there is insufficient stock, with their order being placed on backorder and shipped when available.

As far as I can tell, the only time a customer would be actively informed about stock level/backordering is on the shopping_cart page via the "Products marked with *** are out of stock. Items not in stock will be placed on backorder." message. This is where the necessity to display the shopping_cart page ONLY when the stock level is less than 1 comes in...

Desired results:

Customers who add a product that is in stock to their cart, stay on the product_info page, with the "Successfully added Product to the cart ..." message shown (this is what currently already happens).

Customers who add a product that is out of stock to their cart are forwarded to the shopping_cart page immediately after adding an out of stock product.

Is this possible? If so, how?

Thanks :smile:

6 Jan 2013, 6:44 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: "Display Cart After Adding Product" - Only if Stock is Less than 1

You can try this ...

Edit the file:
/includes/init_includes/init_cart_handler.php

and add the code in RED:

  if ($session_started == false) {
    zen_redirect(zen_href_link(FILENAME_COOKIE_USAGE));
  }

[B]// bof: check to override DISPLAY_CART false
  $chk_products = $_POST['products_id'];
  $show_cart = false;
  if (is_array($chk_products)) {
    foreach ($chk_products as $key => $value) {
      if ((zen_get_products_stock($key) - ($value + $_SESSION['cart']->in_cart_mixed($key))) < 0) {
        $show_cart = true;
        break;
      }
    }
  } else {
    if (zen_get_products_stock($chk_products) <= 0) {
      $show_cart = true;
    }
  }
[/B]
  if (DISPLAY_CART == 'true' [B]|| $show_cart[/B]) {
[B]// eof: check to override DISPLAY_CART false
[/B]    $goto =  FILENAME_SHOPPING_CART;

see if that accomplishes what you are after ...

6 Jan 2013, 7:21 PM
#3
gaffettape avatar

gaffettape

Zen Follower

Join Date:
May 2009
Posts:
433
Plugin Contributions:
0

Re: "Display Cart After Adding Product" - Only if Stock is Less than 1

Perfect!

Thank you so much, Linda :smile:

Edit: I noticed that there's an /overrides/ folder in /init_includes/ - should I stick the new edited file in there?

6 Jan 2013, 7:40 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: "Display Cart After Adding Product" - Only if Stock is Less than 1

Yes, you can use the /overrides directory ...