Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help! Customers Exceeding Stock Qty By Changing Options!


bwbass

Recommended Posts

We have a lot of one-of-a-kind products in our store (all stock qty = 1), but we've had a few customers manage to place orders which exceed this quantity by adding the same product multiple times with different options selected.

 

Example:

If we only have one widget X to sell, which can be painted red or blue, osCommerce will allow you to buy two widget X's on the same order: one painted red and one painted blue!

 

This only applies to items on a single order - if you check out with 1 widget X painted red and then returned to the store, you'd be unable to buy another one in either color, because it's stock is now 0, which is correct.

 

How can I prevent this? Help!

Link to comment
Share on other sites

I am not fully conversant with the stock options on osCommerce, although I do see your problem.

 

I think what you need to do is make it so that the stock decreases the moment someone pops the item in your basket and would also increase the stock if they remove it or the session ends (i.e. they leave of which you would have to nullify anything in their cart).

 

Have to admit though that this is not something I have had to do for any of my clients so the coding is not something I can immediately assist with. I am sure making it decrease is quite easy but its making it add it back if they do not purchase that will be the tough one.

 

I am sure someone on here more conversant in the stock keeping option on osCommerce will be able to go futher that I currently can.

My Toolbox: Crimson Editor, Adobe Photoshop CS2.0, Expression Web, Macromedia Suite 8.0, Cinema 4D, Nvu.

Link to comment
Share on other sites

Thanks, Steve!

 

I don't really mind the way osC handles stock most of the time, and for what we do having stock qty remain 1 until the item is paid for is a good thing, so I wouldn't want to change that. What I'd like to do is add a validation routine to check for this in shopping_cart.php

 

I was thinking of storing the cart's product id's and qty's in an array, checking as you added each one to see if the same ID was already in the array and if the combined cart qty exceeded the stock qty for that product. However php is not my best language and I'm not exactly sure how to code this.

Link to comment
Share on other sites

Thats a more feasible solution to be honest. If I get chance later tonight I'll run that idea on my test environment and see if I can get it working. Its possibly something that others may want too and would more than likely just be a code change on the shopping_cart.php.

 

I would think its likely to be an if else statement that prompts an error message if the same product is added twice to the shopping cart.

My Toolbox: Crimson Editor, Adobe Photoshop CS2.0, Expression Web, Macromedia Suite 8.0, Cinema 4D, Nvu.

Link to comment
Share on other sites

Ok, I fixed it myself. It's a pretty narrow fix, mind you (it only checks for multiple option configurations of items with a stock qty of 1 on the same order), but it works for us. Hopefully someone else may find it useful:

 

In shopping_cart.php:

At the top, find:

  require("includes/application_top.php");

 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SHOPPING_CART);

Just below it, add:

  $checkout_ok=true;

Find:

  <?php
// minimum order total
   if ($cart->show_total() > MAX_ORDER_AMOUNT) {
     $checkout_ok = false;
?>
     <tr>
       <td class="ShippingWarning" align="center"><br><b><?php echo sprintf(TEXT_ORDER_OVER_MAX_AMOUNT, $currencies->format(MAX_ORDER_AMOUNT)); ?></b></td>
     </tr>
<?php
   }
?>

Just below it, add:

<?php
   $stock_array = array();
   for ($i=0, $n=sizeof($products); $i<$n; $i++) {
     if (in_array(tep_get_prid($products[$i]['id']),$stock_array)) {
       if(tep_get_products_stock($products[$i]['id'])<2) {
       $checkout_ok = false;
       echo "<tr><td class=\"ShippingWarning\" align=\"center\"><br><b>There is only one ".tep_get_products_name($products[$i]['id'])." available for sale.<br/>Please remove duplicates from your cart before proceeding.</td></tr>";
     }
     };
     $stock_array[$i] = tep_get_prid($products[$i]['id']);
   };
?>

Then find:

                  <?php echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . tep_image_button('button_checkout.gif', IMAGE_BUTTON_CHECKOUT) . '</a>';

And replace it with:

                  <?php
                 if ($checkout_ok) {
                   echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . tep_image_button('button_checkout.gif', IMAGE_BUTTON_CHECKOUT) . '</a>';
                   };
                   ?>

 

The above code should check for duplicates of the same item whose stock quantity is 1 but whose options are different. If it finds one, it displays a warning at the bottom of the page and hides the checkout button.

 

However, you can still click on the checkout link at the top right and "purchase" the nonexistant items. To prevent this, you need to modify checkout_shipping.php as well...

 

In checkout_shipping.php:

 

At the top, find:

  require('includes/application_top.php');
 require('includes/classes/http_client.php');

Just below that, add:

  $products = $cart->get_products();
 $checkout_ok = true;
 $stock_array = array();
   for ($i=0, $n=sizeof($products); $i<$n; $i++) {
     if (in_array(tep_get_prid($products[$i]['id']),$stock_array)) {
       if(tep_get_products_stock($products[$i]['id'])<2) {
       $checkout_ok = false;
       }
     };
     $stock_array[$i] = tep_get_prid($products[$i]['id']);
     if (STOCK_CHECK == 'true') {
       $stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
       if (tep_not_null($stock_check)) {
         $checkout_ok = false;
       }
     }
   };

   if(!$checkout_ok) {
   tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
 }

As with all mods, back up everything first, test on a local box first if possible, proceed at your own risk, your mileage may vary, etc.

 

Enjoy!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...