• Resolved sebtoombs

    (@sebtoombs)


    Hey, seems like there is a bug when saving a product if you previously managed stock with this plugin.

    It does not respect the “manage stock” setting, and will set the product back to “out of stock” if the fields are empty.

    I have implemented a small fix. Add the following code at the top of the “update_product_meta” function within trait-slw-stock-locations-tab.php (line 277). This prevents the product meta from being updated if stock is not managed for the product.

    
    277: public function update_product_meta($id, $product_stock_location_terms, $terms_total): void {
      278: //Check whether should run
      $manage_stock = get_post_meta($id, '_manage_stock', true) === 'yes';
      if (!$manage_stock) {
        return;
      }
    
      //... rest of method
    

    If you can integrate this that would be great! Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @sebtoombs

    Thank you for reporting me this, i will test locally and release an update asap to fix the issue.

    Thread Starter sebtoombs

    (@sebtoombs)

    Hey @alexmigf

    I’ve found potentially another bug. We’re running this plugin on a moderately sized wordpress install (say 100-200 concurrent users) and noticed extremely high disk writes.

    Eventually tracked it down to rewrite rules being flushed on every page view, which seems to be caused by the init method of SlwMain (line 92 specificall)

    
    public function init(): void
            {
                // Action to load textdomain
                add_action( 'init', array($this, 'load_textdomain') );
    
                // Enqueue scripts and styles
                add_action( 'admin_enqueue_scripts', array($this, 'enqueue') );
    
                // Prevent WooCommerce from reduce stock
                add_filter( 'woocommerce_can_reduce_order_stock', '__return_false', 999 ); // Since WC 3.0.2
    
                // Display admin notices
    			add_action( 'admin_notices', [new SLW\SRC\Classes\SlwAdminNotice(), 'displayAdminNotice'] );
    
    			// Flush rewrite rules
                add_action( 'shutdown', array($this, 'flush_rewrite_rules'), 9999 );
    		}
    

    My understanding is that rewrites should only be flushed when there is a change to the permalink structure?

    For now I’ve simply commented the line out and that seems to have fixed the issue.

    I’ve posted it in this topic so as not to clutter up the support forum.

    Plugin Contributor alexmigf

    (@alexmigf)

    Hi @sebtoombs

    Thank you for pointing that, i was to remove in the previous release but I ended up forgetting. Indeed, should be avoided when not necessary, in this case i remove for now. Please update the plugin with the last release.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Stock management bug’ is closed to new replies.