Site maintenance: Sun 15 Nov, from 20:00 UTC, about 4–6 hours. Details

This cutover relies on some testing that is still incomplete so may be cancelled at short notice

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

Started by gaffettape on 5 Jan 2013, 11:30 PM · Views: 774

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 ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

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 ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!