kilbot / WooCommerce-POS

:bangbang: All development now at https://github.com/wcpos.
http://wcpos.com
GNU General Public License v3.0
353 stars 125 forks source link

Stock Quantity not updated correctly #134

Open fswong1972 opened 8 years ago

fswong1972 commented 8 years ago

I recently install a plugin called variable stock management which works by appending a configurable stock amount to be deducted under variable products.

https://github.com/vimes1984/woocommerce_variable_stock_management

The plugin works great under Woocommerce but in WC POS, the stock is not deducted according to the settings under the variable stock management plugin.

I tried to look into the code to see where the stock is deducted to see if I could do some modification. Unfortunately, I am not familiar with Java to see where the problem lies. Could you point out where the stock reduction code lies or even better create an update to fix this issue. I believe this will be a great fix as it would enable users to sell in variable quantities like in pieces, dozen or carton boxes without using bundles or composite products which complicates the inventory database.

kilbot commented 8 years ago

I've had a quick look at the source of the plugin you mention and can see that it is not compatible with the WC REST API. It looks like it uses woocommerce_checkout_order_processed to trigger the stock adjustment, but that hook only fires for orders processed through the online store, not for orders processed through the API like WooCommerce POS.

You could contact the developer to see if they are willing to make their plugin compatible with the WC REST API. Alternatively you could adjust the code and submit a fix to the repository. The woocommerce_payment_complete action should fire for both online and POS orders.

fswong1972 commented 8 years ago

The developer of variable stock plugin did not respond.

I tried hard to look into your code using Chrome's debugger but it works only for .js scripts, for the php files I could not see what's happening. Sorry for sounding stupid but after all I am a retired semiconductor ic designer, software is not really my cup of tea. Is it ok for you to come up with a fixed for a small fee? A simple solution would be to get the variable containing the amount of stock to reduce for the plugin for each variable, do a multiplication with the POS item quantity ordered and then push to the WC_REST_API to do the stock reduction.

On 12 August 2016 at 14:10, Paul Kilmurray notifications@github.com wrote:

I've had a quick look at the source of the plugin you mention and can see that it is not compatible with the WC REST API https://woothemes.github.io/woocommerce-rest-api-docs/. It looks like it uses woocommerce_checkout_order_processed to trigger the stock adjustment, but that hook only fires for orders processed through the online store, not for orders processed through the API like WooCommerce POS.

You could contact the developer to see if they are willing to make their plugin compatible with the WC REST API. Alternatively you could adjust the code and submit a fix to the repository. The woocommerce_payment_complete action should fire for both online and POS orders.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kilbot/WooCommerce-POS/issues/134#issuecomment-239376711, or mute the thread https://github.com/notifications/unsubscribe-auth/AUAsRYE7qztD9JOUkAxSX72jV-BXwVZrks5qfBxSgaJpZM4JiwfK .

kilbot commented 8 years ago

You could try moving the action from woocommerce_checkout_order_processed to woocommerce_payment_complete (ie: copy this change). I don't know if that will have any unintended consequences, but it should fire on a POS sale.

I've had a brief look over the code of that plugin and it's not something I want to get involved in, especially if the developer has stopped supporting it.

fswong1972 commented 8 years ago

I am also a bit worried to use the plugin if it is not supported. Any future updates in Wordpress might cause issues with this plugin. Besides,I need to migrate over 2000+ items from Quickbooks POS to Woocommerce, the data entry is taxing and time consuming. I am still figuring out how to import the Quickbooks inventory into WC easily. This is because in Quickbooks POS I used a feature called Unit of Measure (UOM) which allows each product to a assigned a base UOM. With UOM for each product, I can then set multiples of that UOM, for example UOM X1 for a single unit, UOM X 12 for a dozen, UOM X 24 for carton. So each product has multiple prices making the export csv file more complicated. This plugin accomplishes the same function of Quickbooks UOM in WC.

Back to your suggestion, the change managed to fire on POS sale but the online store does not. I had to enable

add_action( "woocommerce_checkout_order_processed", array($this, 'update_stock_on_checkout_nopayment') );

too in order to fire the online POS. At first I was worried there could be a double reduction in the order amount but there is no such issue. However, I noticed that decimal quantity set in the POS cannot be deducted from the stock quantity. I think this is due to the fact that woocommerce_payment_complete in the plugin does not support decimal quantity.

On 16 August 2016 at 13:43, Paul Kilmurray notifications@github.com wrote:

You could try moving the action from woocommerce_checkout_order_processed to woocommerce_payment_complete (ie: copy this change https://github.com/kilbot/woocommerce_variable_stock_management/commit/ff0ae1f7180a6a7312d9523946ac465c8a5b5129). I don't know if that will have any unintended consequences, but it should fire on a POS sale.

I've had a brief look over the code of that plugin and it's not something I want to get involved in, especially if the developer has stopped supporting it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kilbot/WooCommerce-POS/issues/134#issuecomment-240016576, or mute the thread https://github.com/notifications/unsubscribe-auth/AUAsRYSeNsVDwzhOBNWS6yApSlO8puv4ks5qgVv8gaJpZM4JiwfK .

kilbot commented 8 years ago

Looks like the intval on these lines is going to round everything ... you should be able to safely remove those.

fswong1972 commented 8 years ago

Removing the intval on the lines you mentioned, enable the use of decimal in your POS. Most issues are settled now, I will now get to work on figuring out how to import the Quickbooks inventory into Woocommerce variable products.

On 16 August 2016 at 18:38, Paul Kilmurray notifications@github.com wrote:

Looks like the intval on these lines https://github.com/kilbot/woocommerce_variable_stock_management/blob/master/includes/class-variable-product-stock-reduction.php#L296-L297 is going to round everything ... you should be able to safely remove those.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kilbot/WooCommerce-POS/issues/134#issuecomment-240077621, or mute the thread https://github.com/notifications/unsubscribe-auth/AUAsRZjvc8B3PRIIW-TsKdVKfMxbLdLpks5qgaFPgaJpZM4JiwfK .