Hi there,
First of all, thank you for this great contribution.
But I found a bug in the Ajax CheckOut Contribution. If in oscommerce Admin you have "Check stock level" set to "true", even if you have "Allow Checkout" set to "true", the script won't let you place the order. The right thing to do would be to check the stock level and if "Allow Checkout" is set to "true" to let you place the order but warn you that the product is out of stock.
My solution is this:
In "catalog\ajax\classes\ajaxManagerTest.class.php", arround line 1235, find:
// Stock Check
$any_out_of_stock = false;
if (STOCK_CHECK == 'true') {
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
if (tep_check_stock($order->products[$i]['id'], $order->products[$i]['qty'])) {
$any_out_of_stock = true;
}
}
}
if ( (STOCK_ALLOW_CHECKOUT != 'true') && ($any_out_of_stock == true) ) $any_out_of_stock == true;
else $any_out_of_stock == false;
if (
ajaxSessionIsRegistered('sendto') &&
ajaxSessionIsRegistered('billto') &&
ajaxSessionIsRegistered('shipping') &&
ajaxSessionIsRegistered('payment') &&
ajaxSessionIsRegistered('customer_id') &&
is_object($payment_class) &&
is_array($shipping) && $any_out_of_stock == false
)
{
if (isset($payment_class->form_action_url)) {
$form_action_url = $payment_class->form_action_url;
echo tep_draw_form('checkout_confirmation', $form_action_url, 'post');
echo $payment_class->process_button();
echo '<input type="submit" value="Place Order"></form>';
} else {
echo '<input type="button" value="Place Order" onClick="ajaxPerformPlaceOrder();" id="buttonPlaceOrder">';
}
}
else
{
if ($any_out_of_stock == true) {
require_once(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SHOPPING_CART);
if (STOCK_ALLOW_CHECKOUT == 'true') {
?> <table width=100% border=0>
<tr>
<td class="stockWarning" align="center"><br><?php echo OUT_OF_STOCK_CAN_CHECKOUT; ?></td>
</tr>
</table>
<?php
} else {
?> <table width=100% border=0>
<tr>
<td class="stockWarning" align="center"><br><?php echo OUT_OF_STOCK_CANT_CHECKOUT; ?></td>
</tr>
</table>
<?php
}
}
}
and replace with:
// Stock Check
$any_out_of_stock = false;
if (STOCK_CHECK == 'true') {
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
if (tep_check_stock($order->products[$i]['id'], $order->products[$i]['qty'])) {
$any_out_of_stock = true;
}
}
}
if (
ajaxSessionIsRegistered('sendto') &&
ajaxSessionIsRegistered('billto') &&
ajaxSessionIsRegistered('shipping') &&
ajaxSessionIsRegistered('payment') &&
ajaxSessionIsRegistered('customer_id') &&
is_object($payment_class) &&
is_array($shipping) )
{
if ( ($any_out_of_stock == false) || ( ($any_out_of_stock == true) && (STOCK_ALLOW_CHECKOUT == 'true') ) ) {
if (isset($payment_class->form_action_url)) {
$form_action_url = $payment_class->form_action_url;
echo tep_draw_form('checkout_confirmation', $form_action_url, 'post');
echo $payment_class->process_button();
echo '<input type="submit" value="Place Order"></form>';
} else {
echo '<input type="button" value="Place Order" onClick="ajaxPerformPlaceOrder();" id="buttonPlaceOrder">';
}
if ($any_out_of_stock == true) {
require_once(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SHOPPING_CART);
?><table width=100% border=0>
<tr>
<td class="stockWarning" align="center"><br><?php echo OUT_OF_STOCK_CAN_CHECKOUT; ?></td>
</tr>
</table><?php
}
}
else {
?><table width=100% border=0>
<tr>
<td class="stockWarning" align="center"><br><?php echo OUT_OF_STOCK_CANT_CHECKOUT; ?></td>
</tr>
</table>
<?php
}
}
If you have other questions, please let me know.
Best regards,
Vassy