Post by OpenM » Sun Aug 14, 2011 2:40 am

Return Stock when Order Canceled ?


I have set a product to 3 pieces and made an order from the shop for 3 i recieved the order through admin then i cancelled the order from there checked the product quantiy its zero so the order for the whole quantity was 3 cancelled order no stock back doesn't the default should be restoring the quantity back as it was if orders cancelled?
i even deleted the whole order after cancellation still quantity zero and at the shop it shows out of stock.....

any suggestions to solve this??

Newbie

Posts

Joined
Sun Aug 14, 2011 2:34 am

Post by i2Paq » Sun Aug 14, 2011 2:56 am

OpenM wrote:any suggestions to solve this??
Used our FREE search?

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by opencartisalright » Sun Aug 14, 2011 2:58 am

This is normal behavior of OpenCart (although I wish it wasn't).

I agree that when you cancel an order then it should replace the stock that was taken out. It should also subtract the amount from your total sales figures as well. As of now it doesn't do either. Not sure if it ever will. I don't think there is an extension for it yet.

Active Member

Posts

Joined
Mon Feb 21, 2011 4:09 am

Post by Julio Cesar C G » Mon Aug 15, 2011 12:17 am

I do not know if this is a bug or some implementation that Daniel has not yet activated, but the solution is (But it only works if the order is deleted):

in admin/model/sale/order.php find

Code: Select all

	public function deleteOrder($order_id) {
		if ($this->config->get('config_stock_subtract')) {
			$order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND order_id = '" . (int)$order_id . "'");

			if ($order_query->num_rows) {
				$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");

				foreach($product_query->rows as $product) {
					$this->db->query("UPDATE `" . DB_PREFIX . "product` SET quantity = (quantity + " . (int)$product['quantity'] . ") WHERE product_id = '" . (int)$product['product_id'] . "'");

					$option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$product['order_product_id'] . "'");

					foreach ($option_query->rows as $option) {
						$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity + " . (int)$product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
					}
				}
			}
		}

		$this->db->query("DELETE FROM `" . DB_PREFIX . "order` WHERE order_id = '" . (int)$order_id . "'");
      	$this->db->query("DELETE FROM " . DB_PREFIX . "order_history WHERE order_id = '" . (int)$order_id . "'");
      	$this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
      	$this->db->query("DELETE FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "'");
	  	$this->db->query("DELETE FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$order_id . "'");
      	$this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "customer_transaction WHERE order_id = '" . (int)$order_id . "'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "customer_reward WHERE order_id = '" . (int)$order_id . "'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "affiliate_transaction WHERE order_id = '" . (int)$order_id . "'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "coupon_history WHERE order_id = '" . (int)$order_id . "'");
	}
replace with:

Code: Select all

	public function deleteOrder($order_id) {
		$order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND order_id = '" . (int)$order_id . "'");
		
		if ($order_query->num_rows) {
			$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");

			foreach($product_query->rows as $product) {
				$result = $this->db->query("SELECT subtract FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product['product_id'] . "'");
				
				if($result->row['subtract']){
					$this->db->query("UPDATE `" . DB_PREFIX . "product` SET quantity = (quantity + " . (int)$product['quantity'] . ") WHERE product_id = '" . (int)$product['product_id'] . "'");
	
					$option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$product['order_product_id'] . "'");
	
					foreach ($option_query->rows as $option) {
						$this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity + " . (int)$product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
					}
				}
			}
		}
		
		$this->db->query("DELETE FROM `" . DB_PREFIX . "order` WHERE order_id = '" . (int)$order_id . "'");
      	$this->db->query("DELETE FROM " . DB_PREFIX . "order_history WHERE order_id = '" . (int)$order_id . "'");
      	$this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
      	$this->db->query("DELETE FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "'");
	  	$this->db->query("DELETE FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$order_id . "'");
      	$this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "customer_transaction WHERE order_id = '" . (int)$order_id . "'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "customer_reward WHERE order_id = '" . (int)$order_id . "'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "affiliate_transaction WHERE order_id = '" . (int)$order_id . "'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "coupon_history WHERE order_id = '" . (int)$order_id . "'");
	}

User avatar
New member

Posts

Joined
Tue Oct 19, 2010 12:36 am
Location - Brazil

Post by Alsaru » Tue Apr 24, 2012 6:12 pm

Thank you !

This code is working for me (1.5.1.3).

New member

Posts

Joined
Wed Feb 29, 2012 1:33 am

Post by bytekultur » Tue Jan 29, 2013 11:08 pm

Has there been any attempt to fix this? I think stock should be updated on order status change as well, and as there are different product options with a stock number, it might get complicated to do so...

Newbie

Posts

Joined
Thu Nov 29, 2012 2:01 am

Post by Brite Light LEDs » Sun Apr 14, 2013 3:10 am

mine does not have this code to replace ? please help

V15.2.1

Automotive Lighting upgrades
http://www.BriteLightLEDs.co.uk


User avatar
Active Member

Posts

Joined
Wed Apr 25, 2012 12:47 am

Post by Klimskady » Tue Oct 01, 2013 6:29 am

Has this been rectified in 1.5.5.1? If not can someone post the updated code for this please, as its an important oversight that would be beneficial to most if not all store owners.

Active Member

Posts

Joined
Tue Jun 07, 2011 7:57 am

Post by i2Paq » Tue Oct 01, 2013 2:12 pm

Only when an order is deleted items will return to stock.

This is by design.

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by garywinner » Tue Nov 19, 2013 11:14 pm

i2Paq wrote:Only when an order is deleted items will return to stock.

This is by design.
I am using 1.5.6 OC.
I don't find there is an status of "Delete".
Please advice.

New member

Posts

Joined
Sun Sep 01, 2013 6:31 pm
Location - Hong Kong

Post by i2Paq » Tue Nov 19, 2013 11:16 pm

garywinner wrote:
i2Paq wrote:Only when an order is deleted items will return to stock.

This is by design.
I am using 1.5.6 OC.
I don't find there is an status of "Delete".
Please advice.
It is not a status: you must delete the order.

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by garywinner » Tue Nov 19, 2013 11:23 pm

You are right O0
Deleting the order makes things work. Tho it is not the best way.
Thankyou so much
i2Paq wrote:
garywinner wrote:
i2Paq wrote:Only when an order is deleted items will return to stock.

This is by design.
I am using 1.5.6 OC.
I don't find there is an status of "Delete".
Please advice.
It is not a status: you must delete the order.

New member

Posts

Joined
Sun Sep 01, 2013 6:31 pm
Location - Hong Kong

Post by 308Sound » Wed May 14, 2014 5:08 am

By design or no, I for one (several it would seem) do find it helpful to have records of customers who order, then cancel....during processing. It's a way for me to easily see if a customer has ordered and canceled in the past. IMO, stock should be allowed to be zeroed out and leave an empty order.

Newbie

Posts

Joined
Wed May 14, 2014 12:33 am
Who is online

Users browsing this forum: Amazon [Bot] and 83 guests