Api Create Order With Product Inventory Zero

We are building a POS application which is using the API in 4.3.6. There are some products as well as certain circumstances where we need to be able to transact a product through the POS (via API) that has an inventory of zero. If we attempt to do this, it raises an error that there is not enough inventory. Ok makes sense.

If we change the setting for CS Cart to "allow negative inventory", the order is processed correctly and the inventory changes to -1, -2, etc. BUT it also impact the web page in allowing anyone to buy everything even if not in stock, so that is not an option for us. So we are leaving that as "no"

In looking at the fn.cart.php function, there seems to be an exception for when changes are made with "order_management" which I assumed to be editing the order from admin.php, so we tested that. It raises some warnings, but does allow us to add additional qty to an order of an item that is not in stock, BUT it leaves the inventory at 1 afterwards, should be zero. I will report that as a bug.

What I need to do, is to treat the orders from the API as "order_management" or make a bunch of changes to fn.cart.php to allow the order to go through as if "allow negative inventory" is true, when it is actually false. I played around with this a bit and it appears doable, but I'd rather not hack up the code that much if I can avoid it.

The "text_api_error" is what is displayed back from the API. You can also see the order management exception

if ($current_amount > 0 && $current_amount - $amount < 0 && Registry::get('settings.General.allow_negative_amount') != 'Y') {
if (!defined('ORDER_MANAGEMENT')) {
fn_set_notification('W', __('important'), __('text_cart_amount_corrected', array(
'[product]' => $product['product']
)));
$amount = fn_ceil_to_step($current_amount, $product['qty_step']);
} else {
if ($product['tracking'] == ProductTracking::TRACK_WITH_OPTIONS) {
fn_set_notification('E', __('warning'), __('text_combination_out_of_stock'));
} else {
fn_set_notification('W', __('warning'), __('text_cart_not_enough_inventory'));
}
}
} elseif ($current_amount - $amount < 0 && Registry::get('settings.General.allow_negative_amount') != 'Y') {
if ($product['tracking'] == ProductTracking::TRACK_WITH_OPTIONS) {
fn_set_notification('E', __('notice'), __('text_combination_out_of_stock'));
} else {
fn_set_notification('E', __('notice'), __('text_api_error', array(
'[product]' => $product['product']
)));
}
return false;
} elseif ($current_amount <= 0 && $amount <= 0 && Registry::get('settings.General.allow_negative_amount') != 'Y') {
fn_set_notification('E', __('notice'), __('text_cart_zero_inventory_and_removed', array(
'[product]' => $product['product']
)));
return false;
}
}

So I have figured out a number of ways to suppress the error and allow me to proceed. It works fine if I am adding any qty of product which is NOT in stock. It also works fine if I am adding any qty of product that IS in stock. The problem is when I mix the two. If I add one item which is NOT in stock and one that IS in stock, it does not increment down the qty in stock on the one that IS in stock.

You could add a condition of !defined('API').