Plugin Directory

Changeset 3366520


Ignore:
Timestamp:
09/23/2025 01:13:23 PM (6 months ago)
Author:
sendcloudbv
Message:

Release version 1.0.16

Location:
sendcloud-connected-shipping
Files:
131 added
10 edited

Legend:

Unmodified
Added
Removed
  • sendcloud-connected-shipping/trunk/changelog.txt

    r3336392 r3366520  
    11*** WooCommerce Sendcloud | The all-in-one shipping platform Changelog ***
     2
     3= 2025-09-24 - version 1.0.16 =
     4* Implement compatibility with WooCommerce's block-based checkout
    25
    36= 2025-07-29 - version 1.0.15 =
  • sendcloud-connected-shipping/trunk/includes/ServicePoint/Checkout/class-checkout-block-handler.php

    r3300820 r3366520  
    3333            2
    3434        );
     35
     36        add_action(
     37            'woocommerce_blocks_loaded',
     38            function() {
     39                woocommerce_store_api_register_update_callback( [
     40                    'namespace' => 'sendcloud-connected-shipping-sp-block',
     41                    'callback'  => function ( $data ) {
     42                        if ( ! empty( $data['servicePoint'] ) ) {
     43                            WC()->session->set( 'sendcloud_service_point', $data['servicePoint'] );
     44                        } else {
     45                            WC()->session->__unset( 'sendcloud_service_point' );
     46                        }
     47                    },
     48                ]);
     49            }
     50        );
    3551    }
    3652
     
    6480     */
    6581    public function validate_and_save(\WC_Order $order, \WP_REST_Request $request) {
    66         /**
    67         * This method will be adjusted after Sendcloud team finishes React.js script
    68         *
    69         * Perhaps we should use woocommerce_store_api_checkout_update_order_from_request action for saving data
    70         * and woocommerce_store_api_checkout_order_processed only for validating
    71         */
    72         $chosen_shipping_methods = wc()->session->get( 'chosen_shipping_methods', '' );
    73         if ( ! $chosen_shipping_methods ) {
    74             return;
    75         }
    76         $shipping_method_id = explode( ':', reset( $chosen_shipping_methods ) )[0];
     82        /**
     83        * This method will be adjusted after Sendcloud team finishes React.js script
     84        *
     85        * Perhaps we should use woocommerce_store_api_checkout_update_order_from_request action for saving data
     86        * and woocommerce_store_api_checkout_order_processed only for validating
     87        */
     88        $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods', '' );
     89        if ( ! $chosen_shipping_methods ) {
     90            return;
     91        }
     92        $shipping_method_id = explode( ':', reset( $chosen_shipping_methods ) )[0];
    7793
    78         if ( Service_Point_Free_Shipping_Method::ID !== $shipping_method_id || empty( $order->get_items( 'shipping' ) ) ) {
    79             return;
    80         }
    81         $nonce                  = $this->get_wp_block_nonce();
    82         $service_point_selected = $this->fetch_service_point_data($request) && $nonce;
     94        if ( Service_Point_Free_Shipping_Method::ID !== $shipping_method_id || empty( $order->get_items( 'shipping' ) ) ) {
     95            return;
     96        }
    8397
    84         if ( ! $service_point_selected ) {
    85             wc_add_notice( esc_html__( 'Please choose a service point.', 'sendcloud-connected-shipping' ), 'error' );
    86         } else {
    87             $order_repository = new SCCSP_Order_Repository();
     98        $service_point_selected = $this->fetch_service_point_data();
    8899
    89             $service_point_json = $this->fetch_service_point_data($request)
    90                 ? sanitize_text_field(wp_unslash($this->fetch_service_point_data($request))) : '';
    91             $service_point      = json_decode( $service_point_json, true );
    92             if ( isset( $service_point['id'], $service_point['toPostalCode'], $service_point['name'],
    93                 $service_point['street'], $service_point['city'], $service_point['postal_code'], $service_point['house_number'] )
    94             ) {
    95                 $order_repository->save_service_point_meta( $order->get_id(), $service_point_json );
     100        if ( ! $service_point_selected ) {
     101            wc_add_notice( esc_html__( 'Please choose a service point.', 'sendcloud-connected-shipping' ), 'error' );
     102        } else {
     103            $order_repository = new SCCSP_Order_Repository();
    96104
    97                 return;
    98             }
     105            $service_point_json = $this->fetch_service_point_data()
     106                ? sanitize_text_field( wp_unslash( $this->fetch_service_point_data() ) ) : '';
     107            $service_point      = json_decode( $service_point_json, true );
     108            if ( isset( $service_point['id'], $service_point['toPostalCode'], $service_point['name'],
     109                $service_point['street'], $service_point['city'], $service_point['postal_code'], $service_point['house_number'] )
     110            ) {
     111                $order_repository->save_service_point_meta( $order->get_id(), $service_point_json );
     112
     113                wc_clear_notices();
     114                return;
     115            }
    99116
    100117            SCCSP_Logger::warning( 'Service point data not found.' );
     
    105122     * Fetch service point data from request
    106123     *
    107      * @param \WP_REST_Request $request
    108      *
    109124     * @return mixed|null
    110125     */
    111     public function fetch_service_point_data(\WP_REST_Request $request) {
    112         $body = json_decode($request->get_body(), true);
     126    public function fetch_service_point_data() {
     127        $service_point = WC()->session->get( 'sendcloud_service_point' );
    113128
    114         if (isset($body['extensions']['sendcloud-connected-shipping']['service_point'])) {
    115             return $body['extensions']['sendcloud-connected-shipping']['service_point'];
    116         }
    117 
    118         return null;
    119     }
    120 
    121     /**
    122      * Fetch wp nonce from $_SERVER
    123      *
    124      * @return string|null
    125      */
    126     function get_wp_block_nonce()
    127     {
    128         if (isset($_SERVER['HTTP_X_WP_NONCE'])) {
    129             return sanitize_text_field(wp_unslash($_SERVER['HTTP_X_WP_NONCE']));
     129        if ( ! empty( $service_point ) ) {
     130            return  $service_point;
    130131        }
    131132
  • sendcloud-connected-shipping/trunk/includes/class-sendcloud.php

    r3336392 r3366520  
    2727
    2828class SCCSP_Sendcloud {
    29     const VERSION = '1.0.15';
     29    const VERSION = '1.0.16';
    3030
    3131    const INTEGRATION_NAME = 'sendcloudshipping';
     
    183183            if ( class_exists( FeaturesUtil::class ) ) {
    184184                FeaturesUtil::declare_compatibility( 'custom_order_tables', $this->sendcloud_plugin_file, true );
    185             }
     185                FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', $this->sendcloud_plugin_file, true );
     186
     187            }
    186188        } );
    187189        $this->plugin_disable_handler->init();
  • sendcloud-connected-shipping/trunk/readme.txt

    r3336392 r3366520  
    11=== Sendcloud Shipping ===
    2 Version: 1.0.15
     2Version: 1.0.16
    33Developer: SendCloud Global B.V.
    44Developer URI: http://sendcloud.com
     
    77Requires PHP: 7.0
    88Tested up to: 6.8.2
    9 Stable tag: 1.0.15
     9Stable tag: 1.0.16
    1010License: GPLv2
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    103103
    104104== Changelog ==
     105= 1.0.16 =
     106* Implement compatibility with WooCommerce's block-based checkout
     107
    105108= 1.0.15 =
    106109* Change plugin description
  • sendcloud-connected-shipping/trunk/resources/js/service-point-block.js

    r3300820 r3366520  
    1 document.addEventListener('DOMContentLoaded', function () {
    2     // Check if block checkout is being used
    3     if (window.wc && window.wc.blocksCheckout) {
    4         // Create a MutationObserver to detect when the hidden input is added
    5         const observer = new MutationObserver((mutationsList, observer) => {
    6             for (const mutation of mutationsList) {
    7                 for (const node of mutation.addedNodes) {
    8                     if (node.nodeType === 1) { // Ensure it's an element
    9                         const hiddenInput = node.querySelector?.('#sendcloudshipping_service_point_extra_v2') ||
    10                             (node.id === 'sendcloudshipping_service_point_extra_v2' ? node : null);
     1document.addEventListener('DOMContentLoaded', () => {
     2    if (!window.wc?.blocksCheckout) return;
    113
    12                         if (hiddenInput) {
    13                             // Get the value from the hidden input
    14                             const servicePoint = hiddenInput.value;
     4    const { extensionCartUpdate } = window.wc.blocksCheckout;
     5    let isUpdating = false;
    156
    16                             // Dispatch the data to WooCommerce
    17                             wp.data.dispatch('wc/store/checkout').__internalSetExtensionData(
    18                                 'sendcloud-connected-shipping',
    19                                 {
    20                                     service_point: servicePoint,
    21                                 }
    22                             );
     7    const overlay = createOverlay();
     8    document.body.appendChild(overlay);
    239
    24                             // Stop observing after the element is found
    25                             observer.disconnect();
    26                         }
    27                     }
    28                 }
    29             }
     10    const showOverlay = () => overlay.style.display = 'block';
     11    const hideOverlay = () => overlay.style.display = 'none';
     12
     13    const updateServicePoint = async (value) => {
     14        if (isUpdating) return;
     15        isUpdating = true;
     16        showOverlay();
     17
     18        try {
     19            await extensionCartUpdate({
     20                namespace: 'sendcloud-connected-shipping-sp-block',
     21                data: { servicePoint: value },
     22            });
     23
     24            wp.data.dispatch('wc/store/checkout').updateDraftOrder();
     25
     26            console.log('Service Point updated:', value);
     27        } catch (err) {
     28            console.error('Error updating service point:', err);
     29        } finally {
     30            isUpdating = false;
     31            hideOverlay();
     32        }
     33    };
     34
     35    const observeInput = (input) => {
     36        if (!input) return;
     37
     38        updateServicePoint(input.value);
     39
     40        input.addEventListener('input', () => updateServicePoint(input.value));
     41        input.addEventListener('change', () => updateServicePoint(input.value));
     42
     43        new MutationObserver(() => updateServicePoint(input.value))
     44            .observe(input, { attributes: true, attributeFilter: ['value'] });
     45    };
     46
     47    const observer = new MutationObserver((mutationsList) => {
     48        for (const mutation of mutationsList) {
     49            mutation.addedNodes.forEach(node => {
     50                if (node.nodeType !== 1) return;
     51
     52                const input = node.querySelector('#sendcloudshipping_service_point_extra_v2') ||
     53                    (node.id === 'sendcloudshipping_service_point_extra_v2' ? node : null);
     54                if (input) observeInput(input);
     55            });
     56        }
     57    });
     58
     59    observer.observe(document.body, { childList: true, subtree: true });
     60
     61    // Clear session value on page load
     62    updateServicePoint(null);
     63
     64    function createOverlay() {
     65        const div = document.createElement('div');
     66        Object.assign(div.style, {
     67            position: 'fixed',
     68            top: '0',
     69            left: '0',
     70            width: '100%',
     71            height: '100%',
     72            backgroundColor: 'rgba(0, 0, 0, 0.3)',
     73            zIndex: '9999',
     74            display: 'none'
    3075        });
    31 
    32         // Start observing the document body for added nodes
    33         observer.observe(document.body, {
    34             childList: true,
    35             subtree: true
    36         });
     76        return div;
    3777    }
    3878});
  • sendcloud-connected-shipping/trunk/sendcloud-connected-shipping.php

    r3336392 r3366520  
    44 * Plugin URI: https://wordpress.org/plugins/sendcloud-connected-shipping/
    55 * Description: Sendcloud plugin.
    6  * Version: 1.0.15
     6 * Version: 1.0.16
    77 * Woo:
    88 * Author: Sendcloud B.V.
     
    1515 * Domain Path: /i18n/languages/
    1616 * WC requires at least: 3.5.0
    17  * WC tested up to: 9.9.5
     17 * WC tested up to: 10.0.3
    1818 *
    1919 * @package sendcloud-connected-shipping
  • sendcloud-connected-shipping/trunk/vendor/autoload.php

    r3336392 r3366520  
    55require_once __DIR__ . '/composer/autoload_real.php';
    66
    7 return ComposerAutoloaderInit6c5b39b93eda2c317444925cbe7b3b0f::getLoader();
     7return ComposerAutoloaderInit0f5db296a1f2f4f91da748d7f4b34079::getLoader();
  • sendcloud-connected-shipping/trunk/vendor/composer/autoload_real.php

    r3336392 r3366520  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit6c5b39b93eda2c317444925cbe7b3b0f
     5class ComposerAutoloaderInit0f5db296a1f2f4f91da748d7f4b34079
    66{
    77    private static $loader;
     
    2525        require __DIR__ . '/platform_check.php';
    2626
    27         spl_autoload_register(array('ComposerAutoloaderInit6c5b39b93eda2c317444925cbe7b3b0f', 'loadClassLoader'), true, true);
     27        spl_autoload_register(array('ComposerAutoloaderInit0f5db296a1f2f4f91da748d7f4b34079', 'loadClassLoader'), true, true);
    2828        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
    29         spl_autoload_unregister(array('ComposerAutoloaderInit6c5b39b93eda2c317444925cbe7b3b0f', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInit0f5db296a1f2f4f91da748d7f4b34079', 'loadClassLoader'));
    3030
    3131        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
     
    3333            require __DIR__ . '/autoload_static.php';
    3434
    35             call_user_func(\Composer\Autoload\ComposerStaticInit6c5b39b93eda2c317444925cbe7b3b0f::getInitializer($loader));
     35            call_user_func(\Composer\Autoload\ComposerStaticInit0f5db296a1f2f4f91da748d7f4b34079::getInitializer($loader));
    3636        } else {
    3737            $map = require __DIR__ . '/autoload_namespaces.php';
  • sendcloud-connected-shipping/trunk/vendor/composer/autoload_static.php

    r3336392 r3366520  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit6c5b39b93eda2c317444925cbe7b3b0f
     7class ComposerStaticInit0f5db296a1f2f4f91da748d7f4b34079
    88{
    99    public static $classMap = array (
     
    7272    {
    7373        return \Closure::bind(function () use ($loader) {
    74             $loader->classMap = ComposerStaticInit6c5b39b93eda2c317444925cbe7b3b0f::$classMap;
     74            $loader->classMap = ComposerStaticInit0f5db296a1f2f4f91da748d7f4b34079::$classMap;
    7575
    7676        }, null, ClassLoader::class);
  • sendcloud-connected-shipping/trunk/vendor/composer/installed.php

    r3336392 r3366520  
    66        'install_path' => __DIR__ . '/../../',
    77        'aliases' => array(),
    8         'reference' => '41392e43035af30cef773b15296e74a1431381f9',
     8        'reference' => '85fb3df09d7a39fd5285c55fd04acd9a06b7654c',
    99        'name' => 'sendcloud/woocommerce',
    1010        'dev' => false,
     
    1717            'install_path' => __DIR__ . '/../../',
    1818            'aliases' => array(),
    19             'reference' => '41392e43035af30cef773b15296e74a1431381f9',
     19            'reference' => '85fb3df09d7a39fd5285c55fd04acd9a06b7654c',
    2020            'dev_requirement' => false,
    2121        ),
Note: See TracChangeset for help on using the changeset viewer.