Page 1 of 1

Change quantity for hasstock function

Posted: Wed May 30, 2018 11:51 pm
by ocam
If in System-->Settings-->Options-->Stock Checkout is set to No, it is not possible to complete the checkout if the product quantity is zero or less. As far as I can see, this is verified by the systems-->library-->cart.php hasstock() function:

Code: Select all

public function hasStock() {
		$stock = true;
		
		foreach ($this->getProducts() as $product) {
			if (!$product['stock']) {
	    		$stock = false;
			}
		}
		
    	return $stock;
If however the quantity should for example be -5 instead of zero, before a checkout is not possible, is there any way that this can be coded? I.e. there are 0 products in stock and someone buys 1 item, that should be possible, but if there are -3 products in stock (due to previous purchases for example) and someone buys another 3 items, the error message should appear and checkout should not be possible. Any suggestions would be greatly appreciated.

Thank you.

Re: Change quantity for hasstock function

Posted: Thu May 31, 2018 12:51 am
by Qphoria
Not fully sure what you are trying to do
You could change

Code: Select all

if (!$product['stock']) {
to

Code: Select all

if ($product['stock'] <= -3) {
if you want to allow "0" to be checked out but "-3" or greater to not be allowed

Re: Change quantity for hasstock function

Posted: Thu May 31, 2018 5:59 am
by ocam
Thank you for the suggestion and your reply, it was also my first thought, but it does not work.

In order to display products that are sold out and therefore cannot be ordered anymore and products that are currently not in stock but can still be ordered, the custom solution to prevent checkout of items that are not in stock is not useful (as it would prevent customers from placing orders for all non-stock items, which is not intended). This might be unusual since most shops simply delete products that are unavailable. However, it might be useful in some cases to still display sold-out items. Therefore defining a different (negative) quantity for these items may solve the problem.

Changing the following code seems to do the trick:

Code: Select all

// Stock
					if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $quantity)) {
						$stock = false;
					}