From 5a9791fe8316c2a775bd976856e5841b9823ab08 Mon Sep 17 00:00:00 2001 From: vendidero Date: Wed, 25 Oct 2023 16:52:58 +0200 Subject: [PATCH] Use a hack to prevent the missing object error within checkout block in case the checkboxes block is missing and not extension data is set. See: https://github.com/woocommerce/woocommerce-blocks/issues/11446 Use a regex to replace the last divs of the checkout block with our custom markup to prevent issues with whitespace between div closing strings. Version bump to 3.14.1. --- .../blocks/checkout/slotfills/order-meta.js | 23 +++++++++++++--- assets/js/static/direct-debit.js | 7 ++++- composer.json | 4 +-- composer.lock | 26 +++++++++---------- package.json | 2 +- src/Blocks/Checkout.php | 9 ++++--- woocommerce-germanized.php | 4 +-- 7 files changed, 50 insertions(+), 25 deletions(-) diff --git a/assets/js/blocks/checkout/slotfills/order-meta.js b/assets/js/blocks/checkout/slotfills/order-meta.js index 3e42525c8..343236498 100644 --- a/assets/js/blocks/checkout/slotfills/order-meta.js +++ b/assets/js/blocks/checkout/slotfills/order-meta.js @@ -1,13 +1,30 @@ import { ExperimentalOrderMeta } from '@woocommerce/blocks-checkout'; import { registerPlugin } from '@wordpress/plugins'; import { useEffect } from "@wordpress/element"; +import { dispatch, select } from '@wordpress/data'; +import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data'; import SmallBusinessInfo from "../checkout-small-business-info/frontend"; const DomWatcher = ({ - extensions, - cart - }) => { + extensions, + cart +}) => { + + /** + * Use this little helper which sets the default checkout data in case it + * does not exist, e.g. the checkboxes block is missing to prevent extension errors. + * + * @see https://github.com/woocommerce/woocommerce-blocks/issues/11446 + */ + useEffect(() => { + const extensionsData = select( CHECKOUT_STORE_KEY ).getExtensionData(); + + if ( ! extensionsData.hasOwnProperty( 'woocommerce-germanized' ) ) { + dispatch( CHECKOUT_STORE_KEY ).__internalSetExtensionData( 'woocommerce-germanized', {} ); + } + }, [] ); + useEffect(() => { const orderItems = document.getElementsByClassName( 'wc-block-components-order-summary-item' ); diff --git a/assets/js/static/direct-debit.js b/assets/js/static/direct-debit.js index 04b00c693..25a77d553 100644 --- a/assets/js/static/direct-debit.js +++ b/assets/js/static/direct-debit.js @@ -57,7 +57,12 @@ jQuery( function( $ ) { }, isValidIBAN: function( iban ) { - return window.germanized.static.iban.isValid( iban ); + // Support legacy, non-bundled module loading + if ( window.hasOwnProperty( 'IBAN' ) ) { + return window.IBAN.isValid( iban ); + } else { + return window.germanized.static.iban.isValid( iban ); + } }, isValidSWIFT: function( swift ) { diff --git a/composer.json b/composer.json index e7d58a579..5ef2e69d6 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,8 @@ "digitick/sepa-xml" : "^2.0.0", "defuse/php-encryption": "^2.0.0", "globalcitizen/php-iban": "^4.0.0", - "vendidero/woocommerce-germanized-dhl": "2.1.0", - "vendidero/woocommerce-germanized-shipments": "2.4.3", + "vendidero/woocommerce-germanized-dhl": "2.1.1", + "vendidero/woocommerce-germanized-shipments": "2.4.4", "vendidero/woocommerce-eu-tax-helper": "1.1.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 83c174b15..ce3129f2b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f27e23390e30194ef75a3176629e8b0c", + "content-hash": "032b1da615800ab9f055ba9e50c06921", "packages": [ { "name": "automattic/jetpack-autoloader", @@ -810,16 +810,16 @@ }, { "name": "vendidero/woocommerce-germanized-dhl", - "version": "2.1.0", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/vendidero/woocommerce-germanized-dhl.git", - "reference": "4960e893c0d36065c7f1f5cce030b06678e62bea" + "reference": "be260b948cee49fa80c4a355bb8c896c8e15f2d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vendidero/woocommerce-germanized-dhl/zipball/4960e893c0d36065c7f1f5cce030b06678e62bea", - "reference": "4960e893c0d36065c7f1f5cce030b06678e62bea", + "url": "https://api.github.com/repos/vendidero/woocommerce-germanized-dhl/zipball/be260b948cee49fa80c4a355bb8c896c8e15f2d0", + "reference": "be260b948cee49fa80c4a355bb8c896c8e15f2d0", "shasum": "" }, "require": { @@ -864,23 +864,23 @@ "description": "The Germanized DHL implementation.", "homepage": "https://github.com/vendidero/woocommerce-germanized-dhl", "support": { - "source": "https://github.com/vendidero/woocommerce-germanized-dhl/tree/v2.1.0", + "source": "https://github.com/vendidero/woocommerce-germanized-dhl/tree/v2.1.1", "issues": "https://github.com/vendidero/woocommerce-germanized-dhl/issues" }, - "time": "2023-10-24T08:16:16+00:00" + "time": "2023-10-25T14:37:33+00:00" }, { "name": "vendidero/woocommerce-germanized-shipments", - "version": "2.4.3", + "version": "2.4.4", "source": { "type": "git", "url": "https://github.com/vendidero/woocommerce-germanized-shipments.git", - "reference": "f55a6d210e43aa0b4cc3004bc07c83e03fa72c77" + "reference": "ae9351f2bfd943971a3e1dba7cc1e4643f970f72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vendidero/woocommerce-germanized-shipments/zipball/f55a6d210e43aa0b4cc3004bc07c83e03fa72c77", - "reference": "f55a6d210e43aa0b4cc3004bc07c83e03fa72c77", + "url": "https://api.github.com/repos/vendidero/woocommerce-germanized-shipments/zipball/ae9351f2bfd943971a3e1dba7cc1e4643f970f72", + "reference": "ae9351f2bfd943971a3e1dba7cc1e4643f970f72", "shasum": "" }, "require": { @@ -923,10 +923,10 @@ "description": "The Germanized Shipments implementation.", "homepage": "https://github.com/vendidero/woocommerce-germanized-shipments", "support": { - "source": "https://github.com/vendidero/woocommerce-germanized-shipments/tree/v2.4.3", + "source": "https://github.com/vendidero/woocommerce-germanized-shipments/tree/v2.4.4", "issues": "https://github.com/vendidero/woocommerce-germanized-shipments/issues" }, - "time": "2023-10-24T08:17:13+00:00" + "time": "2023-10-25T14:38:07+00:00" }, { "name": "wsdltophp/wssecurity", diff --git a/package.json b/package.json index efdd4c13e..16cc7b1b7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "woocommerce-germanized", "title": "Germanized for WooCommerce", - "version": "3.13.5", + "version": "3.14.1", "homepage": "https://vendidero.de/woocommerce-germanized", "repository": { "type": "git", diff --git a/src/Blocks/Checkout.php b/src/Blocks/Checkout.php index 45ebbd033..d19426ae7 100644 --- a/src/Blocks/Checkout.php +++ b/src/Blocks/Checkout.php @@ -94,9 +94,12 @@ function( $content, $block ) { if ( 'woocommerce/checkout' === $block['blockName'] && ! apply_filters( 'woocommerce_gzd_disable_checkout_block_adjustments', false ) ) { $content = str_replace( 'wp-block-woocommerce-checkout ', 'wp-block-woocommerce-checkout wc-gzd-checkout ', $content ); - if ( '' === substr( $content, -12 ) ) { - $content = substr( $content, 0, -12 ); - $content = $content . '
'; + // Find the last 2 closing divs of the checkout block and replace them with our custom submit wrap. + preg_match( '/<\/div>(\s*)<\/div>$/', $content, $matches ); + + if ( ! empty( $matches ) ) { + $replacement = '
'; + $content = preg_replace( '/<\/div>(\s*)<\/div>$/', $replacement, $content ); } } diff --git a/woocommerce-germanized.php b/woocommerce-germanized.php index 69ff9e86c..f7e2ba2f1 100644 --- a/woocommerce-germanized.php +++ b/woocommerce-germanized.php @@ -3,7 +3,7 @@ * Plugin Name: Germanized for WooCommerce * Plugin URI: https://www.vendidero.de/woocommerce-germanized * Description: Germanized for WooCommerce extends WooCommerce to become a legally compliant store in the german market. - * Version: 3.14.0 + * Version: 3.14.1 * Author: vendidero * Author URI: https://vendidero.de * Requires at least: 5.4 @@ -69,7 +69,7 @@ final class WooCommerce_Germanized { * * @var string */ - public $version = '3.14.0'; + public $version = '3.14.1'; /** * @var WooCommerce_Germanized $instance of the plugin