Plugin Directory

Changeset 2638457


Ignore:
Timestamp:
12/02/2021 09:41:34 AM (4 years ago)
Author:
bjorntech
Message:

tagging version 7.5.0

Location:
woo-izettle-integration
Files:
28 edited
1 copied

Legend:

Unmodified
Added
Removed
  • woo-izettle-integration/tags/7.5.0/README.txt

    r2602846 r2638457  
    55Tested up to: 5.8
    66Requires PHP: 7.3
    7 Stable tag: 7.4.2
     7Stable tag: 7.5.0
    88License: GPLv3 or later
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    118118
    119119== Changelog ==
     120= 7.5.0 =
     121* The plugin is verified to work with WooCommerce 5.9
     122* New: Added option for prioritizing Zettle price above Sale price
     123* Fix: Changed import type to Merge products as default
     124* Fix: Error thrown if SKU is too long
     125* Fix: Notices failing to show up
     126* Fix: Variations out of stock were synced even when configured not to
     127* Fix: Added timestamp to notices
     128* Fix: Failing to unschedule actions causing error
     129* Fix: thepostid variable not declared causing warnings
     130* Fix: Wrong number of parameters in the update of products from zettle caused products to be created although setting was set to only update.
    120131= 7.4.2 =
    121132* The plugin is verified to work with WooCommerce 5.7
  • woo-izettle-integration/tags/7.5.0/includes/admin/izettle-integration-helper.php

    r2602846 r2638457  
    426426        public static function object_diff(stdClass $obj1, stdClass $obj2): bool
    427427        {
    428             $array1 = json_decode(json_encode($obj1), true);
    429             $array2 = json_decode(json_encode($obj2), true);
     428            $array1 = json_decode(json_encode($obj1, JSON_INVALID_UTF8_IGNORE), true);
     429            $array2 = json_decode(json_encode($obj2, JSON_INVALID_UTF8_IGNORE), true);
    430430            return self::array_diff($array1, $array2);
    431431        }
     
    512512        {
    513513            if (!is_array($object)) {
    514                 $object = json_decode(json_encode($object), true);
     514                $object = json_decode(json_encode($object, JSON_INVALID_UTF8_IGNORE), true);
    515515            }
    516516            unset($object['etag']);
     
    518518            unset($object['updatedBy']);
    519519            self::ksort_recursive($object);
    520             WC_IZ()->logger->add(print_r(json_encode($object), true));
     520            WC_IZ()->logger->add(print_r(json_encode($object, JSON_INVALID_UTF8_IGNORE), true));
    521521            return md5(json_encode((object) $object));
    522522        }
     
    885885                if (false === $tax_rates) {
    886886                    $tax_rates = izettle_api()->get_tax_rates();
    887                     WC_IZ()->logger->add(sprintf('get_rates: "%s"', json_encode($tax_rates)));
     887                    WC_IZ()->logger->add(sprintf('get_rates: "%s"', json_encode($tax_rates, JSON_INVALID_UTF8_IGNORE)));
    888888                    set_site_transient('zettle_tax_rates', $tax_rates, DAY_IN_SECONDS);
    889889                }
     
    958958                if (false === $tax_settings) {
    959959                    $tax_settings = izettle_api()->get_tax_settings();
    960                     WC_IZ()->logger->add(sprintf('get_tax_settings: "%s"', json_encode($tax_settings)));
     960                    WC_IZ()->logger->add(sprintf('get_tax_settings: "%s"', json_encode($tax_settings, JSON_INVALID_UTF8_IGNORE)));
    961961                    set_site_transient('zettle_tax_settings', $tax_settings, DAY_IN_SECONDS);
    962962                }
  • woo-izettle-integration/tags/7.5.0/includes/admin/izettle-integration-notices.php

    r2526349 r2638457  
    6262
    6363            $notices[$id] = $notice;
     64
    6465            set_site_transient('izettle_notices', $notices);
    6566
     
    7071        {
    7172
    72         /*    if (WC_Zettle_Helper::wc_version_check('4.0.0')) {
    73                 require_once dirname(__FILE__) . '/izettle-admin-notes.php';
    74                 \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_iZettle::clear($id);
     73            /*    if (WC_Zettle_Helper::wc_version_check('4.0.0')) {
     74            require_once dirname(__FILE__) . '/izettle-admin-notes.php';
     75            \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_iZettle::clear($id);
    7576            }*/
    7677
    7778            $notices = get_site_transient('izettle_notices');
    78             if ($id && isset($notices[$id])) {
    79                 unset($notices[$id]);
     79            if ($id) {
     80                if (isset($notices[$id])) {
     81                    unset($notices[$id]);
     82                }
    8083            } else {
    8184                $notices = array();
     
    8790        {
    8891            $dismissable = $dismiss ? 'is-dismissible' : '';
     92            $date = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), date('U') + (get_option('gmt_offset') * HOUR_IN_SECONDS));
     93            $message = $date . ' - Zettle: ' . $message;
    8994            echo '<div class="iz_notice ' . $dismissable . ' notice notice-' . $type . ' ' . $id . '"><p>' . $message . '</p></div>';
    9095        }
     
    9398        {
    9499            $notices = get_site_transient('izettle_notices');
    95 
    96100            if (false !== $notices && !empty($notices)) {
    97101                foreach ($notices as $key => $notice) {
  • woo-izettle-integration/tags/7.5.0/includes/admin/settings/views/html-admin-settings-products-from-izettle-options-desc.php

    r2526349 r2638457  
    4444    <?php _e('<b>Create and update products in WooCommerce</b> - Both the Create and Update above will happen.', 'woo-izettle-integration');?>
    4545    </li>
     46    <li>
     47    <?php _e('<b>Create, update and delete products in WooCommerce</b> - Both the Create and Update above will happen. Furthermore, products deleted in Zettle will also be deleted in WooCommerce.', 'woo-izettle-integration');?>
     48    </li>
    4649    </ul>
    4750    <p>
  • woo-izettle-integration/tags/7.5.0/includes/admin/settings/wc-settings-page-izettle.php

    r2602846 r2638457  
    281281            $pricelists = array(
    282282                '' => __('Regular price', 'woocommerce'),
    283                 '_sale' => __('Sale price if available (Regular if not)', 'woo-izettle-integration'),
    284                 '_special' => __('Zettle price from the Zettle tab if available (Regular if not)', 'woo-izettle-integration'),
     283                '_sale' => __('Sale price if available - Regular if not', 'woo-izettle-integration'),
     284                '_special' => __('Zettle price from the Zettle tab if available - Regular if not', 'woo-izettle-integration'),
     285                '_sale_special' => __('Zettle price from Zettle tab if available - Sale price if not - Regular price if not', 'woo-izettle-integration'),
    285286                '_no_price' => __('Do not set the price', 'woo-izettle-integration'),
    286287            );
     
    708709                        'type' => 'select',
    709710                        'desc' => __('Select type of manual import.', 'woo-izettle-integration'),
    710                         'default' => 'dry',
     711                        'default' => 'merge',
    711712                        'options' => array(
    712713                            'dry' => __('Dry run full import', 'woo-izettle-integration'),
    713                             'merge' => __('Merge products', 'woo-izettle-integration'),
     714                            'merge' => __('Merge products (recommended)', 'woo-izettle-integration'),
    714715                            'new' => __('Create all products', 'woo-izettle-integration'),
    715716                            'match_dry' => __('Dry run matching only', 'woo-izettle-integration'),
  • woo-izettle-integration/tags/7.5.0/includes/api/izettle-integration-api.php

    r2602846 r2638457  
    130130                        $args['body'] = $form;
    131131                    } else {
    132                         $json_body = json_encode($form);
     132                        $json_body = json_encode($form, JSON_INVALID_UTF8_IGNORE);
    133133                        if (!$json_body) {
    134134                            $json_error = json_last_error();
     
    166166
    167167                if (($http_code = wp_remote_retrieve_response_code($response)) > 299) {
    168                     $message = isset($data->developerMessage) ? $data->developerMessage : 'Error when connecting to Zettle';
     168
     169                    if (isset($data->violations)) {
     170                        $violatons = reset($data->violations);
     171                        $message = $violatons->developerMessage;
     172                    } elseif (isset($data->developerMessage)) {
     173                        $message = $data->developerMessage;
     174                    } else {
     175                        $message = __('Unknown error when connecting to Zettle', 'woo-izettle-integration');
     176                    }
     177
    169178                    throw new IZ_Integration_API_Exception($message, $http_code);
    170179                }
  • woo-izettle-integration/tags/7.5.0/includes/izettle-integration-authorization.php

    r2526349 r2638457  
    148148                );
    149149                if (count($actions) > 1) {
    150                     as_unschedule_action('izettle_service_heartbeat');
     150                    try{
     151                        as_unschedule_action('izettle_service_heartbeat');
     152                    }catch(\Throwable $throwable){
     153                        WC_IZ()->logger->add(sprintf('schedule_heartbeat_sync - No process to unschedule'));
     154                    }
    151155                }
    152156            } else {
    153157                if (false !== as_next_scheduled_action('izettle_service_heartbeat')) {
    154                     as_unschedule_all_actions('izettle_service_heartbeat');
     158                    try{
     159                        as_unschedule_all_actions('izettle_service_heartbeat');
     160                    }catch(\Throwable $throwable){
     161                        WC_IZ()->logger->add(sprintf('schedule_heartbeat_sync - No process to unschedule'));
     162                    }
    155163                }
    156164            }
  • woo-izettle-integration/tags/7.5.0/includes/izettle-integration-iz-products.php

    r2602846 r2638457  
    3939            add_filter('wciz_sync_iz_products_filter', array($this, 'sync_iz_products'), 10, 2);
    4040            add_action('wciz_sync_iz_products_action', array($this, 'sync_iz_products'), 10, 2);
    41             add_action('wciz_sync_iz_products_process', array($this, 'sync_iz_products_process'), 10, 3);
     41            add_action('wciz_sync_iz_products_process', array($this, 'sync_iz_products_process'), 10, 4);
    4242
    4343        }
     
    297297        {
    298298
     299
     300
    299301            if (false !== $payload) {
    300                 $payload = is_object($payload) ? $payload : json_decode(json_encode($payload));
     302                $payload = is_object($payload) ? $payload : json_decode(json_encode($payload, JSON_INVALID_UTF8_IGNORE));
    301303            } else {
    302304                if ($payload = get_site_transient('sync_products_from_izettle_' . $key)) {
     
    309311            }
    310312
    311             $this->logger(sprintf('sync_iz_products_process: got %s payload %s', $webhook ? 'webhook' : 'import', json_encode($payload)));
     313            $this->logger(sprintf('sync_iz_products_process: got %s payload %s', $webhook ? 'webhook' : 'import', json_encode($payload, JSON_INVALID_UTF8_IGNORE)));
     314
     315            if($create){
     316                $this->logger(sprintf('sync_iz_products_process: create set to %s', $create));
     317            }
    312318
    313319            $iz_product = $this->get_iz_product($payload);
     
    319325
    320326                if (false === $webhook) {
    321                     $izettle_import_type = get_option('izettle_import_type', 'dry');
     327                    $izettle_import_type = get_option('izettle_import_type', 'merge');
    322328                    $this->dry_run = false !== strpos($izettle_import_type, 'dry');
    323329                    $this->match_only = false !== strpos($izettle_import_type, 'match');
     
    713719                $message = $e->getMessage();
    714720                $this->logger(sprintf('sync_iz_products_process: %s when importing Zettle product', $message, $iz_product->uuid));
    715                 IZ_Notice::add(sprintf('Zettle: %s when importing Zettle product %s', $message, $iz_product->name), 'error');
     721                IZ_Notice::add(sprintf('%s when importing Zettle product %s', $message, $iz_product->name), 'error');
    716722
    717723            }
  • woo-izettle-integration/tags/7.5.0/includes/izettle-integration-product-handler-admin.php

    r2526349 r2638457  
    4242        public function show_izettle_fields_variable($loop, $variation_data, $variation)
    4343        {
     44            global $thepostid;
    4445            if ($this->is_default_language($thepostid)) {
    4546                include 'views/html-product-data-inventory-variable.php';
  • woo-izettle-integration/tags/7.5.0/includes/izettle-integration-product-handler.php

    r2602846 r2638457  
    385385                } else {
    386386
     387                    // Use Zettle if available - sale price if not - regular price if not
     388                    if('_sale_special') {
     389                        if(($meta_price = $product->get_meta('_izettle_special_price', true, 'edit'))){
     390                            $price = str_replace(',', '.', $meta_price);
     391                            WC_IZ()->logger->add(sprintf('get_price (%s): Using special price %s', $product_id, $price));
     392                        }
     393                        elseif($product->is_on_sale('edit')) {
     394                            $sale_price = $product->get_sale_price('edit');
     395                            WC_IZ()->logger->add(sprintf('get_price (%s): Using sale price %s instead of price %s', $product_id, $sale_price, $price));
     396                            $price = $sale_price;
     397                        }
     398                    }
     399
    387400                    // Use the sale price if it is avaliable
    388                     if ('_sale' == $preferred_pricelist) {
     401                    elseif ('_sale' == $preferred_pricelist) {
    389402
    390403                        if ($product->is_on_sale('edit')) {
     
    459472            }
    460473
     474            if(strlen($sku) > 64){
     475                throw new IZ_Integration_Exception(sprintf('SKU %s longer than 64 bytes', $sku));
     476            }
     477
    461478            return $sku;
    462479
     
    597614
    598615            if (false !== $tax_rate) {
    599                 $variant["vatPercentage"] = $tax_rate;
     616                if (false === WC_Zettle_Helper::get_tax_settings()) {
     617                    $variant["vatPercentage"] = $tax_rate;
     618                }
    600619            }
    601620
     
    744763            }
    745764
    746             $task_object = is_object($task_object) ? $task_object : json_decode(json_encode($task_object));
     765            $task_object = is_object($task_object) ? $task_object : json_decode(json_encode($task_object, JSON_INVALID_UTF8_IGNORE));
    747766
    748767            $product_id = $task_object->product_id;
     
    781800                    $product_type = $product->get_type();
    782801
     802                    $sync_in_stock_only = wc_string_to_bool(get_option('izettle_sync_in_stock_only'));
     803
    783804                    if ('variable' == $product_type) {
    784805
    785                         if ('yes' == get_option('izettle_sync_in_stock_only')) {
     806                        if ($sync_in_stock_only) {
    786807                            $variations = $product->get_available_variations();
    787808                        } else {
     
    821842                                    $variation = wc_get_product($variation['variation_id']);
    822843                                }
     844                                $variation_id = $variation->get_id();
    823845
    824846                                if ($variation->get_meta('_izettle_nosync', true, 'edit') == 'yes') {
    825                                     WC_IZ()->logger->add(sprintf('add_or_update_izettle_product (%s): Variation %s marked not to sync to Zettle', $product_id, $variation->get_id()));
     847
     848                                    WC_IZ()->logger->add(sprintf('add_or_update_izettle_product (%s): Variation %s marked not to sync to Zettle', $product_id, $variation_id));
     849
     850                                } elseif ($sync_in_stock_only && !$variation->is_in_stock('edit')) {
     851
     852                                    WC_IZ()->logger->add(sprintf('add_or_update_izettle_product (%s): Variation %s had no stock and will not sync', $product_id, $variation_id));
     853
    826854                                } else {
     855
    827856                                    $variant_array = $this->izettle_variant_array(
    828857                                        $variation
     
    832861                                    $changed_variation = $this->maybe_set_product_uuid($changed_variation, $variation, $product_uuid);
    833862                                    $changed_variation = $this->maybe_set_variant_uuid($changed_variation, $variation, $variant_array['uuid']);
    834 
    835863                                }
    836864
    837865                                if (true === $changed_variation) {
    838866                                    $variation->save();
    839                                     WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Created variation %s with UUID %s', $product_id, $variation->get_id(), $variant_array['uuid']));
     867                                    WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Created variation %s with UUID %s', $product_id, $variation_id, $variant_array['uuid']));
    840868                                }
    841869
     
    854882                            );
    855883
    856                             WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Create variable "%s"', $product_id, json_encode($iz_product)));
     884                            WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Create variable "%s"', $product_id, json_encode($iz_product, JSON_INVALID_UTF8_IGNORE)));
    857885
    858886                            $product_response = izettle_api()->create_product(
     
    881909
    882910                                    WC_IZ()->logger->add(sprintf('add_or_update_izettle_product (%s): Variation %s marked not to sync to Zettle', $product_id, $variation_id));
     911
     912                                } elseif ($sync_in_stock_only && !$variation->is_in_stock('edit')) {
     913
     914                                    WC_IZ()->logger->add(sprintf('add_or_update_izettle_product (%s): Variation %s had no stock and will not sync', $product_id, $variation_id));
    883915
    884916                                } else {
     
    933965                            if ($this->is_product_changed($iz_product, $existing_product)) {
    934966
    935                                 WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Update variable "%s"', $product_id, json_encode($iz_product)));
     967                                WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Update variable "%s"', $product_id, json_encode($iz_product, JSON_INVALID_UTF8_IGNORE)));
    936968
    937969                                $product_response = izettle_api()->update_product(
     
    9821014                            $this->changed = $this->maybe_set_variant_uuid($this->changed, $product, $variant_array['uuid']);
    9831015
    984                             WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Create simple "%s"', $product_id, json_encode($iz_product)));
     1016                            WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Create simple "%s"', $product_id, json_encode($iz_product, JSON_INVALID_UTF8_IGNORE)));
    9851017
    9861018                            $product_response = izettle_api()->create_product(
     
    10151047                            if ($this->is_product_changed($iz_product, $existing_product)) {
    10161048
    1017                                 WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Update simple "%s"', $product_id, json_encode($iz_product)));
     1049                                WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Update simple "%s"', $product_id, json_encode($iz_product, JSON_INVALID_UTF8_IGNORE)));
    10181050
    10191051                                $product_response = izettle_api()->update_product(
     
    10771109                    $message = $e->getMessage();
    10781110                    WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): "%s" when creating Zettle product', $product_id, $message));
     1111                    IZ_Notice::add(sprintf('%s when creating Zettle product from WooCommerce product %s', $message, $product_id), 'error');
    10791112                }
    10801113
     
    15571590        {
    15581591
    1559             $task_object = is_object($task_object) ? $task_object : json_decode(json_encode($task_object));
     1592            $task_object = is_object($task_object) ? $task_object : json_decode(json_encode($task_object, JSON_INVALID_UTF8_IGNORE));
    15601593
    15611594            if (is_admin() && 'yes' == get_option('izettle_do_not_queue_admin_updates')) {
     
    16381671            }
    16391672
    1640             WC_IZ()->logger->add(sprintf('sync_wc_products: Using product args %s', json_encode($args), true));
     1673            WC_IZ()->logger->add(sprintf('sync_wc_products: Using product args %s', json_encode($args, JSON_INVALID_UTF8_IGNORE), true));
    16411674
    16421675            $products_ids = wc_get_products($args);
    16431676
    1644             WC_IZ()->logger->add(sprintf('sync_wc_products: Get product id:s %s', json_encode($products_ids), true));
     1677            WC_IZ()->logger->add(sprintf('sync_wc_products: Get product id:s %s', json_encode($products_ids, JSON_INVALID_UTF8_IGNORE), true));
    16451678
    16461679            $total_to_sync = count($products_ids);
  • woo-izettle-integration/tags/7.5.0/includes/izettle-integration-purchase-handler.php

    r2592459 r2638457  
    7676                if (count($actions) > 1) {
    7777
    78                     as_unschedule_action('wciz_sync_iz_purchases_action');
    79 
     78                    try{
     79                        as_unschedule_action('wciz_sync_iz_purchases_action');
     80                    }catch(\Throwable $throwable){
     81                        WC_IZ()->logger->add(sprintf('schedule_sync_izettle_purchases - No process to unschedule'));
     82                    }
    8083                }
    8184
     
    9598
    9699                if (false !== as_next_scheduled_action('wciz_sync_iz_purchases_action')) {
    97                     as_unschedule_all_actions('wciz_sync_iz_purchases_action');
     100
     101                    try{
     102                        as_unschedule_all_actions('wciz_sync_iz_purchases_action');
     103                    }catch(\Throwable $throwable){
     104                        WC_IZ()->logger->add(sprintf('schedule_heartbeat_sync - No process to unschedule'));
     105                    }
    98106                }
    99107
    100108                if (false !== as_next_scheduled_action('wciz_sync_iz_purchases_action_daily')) {
    101                     as_unschedule_all_actions('wciz_sync_iz_purchases_action_daily');
     109                    try{
     110                        as_unschedule_all_actions('wciz_sync_iz_purchases_action_daily');
     111                    }catch(\Throwable $throwable){
     112                        WC_IZ()->logger->add(sprintf('schedule_sync_izettle_purchases - No process to unschedule'));
     113                    }
    102114                }
    103115
     
    390402                                                }
    391403
     404                                            } else {
     405
     406                                                $new_stock = wc_update_product_stock($product, $purchase_product->quantity, $reverse ? 'increase' : 'decrease');
     407                                                $this->document_changes($post_id, $purchase->purchaseNumber, $reverse ? 'reverse' : 'wc_stockchange', sprintf(__('Product not tracked, stocklevel for %s (%s) changed from %s to %s', 'woo-izettle-integration'), $product_name, $product_id, $current_stock, $new_stock));
     408
    392409                                            }
    393410                                        }
     
    727744                    self::$order_id = $order_id;
    728745
    729                     WC_IZ()->logger->add(sprintf('process_purchase_wc_order: got purchase %s', json_encode($purchase)));
     746                    WC_IZ()->logger->add(sprintf('process_purchase_wc_order: got purchase %s', json_encode($purchase, JSON_INVALID_UTF8_IGNORE)));
    730747
    731748                    $order_tax_values = array();
  • woo-izettle-integration/tags/7.5.0/includes/izettle-purchase-transaction-post.php

    r2568813 r2638457  
    153153            $item = izettle_api()->get_purchase($uuid);
    154154
    155             WC_IZ()->logger->add(sprintf('insert_post: got purchase change %s', json_encode($item)));
     155            WC_IZ()->logger->add(sprintf('insert_post: got purchase change %s', json_encode($item, JSON_INVALID_UTF8_IGNORE)));
    156156
    157157            if (apply_filters('zettle_before_insert_purchase_post', true, $item, $post)) {
  • woo-izettle-integration/tags/7.5.0/includes/izettle-stock-level-handler.php

    r2592459 r2638457  
    149149
    150150                $stock_quantity = $product->get_stock_quantity('view');
    151                 $wc_level = $stock_quantity ? $stock_quantity : 0;
     151                $wc_level = is_numeric($stock_quantity) ? $stock_quantity : 0;
    152152
    153153                $product_uuid = $product->get_meta('woocommerce_izettle_product_uuid', true);
     
    300300            do_action('izettle_remove_product_update_actions');
    301301
    302             WC_IZ()->logger->add(sprintf('received_inventory_balance_changed: got balance change %s', json_encode($change_record)));
    303 
    304             $change_record = is_object($change_record) ? $change_record : json_decode(json_encode($change_record));
     302            WC_IZ()->logger->add(sprintf('received_inventory_balance_changed: got balance change %s', json_encode($change_record, JSON_INVALID_UTF8_IGNORE)));
     303
     304            $change_record = is_object($change_record) ? $change_record : json_decode(json_encode($change_record, JSON_INVALID_UTF8_IGNORE));
    305305
    306306            if (isset($change_record->change_record_key)) {
  • woo-izettle-integration/tags/7.5.0/woo-izettle-integration.php

    r2602846 r2638457  
    1414 * Plugin Name:       WooCommerce Zettle Integration
    1515 * Plugin URI:        https://www.bjorntech.com/woocommerce-zettle/?utm_source=wp-izettle&utm_medium=plugin&utm_campaign=product
    16  * Description:       Syncronizes products, purchases and stock-levels.
    17  * Version:           7.4.2
     16 * Description:       Synchronizes products, purchases and stock levels.
     17 * Version:           7.5.0
    1818 * Author:            BjornTech AB
    1919 * Author URI:        https://www.bjorntech.com/?utm_source=wp-izettle&utm_medium=plugin&utm_campaign=product
     
    2121 *
    2222 * WC requires at least: 4.0
    23  * WC tested up to: 5.7
     23 * WC tested up to: 5.9
    2424 *
    2525 * Copyright:         2017-2020 BjornTech AB
     
    7373     */
    7474    const NAME = 'WooCommerce Zettle Integration';
    75     const VERSION = '7.4.2';
     75    const VERSION = '7.5.0';
    7676    const SCRIPT_HANDLE = 'wc-izettle-integration';
    7777    const PLUGIN_FILE = __FILE__;
     
    376376                'version' => $this->version,
    377377            );
    378             $encoded_params = base64_encode(json_encode($site_params));
     378            $encoded_params = base64_encode(json_encode($site_params, JSON_INVALID_UTF8_IGNORE));
    379379            $client_id = $this->client_id;
    380380            $state = array(
     
    428428
    429429        } elseif ('start' == $_POST['task']) {
    430 
    431             as_unschedule_all_actions($id . '_process');
     430            try{
     431                as_unschedule_all_actions($id . '_process');
     432            }catch(\Throwable $throwable){
     433                WC_IZ()->logger->add(sprintf('ajax_wciz_processing_button - No process to unschedule'));
     434            }
    432435            $response = array(
    433436                'status' => 'success',
     
    476479            delete_site_transient('zettle_tax_rates');
    477480            delete_site_transient('zettle_tax_settings');
    478             IZ_Notice::add('Zettle: New token requested from service', 'success');
     481            IZ_Notice::add('New token requested from service', 'success');
    479482
    480483        } catch (IZ_Integration_API_Exception $e) {
    481484
    482485            $e->write_to_logs();
    483             IZ_Notice::add('Zettle: Error when connecting to service, check logs', 'success');
     486            IZ_Notice::add('Error when connecting to service, check logs', 'success');
    484487
    485488        }
     
    623626    {
    624627        $webhook_signing_key = izettle_api()->get_webhook_signing_key();
    625         WC_IZ()->logger->add(sprintf('Webhook signing key %s',$webhook_signing_key));
     628        WC_IZ()->logger->add(sprintf('Webhook signing key %s', $webhook_signing_key));
    626629        return hash_hmac(
    627630            'sha256',
     
    643646                    if (wc_string_to_bool(get_option('zettle_enable_purchase_processing')) && 1 == get_option('izettle_purchase_sync_model')) {
    644647                        $payload = json_decode($request['payload']);
     648                        WC_IZ()->logger->add(sprintf('received_webhook_call: Entering PurchaseCreated'));
    645649                        do_action('izettle_add_purchase_to_queue', $payload->purchaseUuid, true);
    646650                    } else {
     
    653657                        $payload = json_decode($request['payload']);
    654658                        if (!get_site_transient('izettle_stocklevel_update' . $payload->externalUuid)) {
     659                            WC_IZ()->logger->add(sprintf('received_webhook_call: Entering InventoryBalanceChanged'));
    655660                            do_action('izettle_received_inventory_balance_changed_add', $payload, $request['messageId'], true);
    656661                        } else {
     
    664669                        if ($payload = json_decode($request['payload'])) {
    665670                            if (!isset($payload->externalReference)) {
     671                                WC_IZ()->logger->add(sprintf('received_webhook_call: Entering ProductCreated'));
    666672                                do_action('izettle_sync_products_from_izettle_add', $payload, $request['messageId'], true);
    667673                            } else {
     
    676682                        if ($payload = json_decode($request['payload'])) {
    677683                            if (!isset($payload->newEntity->externalReference) || $payload->newEntity->etag != get_post_meta(WC_Zettle_Helper::get_id($payload->newEntity->externalReference), '_izettle_product_etag', true)) {
     684                                WC_IZ()->logger->add(sprintf('received_webhook_call: Entering ProductUpdated'));
    678685                                do_action('izettle_sync_products_from_izettle_add', $payload, $request['messageId'], true, false);
    679686                            } else {
     
    687694                    if (false !== strpos(get_option('izettle_when_changed_in_izettle'), 'delete')) {
    688695                        if ($payload = json_decode($request['payload'])) {
     696                            WC_IZ()->logger->add(sprintf('received_webhook_call: Entering ProductDeleted'));
    689697                            do_action('izettle_delete_product_from_izettle', $payload->uuid, get_option('izettle_force_delete_in_woocommerce') == 'yes');
    690698                        }
     
    695703                    if (WC_Zettle_Helper::zettle_changes_stock()) {
    696704                        if ($payload = json_decode($request['payload'])) {
     705                            WC_IZ()->logger->add(sprintf('received_webhook_call: Entering InventoryTrackingStarted'));
    697706                            do_action('izettle_received_inventory_tracking_started_add', $payload, $request['messageId'], true);
    698707                        }
     
    703712                    if (WC_Zettle_Helper::zettle_changes_stock()) {
    704713                        if ($payload = json_decode($request['payload'])) {
     714                            WC_IZ()->logger->add(sprintf('received_webhook_call: Entering InventoryTrackingStopped'));
    705715                            do_action('izettle_received_inventory_tracking_stopped_add', $payload, $request['messageId'], true);
    706716                        }
  • woo-izettle-integration/trunk/README.txt

    r2602846 r2638457  
    55Tested up to: 5.8
    66Requires PHP: 7.3
    7 Stable tag: 7.4.2
     7Stable tag: 7.5.0
    88License: GPLv3 or later
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    118118
    119119== Changelog ==
     120= 7.5.0 =
     121* The plugin is verified to work with WooCommerce 5.9
     122* New: Added option for prioritizing Zettle price above Sale price
     123* Fix: Changed import type to Merge products as default
     124* Fix: Error thrown if SKU is too long
     125* Fix: Notices failing to show up
     126* Fix: Variations out of stock were synced even when configured not to
     127* Fix: Added timestamp to notices
     128* Fix: Failing to unschedule actions causing error
     129* Fix: thepostid variable not declared causing warnings
     130* Fix: Wrong number of parameters in the update of products from zettle caused products to be created although setting was set to only update.
    120131= 7.4.2 =
    121132* The plugin is verified to work with WooCommerce 5.7
  • woo-izettle-integration/trunk/includes/admin/izettle-integration-helper.php

    r2602846 r2638457  
    426426        public static function object_diff(stdClass $obj1, stdClass $obj2): bool
    427427        {
    428             $array1 = json_decode(json_encode($obj1), true);
    429             $array2 = json_decode(json_encode($obj2), true);
     428            $array1 = json_decode(json_encode($obj1, JSON_INVALID_UTF8_IGNORE), true);
     429            $array2 = json_decode(json_encode($obj2, JSON_INVALID_UTF8_IGNORE), true);
    430430            return self::array_diff($array1, $array2);
    431431        }
     
    512512        {
    513513            if (!is_array($object)) {
    514                 $object = json_decode(json_encode($object), true);
     514                $object = json_decode(json_encode($object, JSON_INVALID_UTF8_IGNORE), true);
    515515            }
    516516            unset($object['etag']);
     
    518518            unset($object['updatedBy']);
    519519            self::ksort_recursive($object);
    520             WC_IZ()->logger->add(print_r(json_encode($object), true));
     520            WC_IZ()->logger->add(print_r(json_encode($object, JSON_INVALID_UTF8_IGNORE), true));
    521521            return md5(json_encode((object) $object));
    522522        }
     
    885885                if (false === $tax_rates) {
    886886                    $tax_rates = izettle_api()->get_tax_rates();
    887                     WC_IZ()->logger->add(sprintf('get_rates: "%s"', json_encode($tax_rates)));
     887                    WC_IZ()->logger->add(sprintf('get_rates: "%s"', json_encode($tax_rates, JSON_INVALID_UTF8_IGNORE)));
    888888                    set_site_transient('zettle_tax_rates', $tax_rates, DAY_IN_SECONDS);
    889889                }
     
    958958                if (false === $tax_settings) {
    959959                    $tax_settings = izettle_api()->get_tax_settings();
    960                     WC_IZ()->logger->add(sprintf('get_tax_settings: "%s"', json_encode($tax_settings)));
     960                    WC_IZ()->logger->add(sprintf('get_tax_settings: "%s"', json_encode($tax_settings, JSON_INVALID_UTF8_IGNORE)));
    961961                    set_site_transient('zettle_tax_settings', $tax_settings, DAY_IN_SECONDS);
    962962                }
  • woo-izettle-integration/trunk/includes/admin/izettle-integration-notices.php

    r2526349 r2638457  
    6262
    6363            $notices[$id] = $notice;
     64
    6465            set_site_transient('izettle_notices', $notices);
    6566
     
    7071        {
    7172
    72         /*    if (WC_Zettle_Helper::wc_version_check('4.0.0')) {
    73                 require_once dirname(__FILE__) . '/izettle-admin-notes.php';
    74                 \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_iZettle::clear($id);
     73            /*    if (WC_Zettle_Helper::wc_version_check('4.0.0')) {
     74            require_once dirname(__FILE__) . '/izettle-admin-notes.php';
     75            \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_iZettle::clear($id);
    7576            }*/
    7677
    7778            $notices = get_site_transient('izettle_notices');
    78             if ($id && isset($notices[$id])) {
    79                 unset($notices[$id]);
     79            if ($id) {
     80                if (isset($notices[$id])) {
     81                    unset($notices[$id]);
     82                }
    8083            } else {
    8184                $notices = array();
     
    8790        {
    8891            $dismissable = $dismiss ? 'is-dismissible' : '';
     92            $date = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), date('U') + (get_option('gmt_offset') * HOUR_IN_SECONDS));
     93            $message = $date . ' - Zettle: ' . $message;
    8994            echo '<div class="iz_notice ' . $dismissable . ' notice notice-' . $type . ' ' . $id . '"><p>' . $message . '</p></div>';
    9095        }
     
    9398        {
    9499            $notices = get_site_transient('izettle_notices');
    95 
    96100            if (false !== $notices && !empty($notices)) {
    97101                foreach ($notices as $key => $notice) {
  • woo-izettle-integration/trunk/includes/admin/settings/views/html-admin-settings-products-from-izettle-options-desc.php

    r2526349 r2638457  
    4444    <?php _e('<b>Create and update products in WooCommerce</b> - Both the Create and Update above will happen.', 'woo-izettle-integration');?>
    4545    </li>
     46    <li>
     47    <?php _e('<b>Create, update and delete products in WooCommerce</b> - Both the Create and Update above will happen. Furthermore, products deleted in Zettle will also be deleted in WooCommerce.', 'woo-izettle-integration');?>
     48    </li>
    4649    </ul>
    4750    <p>
  • woo-izettle-integration/trunk/includes/admin/settings/wc-settings-page-izettle.php

    r2602846 r2638457  
    281281            $pricelists = array(
    282282                '' => __('Regular price', 'woocommerce'),
    283                 '_sale' => __('Sale price if available (Regular if not)', 'woo-izettle-integration'),
    284                 '_special' => __('Zettle price from the Zettle tab if available (Regular if not)', 'woo-izettle-integration'),
     283                '_sale' => __('Sale price if available - Regular if not', 'woo-izettle-integration'),
     284                '_special' => __('Zettle price from the Zettle tab if available - Regular if not', 'woo-izettle-integration'),
     285                '_sale_special' => __('Zettle price from Zettle tab if available - Sale price if not - Regular price if not', 'woo-izettle-integration'),
    285286                '_no_price' => __('Do not set the price', 'woo-izettle-integration'),
    286287            );
     
    708709                        'type' => 'select',
    709710                        'desc' => __('Select type of manual import.', 'woo-izettle-integration'),
    710                         'default' => 'dry',
     711                        'default' => 'merge',
    711712                        'options' => array(
    712713                            'dry' => __('Dry run full import', 'woo-izettle-integration'),
    713                             'merge' => __('Merge products', 'woo-izettle-integration'),
     714                            'merge' => __('Merge products (recommended)', 'woo-izettle-integration'),
    714715                            'new' => __('Create all products', 'woo-izettle-integration'),
    715716                            'match_dry' => __('Dry run matching only', 'woo-izettle-integration'),
  • woo-izettle-integration/trunk/includes/api/izettle-integration-api.php

    r2602846 r2638457  
    130130                        $args['body'] = $form;
    131131                    } else {
    132                         $json_body = json_encode($form);
     132                        $json_body = json_encode($form, JSON_INVALID_UTF8_IGNORE);
    133133                        if (!$json_body) {
    134134                            $json_error = json_last_error();
     
    166166
    167167                if (($http_code = wp_remote_retrieve_response_code($response)) > 299) {
    168                     $message = isset($data->developerMessage) ? $data->developerMessage : 'Error when connecting to Zettle';
     168
     169                    if (isset($data->violations)) {
     170                        $violatons = reset($data->violations);
     171                        $message = $violatons->developerMessage;
     172                    } elseif (isset($data->developerMessage)) {
     173                        $message = $data->developerMessage;
     174                    } else {
     175                        $message = __('Unknown error when connecting to Zettle', 'woo-izettle-integration');
     176                    }
     177
    169178                    throw new IZ_Integration_API_Exception($message, $http_code);
    170179                }
  • woo-izettle-integration/trunk/includes/izettle-integration-authorization.php

    r2526349 r2638457  
    148148                );
    149149                if (count($actions) > 1) {
    150                     as_unschedule_action('izettle_service_heartbeat');
     150                    try{
     151                        as_unschedule_action('izettle_service_heartbeat');
     152                    }catch(\Throwable $throwable){
     153                        WC_IZ()->logger->add(sprintf('schedule_heartbeat_sync - No process to unschedule'));
     154                    }
    151155                }
    152156            } else {
    153157                if (false !== as_next_scheduled_action('izettle_service_heartbeat')) {
    154                     as_unschedule_all_actions('izettle_service_heartbeat');
     158                    try{
     159                        as_unschedule_all_actions('izettle_service_heartbeat');
     160                    }catch(\Throwable $throwable){
     161                        WC_IZ()->logger->add(sprintf('schedule_heartbeat_sync - No process to unschedule'));
     162                    }
    155163                }
    156164            }
  • woo-izettle-integration/trunk/includes/izettle-integration-iz-products.php

    r2602846 r2638457  
    3939            add_filter('wciz_sync_iz_products_filter', array($this, 'sync_iz_products'), 10, 2);
    4040            add_action('wciz_sync_iz_products_action', array($this, 'sync_iz_products'), 10, 2);
    41             add_action('wciz_sync_iz_products_process', array($this, 'sync_iz_products_process'), 10, 3);
     41            add_action('wciz_sync_iz_products_process', array($this, 'sync_iz_products_process'), 10, 4);
    4242
    4343        }
     
    297297        {
    298298
     299
     300
    299301            if (false !== $payload) {
    300                 $payload = is_object($payload) ? $payload : json_decode(json_encode($payload));
     302                $payload = is_object($payload) ? $payload : json_decode(json_encode($payload, JSON_INVALID_UTF8_IGNORE));
    301303            } else {
    302304                if ($payload = get_site_transient('sync_products_from_izettle_' . $key)) {
     
    309311            }
    310312
    311             $this->logger(sprintf('sync_iz_products_process: got %s payload %s', $webhook ? 'webhook' : 'import', json_encode($payload)));
     313            $this->logger(sprintf('sync_iz_products_process: got %s payload %s', $webhook ? 'webhook' : 'import', json_encode($payload, JSON_INVALID_UTF8_IGNORE)));
     314
     315            if($create){
     316                $this->logger(sprintf('sync_iz_products_process: create set to %s', $create));
     317            }
    312318
    313319            $iz_product = $this->get_iz_product($payload);
     
    319325
    320326                if (false === $webhook) {
    321                     $izettle_import_type = get_option('izettle_import_type', 'dry');
     327                    $izettle_import_type = get_option('izettle_import_type', 'merge');
    322328                    $this->dry_run = false !== strpos($izettle_import_type, 'dry');
    323329                    $this->match_only = false !== strpos($izettle_import_type, 'match');
     
    713719                $message = $e->getMessage();
    714720                $this->logger(sprintf('sync_iz_products_process: %s when importing Zettle product', $message, $iz_product->uuid));
    715                 IZ_Notice::add(sprintf('Zettle: %s when importing Zettle product %s', $message, $iz_product->name), 'error');
     721                IZ_Notice::add(sprintf('%s when importing Zettle product %s', $message, $iz_product->name), 'error');
    716722
    717723            }
  • woo-izettle-integration/trunk/includes/izettle-integration-product-handler-admin.php

    r2526349 r2638457  
    4242        public function show_izettle_fields_variable($loop, $variation_data, $variation)
    4343        {
     44            global $thepostid;
    4445            if ($this->is_default_language($thepostid)) {
    4546                include 'views/html-product-data-inventory-variable.php';
  • woo-izettle-integration/trunk/includes/izettle-integration-product-handler.php

    r2602846 r2638457  
    385385                } else {
    386386
     387                    // Use Zettle if available - sale price if not - regular price if not
     388                    if('_sale_special') {
     389                        if(($meta_price = $product->get_meta('_izettle_special_price', true, 'edit'))){
     390                            $price = str_replace(',', '.', $meta_price);
     391                            WC_IZ()->logger->add(sprintf('get_price (%s): Using special price %s', $product_id, $price));
     392                        }
     393                        elseif($product->is_on_sale('edit')) {
     394                            $sale_price = $product->get_sale_price('edit');
     395                            WC_IZ()->logger->add(sprintf('get_price (%s): Using sale price %s instead of price %s', $product_id, $sale_price, $price));
     396                            $price = $sale_price;
     397                        }
     398                    }
     399
    387400                    // Use the sale price if it is avaliable
    388                     if ('_sale' == $preferred_pricelist) {
     401                    elseif ('_sale' == $preferred_pricelist) {
    389402
    390403                        if ($product->is_on_sale('edit')) {
     
    459472            }
    460473
     474            if(strlen($sku) > 64){
     475                throw new IZ_Integration_Exception(sprintf('SKU %s longer than 64 bytes', $sku));
     476            }
     477
    461478            return $sku;
    462479
     
    597614
    598615            if (false !== $tax_rate) {
    599                 $variant["vatPercentage"] = $tax_rate;
     616                if (false === WC_Zettle_Helper::get_tax_settings()) {
     617                    $variant["vatPercentage"] = $tax_rate;
     618                }
    600619            }
    601620
     
    744763            }
    745764
    746             $task_object = is_object($task_object) ? $task_object : json_decode(json_encode($task_object));
     765            $task_object = is_object($task_object) ? $task_object : json_decode(json_encode($task_object, JSON_INVALID_UTF8_IGNORE));
    747766
    748767            $product_id = $task_object->product_id;
     
    781800                    $product_type = $product->get_type();
    782801
     802                    $sync_in_stock_only = wc_string_to_bool(get_option('izettle_sync_in_stock_only'));
     803
    783804                    if ('variable' == $product_type) {
    784805
    785                         if ('yes' == get_option('izettle_sync_in_stock_only')) {
     806                        if ($sync_in_stock_only) {
    786807                            $variations = $product->get_available_variations();
    787808                        } else {
     
    821842                                    $variation = wc_get_product($variation['variation_id']);
    822843                                }
     844                                $variation_id = $variation->get_id();
    823845
    824846                                if ($variation->get_meta('_izettle_nosync', true, 'edit') == 'yes') {
    825                                     WC_IZ()->logger->add(sprintf('add_or_update_izettle_product (%s): Variation %s marked not to sync to Zettle', $product_id, $variation->get_id()));
     847
     848                                    WC_IZ()->logger->add(sprintf('add_or_update_izettle_product (%s): Variation %s marked not to sync to Zettle', $product_id, $variation_id));
     849
     850                                } elseif ($sync_in_stock_only && !$variation->is_in_stock('edit')) {
     851
     852                                    WC_IZ()->logger->add(sprintf('add_or_update_izettle_product (%s): Variation %s had no stock and will not sync', $product_id, $variation_id));
     853
    826854                                } else {
     855
    827856                                    $variant_array = $this->izettle_variant_array(
    828857                                        $variation
     
    832861                                    $changed_variation = $this->maybe_set_product_uuid($changed_variation, $variation, $product_uuid);
    833862                                    $changed_variation = $this->maybe_set_variant_uuid($changed_variation, $variation, $variant_array['uuid']);
    834 
    835863                                }
    836864
    837865                                if (true === $changed_variation) {
    838866                                    $variation->save();
    839                                     WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Created variation %s with UUID %s', $product_id, $variation->get_id(), $variant_array['uuid']));
     867                                    WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Created variation %s with UUID %s', $product_id, $variation_id, $variant_array['uuid']));
    840868                                }
    841869
     
    854882                            );
    855883
    856                             WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Create variable "%s"', $product_id, json_encode($iz_product)));
     884                            WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Create variable "%s"', $product_id, json_encode($iz_product, JSON_INVALID_UTF8_IGNORE)));
    857885
    858886                            $product_response = izettle_api()->create_product(
     
    881909
    882910                                    WC_IZ()->logger->add(sprintf('add_or_update_izettle_product (%s): Variation %s marked not to sync to Zettle', $product_id, $variation_id));
     911
     912                                } elseif ($sync_in_stock_only && !$variation->is_in_stock('edit')) {
     913
     914                                    WC_IZ()->logger->add(sprintf('add_or_update_izettle_product (%s): Variation %s had no stock and will not sync', $product_id, $variation_id));
    883915
    884916                                } else {
     
    933965                            if ($this->is_product_changed($iz_product, $existing_product)) {
    934966
    935                                 WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Update variable "%s"', $product_id, json_encode($iz_product)));
     967                                WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Update variable "%s"', $product_id, json_encode($iz_product, JSON_INVALID_UTF8_IGNORE)));
    936968
    937969                                $product_response = izettle_api()->update_product(
     
    9821014                            $this->changed = $this->maybe_set_variant_uuid($this->changed, $product, $variant_array['uuid']);
    9831015
    984                             WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Create simple "%s"', $product_id, json_encode($iz_product)));
     1016                            WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Create simple "%s"', $product_id, json_encode($iz_product, JSON_INVALID_UTF8_IGNORE)));
    9851017
    9861018                            $product_response = izettle_api()->create_product(
     
    10151047                            if ($this->is_product_changed($iz_product, $existing_product)) {
    10161048
    1017                                 WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Update simple "%s"', $product_id, json_encode($iz_product)));
     1049                                WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): Update simple "%s"', $product_id, json_encode($iz_product, JSON_INVALID_UTF8_IGNORE)));
    10181050
    10191051                                $product_response = izettle_api()->update_product(
     
    10771109                    $message = $e->getMessage();
    10781110                    WC_IZ()->logger->add(sprintf('sync_wc_products_process (%s): "%s" when creating Zettle product', $product_id, $message));
     1111                    IZ_Notice::add(sprintf('%s when creating Zettle product from WooCommerce product %s', $message, $product_id), 'error');
    10791112                }
    10801113
     
    15571590        {
    15581591
    1559             $task_object = is_object($task_object) ? $task_object : json_decode(json_encode($task_object));
     1592            $task_object = is_object($task_object) ? $task_object : json_decode(json_encode($task_object, JSON_INVALID_UTF8_IGNORE));
    15601593
    15611594            if (is_admin() && 'yes' == get_option('izettle_do_not_queue_admin_updates')) {
     
    16381671            }
    16391672
    1640             WC_IZ()->logger->add(sprintf('sync_wc_products: Using product args %s', json_encode($args), true));
     1673            WC_IZ()->logger->add(sprintf('sync_wc_products: Using product args %s', json_encode($args, JSON_INVALID_UTF8_IGNORE), true));
    16411674
    16421675            $products_ids = wc_get_products($args);
    16431676
    1644             WC_IZ()->logger->add(sprintf('sync_wc_products: Get product id:s %s', json_encode($products_ids), true));
     1677            WC_IZ()->logger->add(sprintf('sync_wc_products: Get product id:s %s', json_encode($products_ids, JSON_INVALID_UTF8_IGNORE), true));
    16451678
    16461679            $total_to_sync = count($products_ids);
  • woo-izettle-integration/trunk/includes/izettle-integration-purchase-handler.php

    r2592459 r2638457  
    7676                if (count($actions) > 1) {
    7777
    78                     as_unschedule_action('wciz_sync_iz_purchases_action');
    79 
     78                    try{
     79                        as_unschedule_action('wciz_sync_iz_purchases_action');
     80                    }catch(\Throwable $throwable){
     81                        WC_IZ()->logger->add(sprintf('schedule_sync_izettle_purchases - No process to unschedule'));
     82                    }
    8083                }
    8184
     
    9598
    9699                if (false !== as_next_scheduled_action('wciz_sync_iz_purchases_action')) {
    97                     as_unschedule_all_actions('wciz_sync_iz_purchases_action');
     100
     101                    try{
     102                        as_unschedule_all_actions('wciz_sync_iz_purchases_action');
     103                    }catch(\Throwable $throwable){
     104                        WC_IZ()->logger->add(sprintf('schedule_heartbeat_sync - No process to unschedule'));
     105                    }
    98106                }
    99107
    100108                if (false !== as_next_scheduled_action('wciz_sync_iz_purchases_action_daily')) {
    101                     as_unschedule_all_actions('wciz_sync_iz_purchases_action_daily');
     109                    try{
     110                        as_unschedule_all_actions('wciz_sync_iz_purchases_action_daily');
     111                    }catch(\Throwable $throwable){
     112                        WC_IZ()->logger->add(sprintf('schedule_sync_izettle_purchases - No process to unschedule'));
     113                    }
    102114                }
    103115
     
    390402                                                }
    391403
     404                                            } else {
     405
     406                                                $new_stock = wc_update_product_stock($product, $purchase_product->quantity, $reverse ? 'increase' : 'decrease');
     407                                                $this->document_changes($post_id, $purchase->purchaseNumber, $reverse ? 'reverse' : 'wc_stockchange', sprintf(__('Product not tracked, stocklevel for %s (%s) changed from %s to %s', 'woo-izettle-integration'), $product_name, $product_id, $current_stock, $new_stock));
     408
    392409                                            }
    393410                                        }
     
    727744                    self::$order_id = $order_id;
    728745
    729                     WC_IZ()->logger->add(sprintf('process_purchase_wc_order: got purchase %s', json_encode($purchase)));
     746                    WC_IZ()->logger->add(sprintf('process_purchase_wc_order: got purchase %s', json_encode($purchase, JSON_INVALID_UTF8_IGNORE)));
    730747
    731748                    $order_tax_values = array();
  • woo-izettle-integration/trunk/includes/izettle-purchase-transaction-post.php

    r2568813 r2638457  
    153153            $item = izettle_api()->get_purchase($uuid);
    154154
    155             WC_IZ()->logger->add(sprintf('insert_post: got purchase change %s', json_encode($item)));
     155            WC_IZ()->logger->add(sprintf('insert_post: got purchase change %s', json_encode($item, JSON_INVALID_UTF8_IGNORE)));
    156156
    157157            if (apply_filters('zettle_before_insert_purchase_post', true, $item, $post)) {
  • woo-izettle-integration/trunk/includes/izettle-stock-level-handler.php

    r2592459 r2638457  
    149149
    150150                $stock_quantity = $product->get_stock_quantity('view');
    151                 $wc_level = $stock_quantity ? $stock_quantity : 0;
     151                $wc_level = is_numeric($stock_quantity) ? $stock_quantity : 0;
    152152
    153153                $product_uuid = $product->get_meta('woocommerce_izettle_product_uuid', true);
     
    300300            do_action('izettle_remove_product_update_actions');
    301301
    302             WC_IZ()->logger->add(sprintf('received_inventory_balance_changed: got balance change %s', json_encode($change_record)));
    303 
    304             $change_record = is_object($change_record) ? $change_record : json_decode(json_encode($change_record));
     302            WC_IZ()->logger->add(sprintf('received_inventory_balance_changed: got balance change %s', json_encode($change_record, JSON_INVALID_UTF8_IGNORE)));
     303
     304            $change_record = is_object($change_record) ? $change_record : json_decode(json_encode($change_record, JSON_INVALID_UTF8_IGNORE));
    305305
    306306            if (isset($change_record->change_record_key)) {
  • woo-izettle-integration/trunk/woo-izettle-integration.php

    r2602846 r2638457  
    1414 * Plugin Name:       WooCommerce Zettle Integration
    1515 * Plugin URI:        https://www.bjorntech.com/woocommerce-zettle/?utm_source=wp-izettle&utm_medium=plugin&utm_campaign=product
    16  * Description:       Syncronizes products, purchases and stock-levels.
    17  * Version:           7.4.2
     16 * Description:       Synchronizes products, purchases and stock levels.
     17 * Version:           7.5.0
    1818 * Author:            BjornTech AB
    1919 * Author URI:        https://www.bjorntech.com/?utm_source=wp-izettle&utm_medium=plugin&utm_campaign=product
     
    2121 *
    2222 * WC requires at least: 4.0
    23  * WC tested up to: 5.7
     23 * WC tested up to: 5.9
    2424 *
    2525 * Copyright:         2017-2020 BjornTech AB
     
    7373     */
    7474    const NAME = 'WooCommerce Zettle Integration';
    75     const VERSION = '7.4.2';
     75    const VERSION = '7.5.0';
    7676    const SCRIPT_HANDLE = 'wc-izettle-integration';
    7777    const PLUGIN_FILE = __FILE__;
     
    376376                'version' => $this->version,
    377377            );
    378             $encoded_params = base64_encode(json_encode($site_params));
     378            $encoded_params = base64_encode(json_encode($site_params, JSON_INVALID_UTF8_IGNORE));
    379379            $client_id = $this->client_id;
    380380            $state = array(
     
    428428
    429429        } elseif ('start' == $_POST['task']) {
    430 
    431             as_unschedule_all_actions($id . '_process');
     430            try{
     431                as_unschedule_all_actions($id . '_process');
     432            }catch(\Throwable $throwable){
     433                WC_IZ()->logger->add(sprintf('ajax_wciz_processing_button - No process to unschedule'));
     434            }
    432435            $response = array(
    433436                'status' => 'success',
     
    476479            delete_site_transient('zettle_tax_rates');
    477480            delete_site_transient('zettle_tax_settings');
    478             IZ_Notice::add('Zettle: New token requested from service', 'success');
     481            IZ_Notice::add('New token requested from service', 'success');
    479482
    480483        } catch (IZ_Integration_API_Exception $e) {
    481484
    482485            $e->write_to_logs();
    483             IZ_Notice::add('Zettle: Error when connecting to service, check logs', 'success');
     486            IZ_Notice::add('Error when connecting to service, check logs', 'success');
    484487
    485488        }
     
    623626    {
    624627        $webhook_signing_key = izettle_api()->get_webhook_signing_key();
    625         WC_IZ()->logger->add(sprintf('Webhook signing key %s',$webhook_signing_key));
     628        WC_IZ()->logger->add(sprintf('Webhook signing key %s', $webhook_signing_key));
    626629        return hash_hmac(
    627630            'sha256',
     
    643646                    if (wc_string_to_bool(get_option('zettle_enable_purchase_processing')) && 1 == get_option('izettle_purchase_sync_model')) {
    644647                        $payload = json_decode($request['payload']);
     648                        WC_IZ()->logger->add(sprintf('received_webhook_call: Entering PurchaseCreated'));
    645649                        do_action('izettle_add_purchase_to_queue', $payload->purchaseUuid, true);
    646650                    } else {
     
    653657                        $payload = json_decode($request['payload']);
    654658                        if (!get_site_transient('izettle_stocklevel_update' . $payload->externalUuid)) {
     659                            WC_IZ()->logger->add(sprintf('received_webhook_call: Entering InventoryBalanceChanged'));
    655660                            do_action('izettle_received_inventory_balance_changed_add', $payload, $request['messageId'], true);
    656661                        } else {
     
    664669                        if ($payload = json_decode($request['payload'])) {
    665670                            if (!isset($payload->externalReference)) {
     671                                WC_IZ()->logger->add(sprintf('received_webhook_call: Entering ProductCreated'));
    666672                                do_action('izettle_sync_products_from_izettle_add', $payload, $request['messageId'], true);
    667673                            } else {
     
    676682                        if ($payload = json_decode($request['payload'])) {
    677683                            if (!isset($payload->newEntity->externalReference) || $payload->newEntity->etag != get_post_meta(WC_Zettle_Helper::get_id($payload->newEntity->externalReference), '_izettle_product_etag', true)) {
     684                                WC_IZ()->logger->add(sprintf('received_webhook_call: Entering ProductUpdated'));
    678685                                do_action('izettle_sync_products_from_izettle_add', $payload, $request['messageId'], true, false);
    679686                            } else {
     
    687694                    if (false !== strpos(get_option('izettle_when_changed_in_izettle'), 'delete')) {
    688695                        if ($payload = json_decode($request['payload'])) {
     696                            WC_IZ()->logger->add(sprintf('received_webhook_call: Entering ProductDeleted'));
    689697                            do_action('izettle_delete_product_from_izettle', $payload->uuid, get_option('izettle_force_delete_in_woocommerce') == 'yes');
    690698                        }
     
    695703                    if (WC_Zettle_Helper::zettle_changes_stock()) {
    696704                        if ($payload = json_decode($request['payload'])) {
     705                            WC_IZ()->logger->add(sprintf('received_webhook_call: Entering InventoryTrackingStarted'));
    697706                            do_action('izettle_received_inventory_tracking_started_add', $payload, $request['messageId'], true);
    698707                        }
     
    703712                    if (WC_Zettle_Helper::zettle_changes_stock()) {
    704713                        if ($payload = json_decode($request['payload'])) {
     714                            WC_IZ()->logger->add(sprintf('received_webhook_call: Entering InventoryTrackingStopped'));
    705715                            do_action('izettle_received_inventory_tracking_stopped_add', $payload, $request['messageId'], true);
    706716                        }
Note: See TracChangeset for help on using the changeset viewer.