Plugin Directory

Changeset 3020674


Ignore:
Timestamp:
01/11/2024 11:39:26 PM (2 years ago)
Author:
slynkdigital
Message:

v4.2.5

  • Updated logic for setting woo master category for variable products
  • Ensured that the sln_product_type meta is in lowercase if updated via the API
Location:
woo-epos-now-integration/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • woo-epos-now-integration/trunk/inc/wc-products.php

    r3006305 r3020674  
    122122
    123123            if ( $query_params['trigger_product_update_webhook'] && ! $ignore_product ) {
    124                 sew_woocommerce_update_product_callback( get_the_ID(), $product_obj );
     124                do_action('sew_product_updated', get_the_ID(), $product_obj);
    125125            }
    126126
     
    177177
    178178    if(isset($query_params['include'])){
    179         $variaton_ids = explode(',', $query_params['include']);
    180         $args['post__in'] = $variaton_ids;
     179        $variation_ids = explode(',', $query_params['include']);
     180        $args['post__in'] = $variation_ids;
    181181    }
    182182
     
    246246    }
    247247}
    248 
    249 function sew_product_post_save($product_obj){
    250 
     248function sew_product_meta_updated($meta_id, $post_id, $meta_key, $meta_value)
     249{
    251250    global $sew_plugin_settings;
    252251
    253252    if (isset($sew_plugin_settings['product_sync_disabled']) && $sew_plugin_settings['product_sync_disabled'] == false) {
    254         $product_data = $product_obj->get_data();
    255 
    256         //check that the product update is not from our stock update
    257         if (!sew_check_product_webhook_from_stock($product_obj, $product_data['id'])) {
    258 
    259             if ($product_obj->is_type('variable')) {
    260 
    261                 $sln_product_category_master = 0;
    262                 $product_meta = $product_obj->get_meta_data();
    263 
    264                 foreach ($product_meta as $product_meta_obj) {
    265                     $product_meta_data = $product_meta_obj->get_data();
    266 
    267                     if ($product_meta_data['key'] == 'sln_product_category_master') {
    268                         if ($product_meta_data['value']) {
    269                             $sln_product_category_master = $product_meta_data['value'];
    270                             break;
    271                         }
    272                     }
    273 
    274                 }
    275                 //set the master category for all the variations
    276                 sew_set_sln_product_category_master_for_variations($product_obj, $sln_product_category_master);
     253
     254        if ($meta_key == 'sln_product_category_master') {
     255            //check if the post type is a variable product
     256            $post_type = get_post_type($post_id);
     257
     258            if ($post_type === 'product') {
     259                sew_set_sln_product_category_master_for_variations($post_id, $meta_value);
    277260            }
    278 
    279         }
    280 
    281     }
    282 }
    283 add_action('woocommerce_after_product_object_save', 'sew_product_post_save');
    284 
    285 function sew_set_sln_product_category_master_for_variations($product_obj,$sln_product_category_master){
     261        }
     262    }
     263}
     264
     265//only fires when updating a meta value that already exists
     266//not using updated_post_meta because that fires only when the meta_value is changing to a new value
     267add_action('update_post_meta', 'sew_product_meta_updated', 10, 4);
     268//only fires when adding a new meta key that doesn't already exist
     269add_action('added_post_meta', 'sew_product_meta_updated', 10, 4);
     270
     271function sew_set_sln_product_category_master_for_variations($product_id,$sln_product_category_master){
     272    //get the product
     273    $product_obj = wc_get_product($product_id);
    286274    //get the variations
    287275    $variations = $product_obj->get_children();
     
    290278
    291279            $current_cat_id = get_post_meta( $variation_id, 'sln_product_category_master', true );
    292 
    293280            //check if the category has changed and update category for variations and trigger product webhooks
    294281            if($current_cat_id != $sln_product_category_master) {
     
    380367                //loop through each product meta
    381368                foreach($sln_post_meta_arr as $sln_post_meta){
     369                    //check if set in payload received
    382370                    if(isset($product_value[$sln_post_meta])){
    383                         //get product type
     371                        //if we received sln_product_type, make sure it is in lowercase
    384372                        if($product_value['sln_product_type']){
    385                             strtolower($product_value[$sln_post_meta]);
     373                            $product_value['sln_product_type'] = strtolower($product_value['sln_product_type']);
    386374                        }
    387375                        update_post_meta($product_id, $sln_post_meta, $product_value[$sln_post_meta]);
  • woo-epos-now-integration/trunk/readme.txt

    r3006305 r3020674  
    33Tags: woocommerce,eposnow,integration,epos,stock sync,order sync, product sync, inventory sync
    44Requires at least: 4.9.8
    5 Tested up to: 6.4.1
     5Tested up to: 6.4.2
    66Requires PHP: 5.5
    77Stable tag: trunk
     
    8686== Changelog ==
    8787
     88= 4.2.5 =
     89* Updated logic for setting woo master category for variable products
     90* Ensured that the sln_product_type meta is in lowercase if updated via the API
     91
    8892= 4.2.4 =
    8993* Product meta update now includes more post statuses
  • woo-epos-now-integration/trunk/woo-epos-now-integration.php

    r3019941 r3020674  
    44Plugin URI:             https://slynk.io/epos-now-woocommerce-integration/
    55Description:            Integration for syncing orders, products, stock and customers between WooCommerce and Epos Now
    6 Version:                4.2.4
     6Version:                4.2.5
    77Author:                 Slynk Digital
    88Author URI:             https://www.slynk.io
     
    1414
    1515//CONSTANTS
    16 define('SLYNK_EW_PLUGIN_VERSION','4.2.4');
     16define('SLYNK_EW_PLUGIN_VERSION','4.2.5');
    1717define('SLYNK_EW_PLUGIN_NAME','Integration for Epos Now and WooCommerce');
    1818define('SLYNK_EW_PLUGIN_PATH',basename(dirname(__FILE__)).'/'.basename(__FILE__));
Note: See TracChangeset for help on using the changeset viewer.