Post by lenna » Tue Nov 17, 2009 6:11 pm

if you have config_stock_subtract enable, you may need to reintegrate/charge back your stock when orders reach some statuses (as cancelled, chargeback, denied and so);
i tweak a little admin/model/customer/order.php to chargeback the stock of products once the status is changed to one of my choice (and of course the previous status didnt already made the chargeback)

to enable it
open admin/model/customer/order.php
search for this function: public function editOrder
and paste this code at the beginning of function, jsut before $this->db->query("UPDATE `" . DB_PREFIX . "order`....

at the moment the status that chargeback are hardcoded into $backarr, i will look forward to put a flag in the order_status edit (even it this means adding a db column)
for the moment just fill the $backarr with the order_status_id that you choose

hope this could be useful

Code: Select all

		/*CHARGE BACK*/
		$backarr=array(7,8,11,12,13); // these are the status that requires a chargeback (change as you need, you can grab these code from order_status table (order_status_id)
		if (in_array((int)$data['order_status_id'], $backarr)) {
			$prev_st=$this->db->query("SELECT order_status_id from " . DB_PREFIX . "order where order_id= '" .  (int)$order_id . "'");
			echo $prev_st->row['order_status_id'];
			if ($this->config->get('config_stock_subtract')) {
				if (!in_array($prev_st->row['order_status_id'], $backarr)) {
					$order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
					print_r($order_product_query);
					
					foreach ($order_product_query->rows as $result) {
					   $this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity + " . (int)$result['quantity'] . ") WHERE product_id = '" . (int)$result['product_id'] . "'");
					}
				}
			}
		}

Newbie

Posts

Joined
Tue Nov 17, 2009 6:00 pm

Post by i2Paq » Tue Nov 17, 2009 6:13 pm

This is verry usefull and should be default in OC.
This function is missing in many carts, osCommerce does have this function.

I have added this to the Feature Requests topic.

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 Qphoria » Tue Nov 17, 2009 8:19 pm

This already exists in the core for "deleted" orders. But I guess it could be good for canceled as well

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by i2Paq » Tue Nov 17, 2009 9:05 pm

Qphoria wrote:This already exists in the core for "deleted" orders. But I guess it could be good for canceled as well
How do I see if the canceled orders restock?

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 Qphoria » Tue Nov 17, 2009 11:00 pm

it doesn't.. thats why i said it could be good to add for canceled/chargeback/denied as demonstrated in this post. It currently only works for deleted orders.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by i2Paq » Tue Nov 17, 2009 11:12 pm

Qphoria wrote:it doesn't.. thats why i said it could be good to add for canceled/chargeback/denied as demonstrated in this post. It currently only works for deleted orders.
So if I delete an order it restocks without showing a notification except for""you modified your orders succesfully"?

Edit: it does!

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 DEHiCKA » Wed Jan 20, 2010 9:44 pm

lenna tweak doesn't affect options quantity. Here is my version, that changes options Qty as well.
And it works in both directions. So you can change order satus from cancelled back to one of the active states and it subtract products and options from the stock again.
Just add to the beginning of the editOrder function in order.php:

Code: Select all

// DEHiCKA - add CHARGE BACK
    $backarr=array(7,8,11,12,13); // these are the status that requires a chargeback (change as you need, you can grab these code from order_status table (order_status_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 (in_array((int)$data['order_status_id'], $backarr) != in_array($order_query->row['order_status_id'], $backarr) && $order_query->num_rows) { // status chargeback flag has changed
			$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
			if (in_array((int)$data['order_status_id'], $backarr)) $charge_dir = '+'; else $charge_dir = '-';
		   		
			foreach($product_query->rows as $product) {
					$this->db->query("UPDATE `" . DB_PREFIX . "product` SET quantity = (quantity ". $charge_dir. " " . (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 ". $charge_dir. " " . (int)$product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
					}				
				}
			}
		}
// DEHiCKA - end
There are still some bad logic in the restocking deleted orders: completed and cancelled orders must not restock when deleted.
It can be done easily by modifying deleteOrder function in order.php - add after 66th line ($order_query = $this->db->query(.... ):

Code: Select all

// DEHiCKA - mod CHARGE BACK
		    $backarr=array(7,8,11,12,13,5); // these are the status that DOES NOT requires a chargeback on delete (change as you need, you can grab these code from order_status table (order_status_id)
			if (!in_array($order_query->row['order_status_id'], $backarr))
// DEHiCKA - end CHARGE BACK

Newbie

Posts

Joined
Wed Jan 20, 2010 9:29 pm

Post by Photospirit » Sat Feb 04, 2012 6:28 pm

Hi,
will this code also work for 1.5.3.1? And if yes, in which file do I have to change it?
Many thanks, chris

New member

Posts

Joined
Sat Oct 23, 2010 8:16 pm

Post by topfuel75 » Tue Jan 15, 2013 11:37 am

I have made a vQmod for this. It is based on the code from DEHiCKA, but I havent include the deleteOrder function.
I have only tried it on 1.5.4.1, and it seems to work fine.

You will be able to return the stock tru the pages sale/order/update and sale/order/info when you change the order status.

Be sure to edit $backarr in the vQmod file so the order status id's will fit you need. $backarr is located in two places in the vQmod file.

Please let me know how it works out for you.

Cheers,
Fredrik

Attachments


Newbie

Posts

Joined
Wed Jan 09, 2013 2:32 am

Post by BriteLightLEDs2014 » Wed Dec 24, 2014 4:13 am

can i talk to you about this code, love to get working with my store, it used option to products extension also , i will pay ;D

Active Member

Posts

Joined
Wed Aug 20, 2014 3:59 am
Who is online

Users browsing this forum: No registered users and 77 guests