• Hi,

    There is a problem when stock is reduced twice. I believe you need to replace:

    
    wc_reduce_stock_levels($order_id);
    

    with

    
    wc_maybe_reduce_stock_levels( $order_id );
    

    on line 267 in your class-wc-paysera-gateway.php file.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Algoritmika

    (@algoritmika)

    Hi,

    I see that there is new version of the plugin released, but it looks like you didn’t address the issue there. Let me try to explain what problem we are having here: let’s say customer starts the payment process with Paysera, but doesn’t finish it. Then he goes back and changes payment method to something else (e.g. “Cash on delivery”). As you are calling wc_reduce_stock_levels() and not wc_maybe_reduce_stock_levels(), I believe, stock is reduced twice then (because WooCommerce doesn’t mark order as _order_stock_reduced). Could you please take a look?

    Hello,

    When do you plan to solve this issue?

    Thanks.

    Plugin Author paysera

    (@paysera)

    Dear customer,

    as we already discussed before, we can not change this part, because our plugins are ready for the biggest part of the customers, in case you want to make some changes, you can do it.

    When the customer comes back he may still pay for the product using Paysera and in most cases, customers want to have enough items to sell, that’s why they have stock control.

    The stock level can be recovered with the status change of order, check the automatic status change in the Admin.

    If you have additional questions, how you should update the code, you may write to [email protected].

    Have a nice day!

    Thread Starter Algoritmika

    (@algoritmika)

    Hi @paysera,

    Thank you for the reply.

    First of all – I don’t think you’ve discussed it with me before ??

    Now regarding the issue itself. I’m not sure if you are correct. If you use wc_maybe_reduce_stock_levels() instead of wc_reduce_stock_levels(), stock still will be reduced, but in addition, order will be marked as “stock reduced”, and if some other gateway will try to reduce stock again, it won’t happen and stock won’t be reduced twice. So I don’t think that replacing this function will hurt any of your other users…

    Anyway, if you insist on leaving the wc_reduce_stock_levels() in your code, maybe you could at least add some filters and actions, so I wouldn’t have to make my changes directly in your plugin’s code? For example, if you could replace (line 267 in your class-wc-paysera-gateway.php file):

    
    wc_reduce_stock_levels($order_id);
    

    with something like this:

    
    if ( apply_filters( 'paysera_do_reduce_stock_levels', true, $order_id ) ) {
        wc_reduce_stock_levels( $order_id );
    }
    do_action( 'paysera_after_reduce_stock_levels', $order_id );
    

    then it wouldn’t change anything for your other users, and I wouldn’t have to change your plugin’s code after each update.

    Please let me know what you think.

    Plugin Author paysera

    (@paysera)

    Dear customer,

    Paysera is offering prepared integrations that open-sourced and we allow editing the code as you wish.

    There cases that would affect our current users, just to make one integration compatible with some other needs.

    We advise either to update the code for yourself, either just use automatic stock recovery, as such changes are not planned in near future, your offer is noted.

    If you have additional questions, you may contact us directly [email protected].

    Have a nice day!

    Hey,

    I can see that in 2.5.9 update changes were made to wc_maybe_reduce_stock_levels($order_id) instead of wc_reduce_stock_levels($order_id) at 267 in class-wc-paysera-gateway.php.

    @algoritmika does stock reduction work fine for you after this update?

    I previously had some workarounds, which kind of worked but are no longer working after current update.

    How are you handling stock reduction? What are your paysera woocommerce settings under “u?sakymo būsena” tab?

    Do you have custom code to handle stock reduction?

    Because I have some issues, where customers abandon cart and I still get stock reduction, which is not automatically incremented back and has to be manually reset.

    Also, sometimes when order is successfully completed, stock is reduced twice.

    Hope you can help out,

    Lukas

    Thread Starter Algoritmika

    (@algoritmika)

    Hi @lukasjan123,

    @algoritmika does stock reduction work fine for you after this update?

    Yes, it looks like the latest release fixed it for us. At least at a first glance, I may need to test it more though…

    What are your paysera woocommerce settings under “u?sakymo būsena” tab?

    Our settings are:

    New Order Status: Pending payment
    Paid Order Status: Processing
    Pending checkout: Pending payment

    Do you have custom code to handle stock reduction?

    The only thing we had was wc_maybe_reduce_stock_levels() instead of wc_reduce_stock_levels(). So now after the last plugin update, there is no more custom code left.

    Because I have some issues, where customers abandon cart and I still get stock reduction, which is not automatically incremented back and has to be manually reset.

    We had similar problem (i.e. because of wc_reduce_stock_levels()), but now the issue is gone.

    As far as I know, for stock to be restored after wc_maybe_reduce_stock_levels() was called, order status must change to either “cancelled” or “pending”. There are two hooks for wc_maybe_increase_stock_levels() in WooCommerce (it’s in woocommerce\includes\wc-stock-functions.php):

    
    add_action( 'woocommerce_order_status_cancelled', 'wc_maybe_increase_stock_levels' );
    add_action( 'woocommerce_order_status_pending', 'wc_maybe_increase_stock_levels' );
    

    Also, sometimes when order is successfully completed, stock is reduced twice.

    Actually I don’t think we had anything like that, even before the latest plugin update, so I’m not really sure what’s happening there.

    Hope that helps.

    Thank you! Will try with your settings and see how it goes.

    Thread Starter Algoritmika

    (@algoritmika)

    @lukasjan123,

    Sure, happy to help ?? One note though – regarding:

    Also, sometimes when order is successfully completed, stock is reduced twice.

    I’m now thinking that this could be related to wc_reduce_stock_levels() vs wc_maybe_reduce_stock_levels() issue as well. For example, if your customer starts paying with Paysera, then switches to another method, and then back to Paysera again. Not sure though… Anyway, this should be fixed already in the latest version.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Stock reduced twice’ is closed to new replies.