Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Back Ordering / Out of Stock mod completed

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 12-02-2005, 06:44 PM
 
Smalls Smalls is offline
 

Advanced Member
  
Join Date: Apr 2004
Location: Ontario
Posts: 30
 

Default Back Ordering / Out of Stock mod completed

Ok, this is real rough, but it gets the job done. This mod allows you to order items that you have 0 stock of, to allow people to back-order your products.

This is pretty untested, but it works good so far from my testing of ordering and deleting products a few times.

Like i said, its really rough, because if the person orders 5 of one type product that IS in stock, then goes back and adds 5 more to the order, the checkout window will just say 10 items, it won't differentiate between there being 5 in stock and 5 not that will be back ordered.

I'd also like to give credit to Mike Everland, from this thread:
http://forum.x-cart.com/viewtopic.php?t=109&postdays=0&postorder=asc&highl ight=stock&start=0

I basically took what he had and modified it a bit, specifically to make it work with 4.0.17.

This is for X-Cart 4.0.17... if it works for other versions, I have no clue.

Enjoy and please DO improve upon this, x-cart needs a better back ordering system!!!!!!!
Ryan Lucier

To see it in action, check out: http://www.outbreaksportz.com

================================
xcart/cart.php
================================
BEFORE (line 249):
#
# Add to cart amount of items that is not much than in stock
#
if ($config["General"]["unlimited_products"]=="N" && $added_product["product_type"]!="C")
if ($amount > $added_product["avail"])
$amount = $added_product["avail"];

AFTER (comment out the following lines):
#
# Add to cart amount of items that is not much than in stock
#
#if ($config["General"]["unlimited_products"]=="N" && $added_product["product_type"]!="C")
#if ($amount > $added_product["avail"])
#$amount = $added_product["avail"];

BEFORE (line 427):
$amount_max = $hash[$cart["products"][$productindex]['variantid']]['avail'];

AFTER:
$amount_max = 50; #THIS IS THE MAX AMOUNT THAT A CUSTOMER CAN BACK-ORDER

BEFORE (line 430):
$amount_max=func_query_first_cell("select avail from $sql_tbl[products] where productid='$productid'");

$amount_max=50; #THIS IS THE MAX AMOUNT THAT A CUSTOMER CAN BACK-ORDER, MUST CHANGE THE PREVIOUS AMOUNT MAX AS WELL


================================
xcart/include/func.php
================================
BEFORE (line 2435):
$products_array = func_query_first("select $sql_tbl[products].*, min($sql_tbl[pricing].price) as price from $sql_tbl[products], $sql_tbl[pricing] where $sql_tbl[pricing].productid=$sql_tbl[products].productid and $sql_tbl[products].productid='$productid' and $avail_condition $sql_tbl[pricing].quantity<=$amount and ($sql_tbl[pricing].membership='".addslashes($membership)."' or $sql_tbl[pricing].membership='') AND $sql_tbl[pricing].variantid = 0 group by $sql_tbl[products].productid order by $sql_tbl[pricing].quantity desc");

AFTER:
$products_array = func_query_first("select $sql_tbl[products].*, min($sql_tbl[pricing].price) as price from $sql_tbl[products], $sql_tbl[pricing] where $sql_tbl[pricing].productid=$sql_tbl[products].productid and $sql_tbl[products].productid='$productid' and $sql_tbl[pricing].quantity<=$amount and ($sql_tbl[pricing].membership='".addslashes($membership)."' or $sql_tbl[pricing].membership='') AND $sql_tbl[pricing].variantid = 0 group by $sql_tbl[products].productid order by $sql_tbl[pricing].quantity desc");


================================
xcart/skin1/customer/main/product.tpl
================================
BEFORE: (line 60)
{if $active_modules.Product_Options ne ""}
{ include file="modules/Product_Options/customer_options.tpl"}
{/if}
<TR><TD height="25" width="30%">{$lng.lbl_quantity}{if $product.min_amount gt 1}
<FONT class="ProductDetailsTitle">{$lng.txt_need_min_amo unt} {$product.min_amount} {$lng.lbl_items}</FONT>{/if}</TD>
<TD>
{if $config.General.unlimited_products eq "N" and ($product.avail le 0 or $product.avail lt $product.min_amount) and $variants eq ''}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var min_avail = 1;
var avail = 0;
var product_avail = 0;
</SCRIPT>
{$lng.txt_out_of_stock}
{else}
{if $config.General.unlimited_products eq "Y"}
{math equation="x+1" assign="mq" x=$config.Appearance.max_select_quantity}
{else}
{math equation="x/y" x=$config.Appearance.max_select_quantity y=$product.min_amount assign="tmp"}
{if $tmp<2}
{assign var="minamount" value=$product.min_amount}
{else}
{assign var="minamount" value=1}
{/if}
{math equation="min(maxquantity+minamount, productquantity+1)" assign="mq" maxquantity=$config.Appearance.max_select_quantity minamount=$minamount productquantity=$product.avail}
{/if}
{if $product.distribution eq ""}
{if $product.min_amount le 1}
{assign var="start_quantity" value=1}
{else}
{assign var="start_quantity" value=$product.min_amount}
{/if}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var min_avail = {$start_quantity|default:1};
var avail = {$mq|default:1}-1;
var product_avail = {$product.avail|default:"0"};
</SCRIPT>
<SELECT id="product_avail" name="amount"{if $active_modules.Product_Options ne '' && $product_options ne ''} onchange="check_wholesale(this.value);"{/if}>
{section name=quantity loop=$mq start=$start_quantity}
<OPTION value="{%quantity.index%}" {if $smarty.get.quantity eq %quantity.index%}selected{/if}>{%quantity.index%}</OPTION>
{/section}
</SELECT>
{else}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var min_avail = 1;
var avail = 1;
var product_avail = 1;
</SCRIPT>
<FONT class="ProductDetailsTitle">1</FONT><INPUT type="hidden" name="amount" value="1"> {$lng.txt_product_downloadable}
{/if}
{/if}
</TD></TR>
<TR><TD colspan="2">
<INPUT type="hidden" name="mode" value="add">
{if $variants eq ''}
{include file="customer/main/product_prices.tpl"}
{/if}
{if $config.General.unlimited_products eq "Y" or ($product.avail gt 0 and $product.avail ge $product.min_amount)}
{if $js_enabled}


{if $smarty.get.pconf ne ""}
<INPUT type="hidden" name="slot" value="{$smarty.get.slot}">
<INPUT type="hidden" name="addproductid" value="{$product.productid}">
{include file="buttons/button.tpl" button_title=$lng.lbl_pconf_add_to_configuration style="button" href="javascript:if (FormValidation()) `$ldelim`document.orderform.productid.value='`$sma rty.get.pconf`';document.orderform.action='pconf.p hp';document.orderform.submit()`$rdelim`"}



{/if}
{if $product.forsale ne "B"}
{include file="buttons/add_to_cart.tpl" style="button" href="javascript: if(FormValidation()) document.orderform.submit();"}

{if $login ne "" and $active_modules.Wishlist ne ""}
{include file="customer/add2wl.tpl"}
{/if}
{else}
{$lng.txt_pconf_product_is_bundled}
{/if}
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_add_to_cart}
{/if}
{/if}
{if $active_modules.Feature_Comparison ne ""}
{include file="modules/Feature_Comparison/product_buttons.tpl"}
{/if}



</TD>
</TR></TABLE>
</TD>

AFTER:
{if $active_modules.Product_Options ne ""}
{ include file="modules/Product_Options/customer_options.tpl"}
{/if}
<TR><TD height="25" width="30%">{$lng.lbl_quantity}{if $product.min_amount gt 1}
<FONT class="ProductDetailsTitle">{$lng.txt_need_min_amo unt} {$product.min_amount} {$lng.lbl_items}</FONT>{/if}</TD>
<TD>

{if $config.General.unlimited_products eq "N" and ($product.avail le 0 or $product.avail lt $product.min_amount) and $variants eq ''}
{if $config.General.unlimited_products eq "Y"}
{math equation="x+1" assign="mq" x=$config.Appearance.max_select_quantity}
{else}
{math equation="x/y" x=$config.Appearance.max_select_quantity y=$product.min_amount assign="tmp"}
{if $tmp<2}
{assign var="minamount" value=$product.min_amount}
{else}
{assign var="minamount" value=1}
{/if}
{assign var="mq" value=50}
{/if}
{if $product.min_amount le 1}
{assign var="start_quantity" value=1}
{else}
{assign var="start_quantity" value=$product.min_amount}
{/if}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var min_avail = {$start_quantity|default:1};
var avail = {$mq|default:1}-1;
var product_avail = {$product.avail|default:"0"};
</SCRIPT>
<SELECT id="product_avail" name="amount"{if $active_modules.Product_Options ne '' && $product_options ne ''} onchange="check_wholesale(this.value);"{/if}>
{section name=quantity loop=$mq start=$start_quantity}
<OPTION value="{%quantity.index%}" {if $smarty.get.quantity eq %quantity.index%}selected{/if}>{%quantity.index%}</OPTION>
{/section}
</SELECT>

</TD></TR>
<TR><TD colspan="2">
<INPUT type="hidden" name="mode" value="add">
{if $variants eq ''}
{include file="customer/main/product_prices.tpl"}
{/if}
{if $js_enabled}


{if $smarty.get.pconf ne ""}
<INPUT type="hidden" name="slot" value="{$smarty.get.slot}">
<INPUT type="hidden" name="addproductid" value="{$product.productid}">
{include file="buttons/button.tpl" button_title=$lng.lbl_pconf_add_to_configuration style="button" href="javascript:if (FormValidation()) `$ldelim`document.orderform.productid.value='`$sma rty.get.pconf`';document.orderform.action='pconf.p hp';document.orderform.submit()`$rdelim`"}



{/if}
{if $product.forsale ne "B"}
{include file="buttons/add_to_cart.tpl" style="button" href="javascript: if(FormValidation()) document.orderform.submit();"}

{if $login ne "" and $active_modules.Wishlist ne ""}
{include file="customer/add2wl.tpl"}
{/if}
{else}
{$lng.txt_pconf_product_is_bundled}
{/if}
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_add_to_cart}
{/if}
{if $active_modules.Feature_Comparison ne ""}
{include file="modules/Feature_Comparison/product_buttons.tpl"}
{/if}
{else}
{if $config.General.unlimited_products eq "Y"}
{math equation="x+1" assign="mq" x=$config.Appearance.max_select_quantity}
{else}
{math equation="x/y" x=$config.Appearance.max_select_quantity y=$product.min_amount assign="tmp"}
{if $tmp<2}
{assign var="minamount" value=$product.min_amount}
{else}
{assign var="minamount" value=1}
{/if}
{math equation="min(maxquantity+minamount, productquantity+1)" assign="mq" maxquantity=$config.Appearance.max_select_quantity minamount=$minamount productquantity=$product.avail}
{/if}
{if $product.distribution eq ""}
{if $product.min_amount le 1}
{assign var="start_quantity" value=1}
{else}
{assign var="start_quantity" value=$product.min_amount}
{/if}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var min_avail = {$start_quantity|default:1};
var avail = {$mq|default:1}-1;
var product_avail = {$product.avail|default:"0"};
</SCRIPT>
<SELECT id="product_avail" name="amount"{if $active_modules.Product_Options ne '' && $product_options ne ''} onchange="check_wholesale(this.value);"{/if}>
{section name=quantity loop=$mq start=$start_quantity}
<OPTION value="{%quantity.index%}" {if $smarty.get.quantity eq %quantity.index%}selected{/if}>{%quantity.index%}</OPTION>
{/section}
</SELECT>
{else}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
var min_avail = 1;
var avail = 1;
var product_avail = 1;
</SCRIPT>
<FONT class="ProductDetailsTitle">1</FONT><INPUT type="hidden" name="amount" value="1"> {$lng.txt_product_downloadable}
{/if}
</TD></TR>
<TR><TD colspan="2">
<INPUT type="hidden" name="mode" value="add">
{if $variants eq ''}
{include file="customer/main/product_prices.tpl"}
{/if}
{if $config.General.unlimited_products eq "Y" or ($product.avail gt 0 and $product.avail ge $product.min_amount)}
{if $js_enabled}


{if $smarty.get.pconf ne ""}
<INPUT type="hidden" name="slot" value="{$smarty.get.slot}">
<INPUT type="hidden" name="addproductid" value="{$product.productid}">
{include file="buttons/button.tpl" button_title=$lng.lbl_pconf_add_to_configuration style="button" href="javascript:if (FormValidation()) `$ldelim`document.orderform.productid.value='`$sma rty.get.pconf`';document.orderform.action='pconf.p hp';document.orderform.submit()`$rdelim`"}



{/if}
{if $product.forsale ne "B"}
{include file="buttons/add_to_cart.tpl" style="button" href="javascript: if(FormValidation()) document.orderform.submit();"}

{if $login ne "" and $active_modules.Wishlist ne ""}
{include file="customer/add2wl.tpl"}
{/if}
{else}
{$lng.txt_pconf_product_is_bundled}
{/if}
{else}
{include file="submit_wo_js.tpl" value=$lng.lbl_add_to_cart}
{/if}
{/if}
{if $active_modules.Feature_Comparison ne ""}
{include file="modules/Feature_Comparison/product_buttons.tpl"}
{/if}
{/if}



</TD>
</TR></TABLE>
</TD>
__________________
X-Cart Version 4.1.8
Reply With Quote
  #2  
Old 12-03-2005, 04:54 AM
 
CountyPaintball CountyPaintball is offline
 

Newbie
  
Join Date: Dec 2004
Location: NJ
Posts: 8
 

Default

Thanks for the credit.

Have you tested it on products with options? For example, a product with sizes/color options? I did find out that my original changes work fine except with optioned products. They show up and it lets you "add to cart" but then they don't actually show up in the cart. I'm guessing something in cart.php needs to be changed but I haven't looked at it yet. For now, I'm just not using any product options in my store.
__________________
Mike Everland
CountyPaintball.com
Reply With Quote
  #3  
Old 12-03-2005, 10:28 AM
 
Smalls Smalls is offline
 

Advanced Member
  
Join Date: Apr 2004
Location: Ontario
Posts: 30
 

Default

ah... options dont work over here. You can still add option'ed products that are in stock though... I'll have to look into it a little bit more when I have more time and find a solution though, options would be nice to have.
__________________
X-Cart Version 4.1.8
Reply With Quote
  #4  
Old 12-14-2005, 04:38 PM
 
CountyPaintball CountyPaintball is offline
 

Newbie
  
Join Date: Dec 2004
Location: NJ
Posts: 8
 

Default

I've been able to get "optoined" products that are out of stock into my shopping cart. I've been able to change the options (size, color, etc.) after it's in the cart as well.

However, when a customer goes to checkout, AFTER putting in their credit card number, etc. I get a message like this:

"Sorry, one of the products you have in cart is out of stock. "


Not very helpful message to the customer at all. It doesn't even tell them what product is out of stock. I'm having trouble figuring out where it does that final check before creating the order. The error message is "product_in_cart_expired". Somewhere it's checking to see if an item previously added to cart has since sold out.

Any info, please let me know.
Thanks
Mike
__________________
Mike Everland
CountyPaintball.com
Reply With Quote
  #5  
Old 02-16-2006, 03:01 PM
 
mkam mkam is offline
 

Newbie
  
Join Date: Feb 2006
Posts: 5
 

Default

Thanks!!!.. I just tried the mod.. it works!! But doesn't work on the feature page products... it still say "out of stock" on feature page.. and doesn't work on option products...

Thank you! Keep me up to date!!
__________________
X-Cart Gold 4.0.17
X-Configurator
Reply With Quote
  #6  
Old 08-28-2006, 05:57 PM
 
UpscaleHomeless UpscaleHomeless is offline
 

Newbie
  
Join Date: Aug 2006
Posts: 8
 

Question Re: Back Ordering / Out of Stock mod completed

Got a more specific question -

Any idea if this mod will support product variants?

(Meaning when each variant has a different SKU, but is displayed under the same product page)?

Anyone have any firsthand knowledge?

Thanks!
__________________
Upscale Homeless
(using x-cart version 4.1.3)
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 09:17 PM.

   

 
X-Cart forums © 2001-2020