Skip to content

Commit

Permalink
Use a hack to prevent the missing object error within checkout block …
Browse files Browse the repository at this point in the history
…in case the checkboxes block is missing and not extension data is set. See: woocommerce/woocommerce-blocks#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.
  • Loading branch information
dennisnissle committed Oct 25, 2023
1 parent e89e125 commit 5a9791f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 25 deletions.
23 changes: 20 additions & 3 deletions assets/js/blocks/checkout/slotfills/order-meta.js
Original file line number Diff line number Diff line change
@@ -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' );

Expand Down
7 changes: 6 additions & 1 deletion assets/js/static/direct-debit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 6 additions & 3 deletions src/Blocks/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ( '</div></div>' === substr( $content, -12 ) ) {
$content = substr( $content, 0, -12 );
$content = $content . '<div class="wc-gzd-checkout-submit"><div data-block-name="woocommerce/checkout-order-summary-block" class="wp-block-woocommerce-checkout-order-summary-block"></div><div data-block-name="woocommerce/checkout-actions-block" class="wp-block-woocommerce-checkout-actions-block"></div></div></div></div>';
// 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 = '<div class="wc-gzd-checkout-submit"><div data-block-name="woocommerce/checkout-order-summary-block" class="wp-block-woocommerce-checkout-order-summary-block"></div><div data-block-name="woocommerce/checkout-actions-block" class="wp-block-woocommerce-checkout-actions-block"></div></div></div></div>';
$content = preg_replace( '/<\/div>(\s*)<\/div>$/', $replacement, $content );
}
}

Expand Down
4 changes: 2 additions & 2 deletions woocommerce-germanized.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5a9791f

Please sign in to comment.