Plugin Directory

Changeset 2502500


Ignore:
Timestamp:
03/24/2021 11:54:03 AM (5 years ago)
Author:
Easify
Message:

Version 4.29

Location:
easify-server-woocommerce/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • easify-server-woocommerce/trunk/easify.php

    r2501937 r2502500  
    55 * Plugin URI: http://www.easify.co.uk/wordpress/
    66 * Description: Connects Easify Business Management, EPOS (Electronic Point of Sale) and invoicing software to your WooCommerce enabled WordPress website. Allowing you to keep your online and offline shop's orders and stock control synchronised.
    7  * Version: 4.28
     7 * Version: 4.29
    88 * License: GPL2
    99 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • easify-server-woocommerce/trunk/includes/class-easify-wc-shop.php

    r2501937 r2502500  
    2828 *
    2929 * @class       Easify_Generic_Shop
    30  * @version     4.28
     30 * @version     4.29
    3131 * @package     easify-woocommerce-connector
    3232 * @author      Easify
     
    233233               
    234234                // handling stock - we get free stock minus allocated stock
    235                 $stockLevel = $Product->StockLevel - $this->easify_server->get_allocation_count_by_easify_sku($Product->SKU);
    236 
    237                 // WooCommerce has a separate status value for in stock / out of stock, set it
    238                 // according to stock level...
    239                 if ($stockLevel > 0)
    240                 {
    241                     $this->DeleteOutofStockTermRelationship($ProductId);                                 
    242                     update_post_meta($ProductId, '_stock_status', 'instock');               
    243                 }
    244                 else
    245                 {
    246                     update_post_meta($ProductId, '_stock_status', 'outofstock');                   
    247                 }
     235                $stock_level = $Product->StockLevel - $this->easify_server->get_allocation_count_by_easify_sku($Product->SKU);
     236
     237                $this->update_stock_status( $stock_level, $ProductId );
    248238
    249239                update_post_meta($ProductId, '_manage_stock', 'yes');
     
    256246                // This needs to be free stock level not on hand stock level (Stock level minus amount of stock allocated to other orders)...
    257247                Easify_Logging::Log("Easify_WC_Shop.UpdateProduct() - Updating stock level.");                     
    258                 update_post_meta($ProductId, '_stock', $stockLevel);
     248                update_post_meta($ProductId, '_stock', $stock_level);
    259249            } else{
    260250                Easify_Logging::Log("Easify_WC_Shop.UpdateProduct() - Updating of stock levels disabled.");
     
    439429           
    440430            // handling stock - we get free stock minus allocated stock
    441             $stockLevel = $Product->StockLevel - $this->easify_server->get_allocation_count_by_easify_sku($Product->SKU);
     431            $stock_level = $Product->StockLevel - $this->easify_server->get_allocation_count_by_easify_sku($Product->SKU);
    442432                     
    443433            // get WooCommerce product id from Easify SKU
    444             $ProductId = $this->GetWooCommerceProductIdFromEasifySKU($Product->SKU);
    445            
    446             // WooCommerce has a separate status value for in stock / out of stock, set it
    447             // according to stock level...
    448             if ($stockLevel > 0 || $this->ProductAllowsBackorders($ProductId))
    449             {
    450                 $this->DeleteOutofStockTermRelationship($ProductId);                             
    451                 update_post_meta($ProductId, '_stock_status', 'instock');               
    452             }
    453             else
    454             {
    455                 update_post_meta($ProductId, '_stock_status', 'outofstock');                           
    456             }
    457                                  
    458             // This needs to be free stock level not on hand stock level (Stock level minus amount of stock allocated to other orders)...
     434            $product_id = $this->GetWooCommerceProductIdFromEasifySKU($Product->SKU);
     435
     436            $this->update_stock_status( $stock_level, $product_id );
     437
     438            // This needs to be free stock level not on hand stock level (Stock level minus amount of stock allocated to other orders).
    459439            Easify_Logging::Log("Easify_WC_Shop.UpdateProductStockLevel() - Updating stock level.");                     
    460             update_post_meta($ProductId, '_stock', $stockLevel);
     440            update_post_meta($product_id, '_stock', $stock_level);
    461441                       
    462442            Easify_Logging::Log("Easify_WC_Shop.UpdateProductStockLevel() - End.");
     
    466446        }
    467447    }
     448
     449    /**
     450     * @param string $stock_level
     451     * @param string|null $product_id
     452     */
     453    private function update_stock_status( string $stock_level, ?string $product_id ): void {
     454        // WooCommerce has a separate status value for in stock / out of stock, set it
     455        // according to stock level.
     456        if ( $stock_level > 0 ) {
     457            Easify_Logging::Log( "Easify_WC_Shop.update_stock_status() - Stock level > 0" );
     458
     459            $this->DeleteOutofStockTermRelationship( $product_id );
     460            update_post_meta( $product_id, '_stock_status', 'instock' );
     461        } else {
     462            Easify_Logging::Log( "Easify_WC_Shop.update_stock_status() - Stock level == 0" );
     463
     464            if ( $this->ProductAllowsBackorders( $product_id ) ) {
     465                Easify_Logging::Log( "Easify_WC_Shop.update_stock_status() - Product allows back order" );
     466
     467                update_post_meta( $product_id, '_stock_status', 'onbackorder' );
     468            } else {
     469                Easify_Logging::Log( "Easify_WC_Shop.update_stock_status() - Product does not allow back order" );
     470
     471                update_post_meta( $product_id, '_stock_status', 'outofstock' );
     472            }
     473        }
     474    }
    468475
    469476    public function ProductAllowsBackorders($WooProductId) {
     
    12411248        wp_update_post($ProductStub);         
    12421249    }
    1243            
    1244    
     1250
     1251
     1252
     1253
    12451254}
    12461255
  • easify-server-woocommerce/trunk/readme.txt

    r2501937 r2502500  
    55Requires at least: 4.0
    66Tested up to: 5.7
    7 Stable tag: 4.28
     7Stable tag: 4.29
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    101101
    102102== Changelog ==
     103= 4.29 =
     104* Additional improvements to WooCommerce stock status back order handling.
    103105= 4.28 =
    104106* Resolved issue where for certain configurations, WooCommerce product inventory 'Allow backorders'
     
    193195
    194196== Upgrade Notice ==
    195 = 4.28 =
    196 * Resolved issue where for certain configurations, WooCommerce product inventory 'Allow backorders'
    197 * could be set to 'Do not allow' when product stock levels updated.
     197= 4.29 =
     198* Additional improvements to WooCommerce stock status back order handling.
Note: See TracChangeset for help on using the changeset viewer.