From cf75b6dc64c252870a8e31ba7ea04bda0e445691 Mon Sep 17 00:00:00 2001 From: Warwick Date: Tue, 19 Nov 2024 16:15:45 +0200 Subject: [PATCH 01/11] Updating the Price filters to work on the single supplement as well. --- assets/css/scss/_icons.scss | 6 +- assets/css/scss/style.scss | 27 ------ assets/css/style.css | 85 +++++++++++++------ assets/css/style.css.map | 2 +- assets/js/blocks/tour.js | 2 +- .../classes/legacy/class-accommodation.php | 6 +- includes/classes/legacy/class-tour.php | 7 +- 7 files changed, 74 insertions(+), 61 deletions(-) delete mode 100644 assets/css/scss/style.scss diff --git a/assets/css/scss/_icons.scss b/assets/css/scss/_icons.scss index 41ef0127..0eac7f5b 100644 --- a/assets/css/scss/_icons.scss +++ b/assets/css/scss/_icons.scss @@ -116,7 +116,8 @@ } }*/ -.lsx-price-wrapper { +.lsx-price-wrapper, +.lsx-single-supplement-wrapper { /*&:before { background-image: url( ../img/icons/price-icon.png ); }*/ @@ -129,6 +130,3 @@ } } } - -// Add the icon ULR here. -//.lsx-destination-to-tour-wrapper::before { background-image: url( ../img/icons/destinations-icon.webp ); } diff --git a/assets/css/scss/style.scss b/assets/css/scss/style.scss deleted file mode 100644 index d92f46ae..00000000 --- a/assets/css/scss/style.scss +++ /dev/null @@ -1,27 +0,0 @@ -/* - * LSX Tour Operators - */ - -@import 'include-media'; -@import 'customizer-to-body-colours'; -@import 'customizer-to-main-menu-colours'; - -@import 'base/variables'; - -@import 'base/scaffolding'; - -@import 'layout/widget'; -@import 'layout/slider'; -@import 'layout/meta-data'; -@import 'layout/archive'; -@import 'layout/contact'; -@import 'layout/single-sections'; -@import 'layout/spy-bar'; -@import 'layout/modals'; -@import 'layout/maps'; -@import 'layout/mobile'; - -@import 'update-fixes'; - -@include customizer-to-body-colours(#F6F6F6, #DADDDF, #4A4A4A, #1098AD, #F7AE00, #919191); -@include customizer-to-main-menu-colours(#374750, #2B3840, #FFF, #1098AD); diff --git a/assets/css/style.css b/assets/css/style.css index 5573a925..cbb562c4 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -2,74 +2,105 @@ /* * LSX Tour Operators */ -.lsx-price-wrapper .amount .currency-icon:after { +.lsx-price-wrapper .amount .currency-icon:after, +.lsx-single-supplement-wrapper .amount .currency-icon:after { margin-left: 3px; margin-right: 3px; } -.lsx-price-wrapper .amount .currency-icon.usd:after, .lsx-price-wrapper .amount .currency-icon.nad:after, .lsx-price-wrapper .amount .currency-icon.cad:after, .lsx-price-wrapper .amount .currency-icon.hkd:after, .lsx-price-wrapper .amount .currency-icon.sgd:after, .lsx-price-wrapper .amount .currency-icon.nzd:after, .lsx-price-wrapper .amount .currency-icon.aud:after { +.lsx-price-wrapper .amount .currency-icon.usd:after, +.lsx-single-supplement-wrapper .amount .currency-icon.usd:after, .lsx-price-wrapper .amount .currency-icon.nad:after, +.lsx-single-supplement-wrapper .amount .currency-icon.nad:after, .lsx-price-wrapper .amount .currency-icon.cad:after, +.lsx-single-supplement-wrapper .amount .currency-icon.cad:after, .lsx-price-wrapper .amount .currency-icon.hkd:after, +.lsx-single-supplement-wrapper .amount .currency-icon.hkd:after, .lsx-price-wrapper .amount .currency-icon.sgd:after, +.lsx-single-supplement-wrapper .amount .currency-icon.sgd:after, .lsx-price-wrapper .amount .currency-icon.nzd:after, +.lsx-single-supplement-wrapper .amount .currency-icon.nzd:after, .lsx-price-wrapper .amount .currency-icon.aud:after, +.lsx-single-supplement-wrapper .amount .currency-icon.aud:after { content: "$"; } -.lsx-price-wrapper .amount .currency-icon.eur:after { +.lsx-price-wrapper .amount .currency-icon.eur:after, +.lsx-single-supplement-wrapper .amount .currency-icon.eur:after { content: "€"; } -.lsx-price-wrapper .amount .currency-icon.gbp:after { +.lsx-price-wrapper .amount .currency-icon.gbp:after, +.lsx-single-supplement-wrapper .amount .currency-icon.gbp:after { content: "£"; } -.lsx-price-wrapper .amount .currency-icon.zar:after { +.lsx-price-wrapper .amount .currency-icon.zar:after, +.lsx-single-supplement-wrapper .amount .currency-icon.zar:after { content: "R"; } -.lsx-price-wrapper .amount .currency-icon.brl:after { +.lsx-price-wrapper .amount .currency-icon.brl:after, +.lsx-single-supplement-wrapper .amount .currency-icon.brl:after { content: "R$"; } -.lsx-price-wrapper .amount .currency-icon.bwp:after { +.lsx-price-wrapper .amount .currency-icon.bwp:after, +.lsx-single-supplement-wrapper .amount .currency-icon.bwp:after { content: "P"; } -.lsx-price-wrapper .amount .currency-icon.cny:after, .lsx-price-wrapper .amount .currency-icon.jpy:after { +.lsx-price-wrapper .amount .currency-icon.cny:after, +.lsx-single-supplement-wrapper .amount .currency-icon.cny:after, .lsx-price-wrapper .amount .currency-icon.jpy:after, +.lsx-single-supplement-wrapper .amount .currency-icon.jpy:after { content: "¥"; } -.lsx-price-wrapper .amount .currency-icon.inr:after { +.lsx-price-wrapper .amount .currency-icon.inr:after, +.lsx-single-supplement-wrapper .amount .currency-icon.inr:after { content: "₹"; } -.lsx-price-wrapper .amount .currency-icon.idr:after { +.lsx-price-wrapper .amount .currency-icon.idr:after, +.lsx-single-supplement-wrapper .amount .currency-icon.idr:after { content: "₹"; } -.lsx-price-wrapper .amount .currency-icon.ils:after { +.lsx-price-wrapper .amount .currency-icon.ils:after, +.lsx-single-supplement-wrapper .amount .currency-icon.ils:after { content: "₪"; } -.lsx-price-wrapper .amount .currency-icon.kes:after { +.lsx-price-wrapper .amount .currency-icon.kes:after, +.lsx-single-supplement-wrapper .amount .currency-icon.kes:after { content: "K"; } -.lsx-price-wrapper .amount .currency-icon.lak:after { +.lsx-price-wrapper .amount .currency-icon.lak:after, +.lsx-single-supplement-wrapper .amount .currency-icon.lak:after { content: "₭"; } -.lsx-price-wrapper .amount .currency-icon.mwk:after { +.lsx-price-wrapper .amount .currency-icon.mwk:after, +.lsx-single-supplement-wrapper .amount .currency-icon.mwk:after { content: "MK"; } -.lsx-price-wrapper .amount .currency-icon.myr:after { +.lsx-price-wrapper .amount .currency-icon.myr:after, +.lsx-single-supplement-wrapper .amount .currency-icon.myr:after { content: "RM"; } -.lsx-price-wrapper .amount .currency-icon.mzn:after { +.lsx-price-wrapper .amount .currency-icon.mzn:after, +.lsx-single-supplement-wrapper .amount .currency-icon.mzn:after { content: "MT"; } -.lsx-price-wrapper .amount .currency-icon.nok:after, .lsx-price-wrapper .amount .currency-icon.sek:after { +.lsx-price-wrapper .amount .currency-icon.nok:after, +.lsx-single-supplement-wrapper .amount .currency-icon.nok:after, .lsx-price-wrapper .amount .currency-icon.sek:after, +.lsx-single-supplement-wrapper .amount .currency-icon.sek:after { content: "kr"; } -.lsx-price-wrapper .amount .currency-icon.rub:after { +.lsx-price-wrapper .amount .currency-icon.rub:after, +.lsx-single-supplement-wrapper .amount .currency-icon.rub:after { content: "руб"; } -.lsx-price-wrapper .amount .currency-icon.chf:after { +.lsx-price-wrapper .amount .currency-icon.chf:after, +.lsx-single-supplement-wrapper .amount .currency-icon.chf:after { content: "CHF"; } -.lsx-price-wrapper .amount .currency-icon.tzs:after { +.lsx-price-wrapper .amount .currency-icon.tzs:after, +.lsx-single-supplement-wrapper .amount .currency-icon.tzs:after { content: "TSh"; } -.lsx-price-wrapper .amount .currency-icon.aed:after { +.lsx-price-wrapper .amount .currency-icon.aed:after, +.lsx-single-supplement-wrapper .amount .currency-icon.aed:after { content: "د.إ"; } -.lsx-price-wrapper .amount .currency-icon.zmw:after { +.lsx-price-wrapper .amount .currency-icon.zmw:after, +.lsx-single-supplement-wrapper .amount .currency-icon.zmw:after { content: "Zk"; } -.lsx-price-wrapper .amount .currency-icon.zwl:after { +.lsx-price-wrapper .amount .currency-icon.zwl:after, +.lsx-single-supplement-wrapper .amount .currency-icon.zwl:after { content: "Z$"; } @@ -84,12 +115,14 @@ background-position: center top; } }*/ -.lsx-price-wrapper { +.lsx-price-wrapper, +.lsx-single-supplement-wrapper { /*&:before { background-image: url( ../img/icons/price-icon.png ); }*/ } -.lsx-price-wrapper .amount .currency-icon:after { +.lsx-price-wrapper .amount .currency-icon:after, +.lsx-single-supplement-wrapper .amount .currency-icon:after { margin-right: 0px; } @@ -197,4 +230,4 @@ .lsx-units-wrapper .hidden { display: none; } -/*# sourceMappingURL=style.css.map */ +/*# sourceMappingURL=style.css.map */ \ No newline at end of file diff --git a/assets/css/style.css.map b/assets/css/style.css.map index e93d1452..d858bc1a 100644 --- a/assets/css/style.css.map +++ b/assets/css/style.css.map @@ -1 +1 @@ -{"version":3,"sources":["style.css","style.scss","scss/_icons.scss","scss/_slider.scss"],"names":[],"mappings":"AAAA,gBAAgB;ACAhB;;EAAA;ACEE;EACC,gBAAA;EACA,iBAAA;AFGH;AEOG;EAAU,YAAA;AFJb;AEQG;EAAU,YAAA;AFLb;AESG;EAAU,YAAA;AFNb;AEUG;EAAU,YAAA;AFPb;AEWG;EAAU,aAAA;AFRb;AEYG;EAAU,YAAA;AFTb;AEcG;EAAU,YAAA;AFXb;AEeG;EAAU,YAAA;AFZb;AEgBG;EAAU,YAAA;AFbb;AEiBG;EAAU,YAAA;AFdb;AEkBG;EAAU,YAAA;AFfb;AEmBG;EAAU,YAAA;AFhBb;AEoBG;EAAU,aAAA;AFjBb;AEqBG;EAAU,aAAA;AFlBb;AEsBG;EAAU,aAAA;AFnBb;AEwBG;EAAU,aAAA;AFrBb;AEyBG;EAAU,cAAA;AFtBb;AE0BG;EAAU,cAAA;AFvBb;AE2BG;EAAU,cAAA;AFxBb;AE4BG;EAAU,cAAA;AFzBb;AE6BG;EAAU,aAAA;AF1Bb;AE8BG;EAAU,aAAA;AF3Bb;;AEiCA;;;;;;;;;;EAAA;AAYA;EACC;;IAAA;AF7BD;AEqCG;EAAU,iBAAA;AFlCb;;AG7FA;EACC,WAAA;EACA,SAAA;AHgGD;;AG3FC;;EACC,uBAAA;EACA,kBAAA;EACA,mBAAA;EACA,iBAAA;EACA,WAAA;EACA,YAAA;EACA,sCAAA;EACA,UAAA;EACA,iBAAA;EACA,2BAAA;EACA,6BAAA;EACA,WAAA;EACA,UAAA;AH+FF;AG7FE;;EACC,cAAA;EACA,0BAAA;EACA,eAAA;EACA,cAAA;EACA,kBAAA;EACA,oBAAA;EACA,QAAA;EACA,2BAAA;EACA,4BAAA;EAEA,mCAAA;EACA,kCAAA;AH+FH;AG5FE;;EAAmB,mBAAA;AHgGrB;AG7FG;;EACC,gBAAA;EACA,YAAA;AHgGJ;AG3FG;;EACC,gBAAA;EACA,YAAA;AH8FJ;;AGvFC;EACC,mBAAA;EACA,aAAA;EACA,mBAAA;EACA,YAAA;EACA,uBAAA;EACA,gBAAA;EACA,gBAAA;EACA,UAAA;AH0FF;AGxFE;EACC,cAAA;EACA,YAAA;AH0FH;AGxFG;EACC,uBAAA;EACA,mBAAA;EACA,iBAAA;EACA,WAAA;EACA,YAAA;EACA,iCAAA;EACA,WAAA;AH0FJ;AGpFE;EAAe,WAAA;AHuFjB;AGtFE;EAAe,YAAA;AHyFjB;;AGpFC;EAAoB,gBAAA;AHwFrB;;AGpFC;EACC,aAAA;AHuFF;AGrFE;EAAU,UAAA;AHwFZ;;AGpFA;EAAgC,qBAAA;AHwFhC;;AGnFE;;EACC,iBAAA;AHuFH;;ACvLC;;EACC,aAAA;AD2LF","file":"style.css"} \ No newline at end of file +{"version":3,"sources":["style.css","style.scss","scss/_icons.scss","scss/_slider.scss"],"names":[],"mappings":"AAAA,gBAAgB;ACAhB;;EAAA;ACEE;;EACC,gBAAA;EACA,iBAAA;AFIH;AEMG;;;;;;;;EAAU,YAAA;AFIb;AEAG;;EAAU,YAAA;AFIb;AEAG;;EAAU,YAAA;AFIb;AEAG;;EAAU,YAAA;AFIb;AEAG;;EAAU,aAAA;AFIb;AEAG;;EAAU,YAAA;AFIb;AECG;;;EAAU,YAAA;AFIb;AEAG;;EAAU,YAAA;AFIb;AEAG;;EAAU,YAAA;AFIb;AEAG;;EAAU,YAAA;AFIb;AEAG;;EAAU,YAAA;AFIb;AEAG;;EAAU,YAAA;AFIb;AEAG;;EAAU,aAAA;AFIb;AEAG;;EAAU,aAAA;AFIb;AEAG;;EAAU,aAAA;AFIb;AECG;;;EAAU,aAAA;AFIb;AEAG;;EAAU,cAAA;AFIb;AEAG;;EAAU,cAAA;AFIb;AEAG;;EAAU,cAAA;AFIb;AEAG;;EAAU,cAAA;AFIb;AEAG;;EAAU,aAAA;AFIb;AEAG;;EAAU,aAAA;AFIb;;AEEA;;;;;;;;;;EAAA;AAYA;;EAEC;;IAAA;AFED;AEMG;;EAAU,iBAAA;AFFb;;AG9HA;EACC,WAAA;EACA,SAAA;AHiID;;AG5HC;;EACC,uBAAA;EACA,kBAAA;EACA,mBAAA;EACA,iBAAA;EACA,WAAA;EACA,YAAA;EACA,sCAAA;EACA,UAAA;EACA,iBAAA;EACA,2BAAA;EACA,6BAAA;EACA,WAAA;EACA,UAAA;AHgIF;AG9HE;;EACC,cAAA;EACA,0BAAA;EACA,eAAA;EACA,cAAA;EACA,kBAAA;EACA,oBAAA;EACA,QAAA;EACA,2BAAA;EACA,4BAAA;EAEA,mCAAA;EACA,kCAAA;AHgIH;AG7HE;;EAAmB,mBAAA;AHiIrB;AG9HG;;EACC,gBAAA;EACA,YAAA;AHiIJ;AG5HG;;EACC,gBAAA;EACA,YAAA;AH+HJ;;AGxHC;EACC,mBAAA;EACA,aAAA;EACA,mBAAA;EACA,YAAA;EACA,uBAAA;EACA,gBAAA;EACA,gBAAA;EACA,UAAA;AH2HF;AGzHE;EACC,cAAA;EACA,YAAA;AH2HH;AGzHG;EACC,uBAAA;EACA,mBAAA;EACA,iBAAA;EACA,WAAA;EACA,YAAA;EACA,iCAAA;EACA,WAAA;AH2HJ;AGrHE;EAAe,WAAA;AHwHjB;AGvHE;EAAe,YAAA;AH0HjB;;AGrHC;EAAoB,gBAAA;AHyHrB;;AGrHC;EACC,aAAA;AHwHF;AGtHE;EAAU,UAAA;AHyHZ;;AGrHA;EAAgC,qBAAA;AHyHhC;;AGpHE;;EACC,iBAAA;AHwHH;;ACxNC;;EACC,aAAA;AD4NF","file":"style.css"} \ No newline at end of file diff --git a/assets/js/blocks/tour.js b/assets/js/blocks/tour.js index 1059ca6e..5b9f7abd 100644 --- a/assets/js/blocks/tour.js +++ b/assets/js/blocks/tour.js @@ -721,7 +721,7 @@ wp.domReady(() => { } } }, - className: 'has-primary-color has-text-color has-link-color', + className: 'amount has-primary-color has-text-color has-link-color', style: { elements: { link: { diff --git a/includes/classes/legacy/class-accommodation.php b/includes/classes/legacy/class-accommodation.php index 2787c7e6..01e29bdb 100644 --- a/includes/classes/legacy/class-accommodation.php +++ b/includes/classes/legacy/class-accommodation.php @@ -118,7 +118,11 @@ function entry_class( $classes ) { * Adds in additional info for the price custom field */ public function price_filter( $html = '', $meta_key = false, $value = false, $before = '', $after = '' ) { - if ( get_post_type() === 'accommodation' && 'price' === $meta_key ) { + $currency_fields = [ + 'price' + ]; + + if ( get_post_type() === 'accommodation' && in_array( $meta_key, $currency_fields ) ) { $price_type = get_post_meta( get_the_ID(), 'price_type', true ); $value = preg_replace( '/[^0-9,.]/', '', $value ); $value = ltrim( $value, '.' ); diff --git a/includes/classes/legacy/class-tour.php b/includes/classes/legacy/class-tour.php index c2b09e25..2b81f280 100644 --- a/includes/classes/legacy/class-tour.php +++ b/includes/classes/legacy/class-tour.php @@ -176,7 +176,12 @@ public function itinerary_needs_read_more( $return ) { * Adds in additional info for the price custom field */ public function price_filter( $html = '', $meta_key = false, $value = false, $before = '', $after = '' ) { - if ( get_post_type() === 'tour' && 'price' === $meta_key ) { + $currency_fields = [ + 'price', + 'single_supplement' + ]; + + if ( get_post_type() === 'tour' && in_array( $meta_key, $currency_fields ) ) { $value = preg_replace( '/[^0-9,.]/', '', $value ); $value = ltrim( $value, '.' ); $value = str_replace( ',', '', $value ); From 7a5b5561dad9a2cf67b7aeb8b914a9fae07df3b8 Mon Sep 17 00:00:00 2001 From: Warwick Date: Tue, 19 Nov 2024 16:47:08 +0200 Subject: [PATCH 02/11] Updating the description if there is an empty departure day --- includes/classes/blocks/class-bindings.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/classes/blocks/class-bindings.php b/includes/classes/blocks/class-bindings.php index c13ecf1b..23822d60 100644 --- a/includes/classes/blocks/class-bindings.php +++ b/includes/classes/blocks/class-bindings.php @@ -307,9 +307,10 @@ public function build_itinerary_field( $build = '', $field = '', $count = 1 ) { $value = lsx_to_itinerary_description( false ); $pattern = '/]*\bclass="[^"]*\bitinerary-description\b[^"]*"[^>]*>.*?<\/p>/is'; - if ( ! empty( $value ) ) { - $value = '
' . $value . '
'; + if ( empty( $value ) ) { + $value = ''; } + $value = '
' . $value . '
'; } break; From c6955ae8d2bcf551502f2b02d9651dfa65a56c8d Mon Sep 17 00:00:00 2001 From: Warwick Date: Tue, 19 Nov 2024 17:14:42 +0200 Subject: [PATCH 03/11] Fixing the php warnings --- includes/classes/blocks/class-bindings.php | 24 ++++++++++++------- .../classes/blocks/class-registration.php | 4 +++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/includes/classes/blocks/class-bindings.php b/includes/classes/blocks/class-bindings.php index 23822d60..401c0757 100644 --- a/includes/classes/blocks/class-bindings.php +++ b/includes/classes/blocks/class-bindings.php @@ -133,6 +133,8 @@ public function post_connections_callback( $source_args, $block_instance ) { return ''; } + $value = ''; + switch ( $source_args['key'] ) { case 'post_children': @@ -211,15 +213,18 @@ public function post_meta_callback( $source_args, $block_instance ) { } $value = lsx_to_custom_field_query( $source_args['key'], '', '', false, get_the_ID(), $single ); - $date_transforms = [ - 'booking_validity_start', - 'booking_validity_end', - ]; - if ( in_array( $source_args['key'], $date_transforms ) ) { - $value = wp_date( 'j M Y', $value ); + if ( null !== $value ) { + $date_transforms = [ + 'booking_validity_start', + 'booking_validity_end', + ]; + if ( in_array( $source_args['key'], $date_transforms ) ) { + $value = wp_date( 'j M Y', $value ); + } + + $value = preg_replace( '/^

(.*?)<\/p>$/', '$1', $value ); } - - $value = preg_replace( '/^

(.*?)<\/p>$/', '$1', $value ); + } return $value; } @@ -765,6 +770,9 @@ public function maybe_hide_varitaion( $block_content, $parsed_block, $block_obj break; default: + + do_action( 'dm/debug', $parsed_block ); + break; } } else if ( taxonomy_exists( $key ) ) { diff --git a/includes/classes/blocks/class-registration.php b/includes/classes/blocks/class-registration.php index 5e3fdfe3..ef26e083 100644 --- a/includes/classes/blocks/class-registration.php +++ b/includes/classes/blocks/class-registration.php @@ -198,8 +198,10 @@ public function query_args_filter( $query, $block ) { if ( ! is_array( $found_items ) ) { $found_items = [ $found_items ]; } - $query['post__in'] = $found_items; + } else { + $query['no_relation'] = true; + $query['post__in'] = [ get_the_ID() ]; } break; From 34a9c0d4d31d6d7305ea4506e08e8ec9f2a531dc Mon Sep 17 00:00:00 2001 From: Warwick Date: Tue, 19 Nov 2024 17:48:21 +0200 Subject: [PATCH 04/11] Adding in a check to make sure the bindings are working. --- includes/classes/blocks/class-bindings.php | 47 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/includes/classes/blocks/class-bindings.php b/includes/classes/blocks/class-bindings.php index 401c0757..39b8ce0b 100644 --- a/includes/classes/blocks/class-bindings.php +++ b/includes/classes/blocks/class-bindings.php @@ -175,6 +175,12 @@ public function post_connections_callback( $source_args, $block_instance ) { continue; } } + + + + if ( 0 === $this->post_id_exists( $pid ) ) { + continue; + } $values[] = '' . get_the_title( $pid ) . ''; } @@ -218,7 +224,7 @@ public function post_meta_callback( $source_args, $block_instance ) { 'booking_validity_start', 'booking_validity_end', ]; - if ( in_array( $source_args['key'], $date_transforms ) ) { + if ( in_array( $source_args['key'], $date_transforms ) ) { $value = wp_date( 'j M Y', $value ); } @@ -585,6 +591,10 @@ public function render_gallery_block( $block_content, $parsed_block, $block_obj return $block_content; } + if ( ! is_array( $gallery ) ) { + $gallery = [ $gallery ]; + } + $classes = $this->find_gallery_classes( $block_content ); $images = array(); @@ -771,7 +781,7 @@ public function maybe_hide_varitaion( $block_content, $parsed_block, $block_obj default: - do_action( 'dm/debug', $parsed_block ); + do_action( 'qm/debug', $query_key ); break; } @@ -824,4 +834,37 @@ public function prep_links( $items ) { } return implode( ', ', $item_links ); } + + /** + * Determines if a post exists based on the ID. + * + * + * @global wpdb $wpdb WordPress database abstraction object. + * + * @param string $title Post title. + * @param string $content Optional. Post content. + * @param string $date Optional. Post date. + * @param string $type Optional. Post type. + * @param string $status Optional. Post status. + * @return int Post ID if post exists, 0 otherwise. + */ + protected function post_id_exists( $id ) { + global $wpdb; + + $post_id = wp_unslash( sanitize_post_field( 'id', $id, 0, 'db' ) ); + + $query = "SELECT ID FROM $wpdb->posts WHERE 1=1"; + $args = array(); + + if ( ! empty( $date ) ) { + $query .= ' AND ID = %d'; + $args[] = $post_id; + } + + if ( ! empty( $args ) ) { + return (int) $wpdb->get_var( $wpdb->prepare( $query, $args ) ); + } + + return 0; + } } From 75fb9722e083bdbbc53cb2a4c5330d41ba42c45c Mon Sep 17 00:00:00 2001 From: Warwick Date: Wed, 20 Nov 2024 16:52:01 +0200 Subject: [PATCH 05/11] Making sure the trashed items are not used, BH-77 --- includes/classes/blocks/class-bindings.php | 37 ++++++++++------------ 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/includes/classes/blocks/class-bindings.php b/includes/classes/blocks/class-bindings.php index 39b8ce0b..1bc7707e 100644 --- a/includes/classes/blocks/class-bindings.php +++ b/includes/classes/blocks/class-bindings.php @@ -176,12 +176,6 @@ public function post_connections_callback( $source_args, $block_instance ) { } } - - - if ( 0 === $this->post_id_exists( $pid ) ) { - continue; - } - $values[] = '' . get_the_title( $pid ) . ''; } $value = implode( ', ', $values ); @@ -781,7 +775,6 @@ public function maybe_hide_varitaion( $block_content, $parsed_block, $block_obj default: - do_action( 'qm/debug', $query_key ); break; } @@ -805,6 +798,12 @@ public function maybe_hide_varitaion( $block_content, $parsed_block, $block_obj foreach ( $key_array as $meta_key ) { $value = lsx_to_custom_field_query( $meta_key, '', '', false ); + + // we need to see if the posts exist before we can use them + if ( stripos( $meta_key, '_to_' ) && 0 === $this->post_ids_exist( $value ) ) { + continue; + } + if ( ! empty( $value ) && '' !== $value ) { $has_values = true; } @@ -848,23 +847,21 @@ public function prep_links( $items ) { * @param string $status Optional. Post status. * @return int Post ID if post exists, 0 otherwise. */ - protected function post_id_exists( $id ) { + protected function post_ids_exist( $ids ) { global $wpdb; - $post_id = wp_unslash( sanitize_post_field( 'id', $id, 0, 'db' ) ); - - $query = "SELECT ID FROM $wpdb->posts WHERE 1=1"; - $args = array(); - - if ( ! empty( $date ) ) { - $query .= ' AND ID = %d'; - $args[] = $post_id; + if ( is_array( $ids ) ) { + $ids = implode( ',', $ids ); } - if ( ! empty( $args ) ) { - return (int) $wpdb->get_var( $wpdb->prepare( $query, $args ) ); - } + $ids = wp_unslash( sanitize_post_field( 'id', $ids, 0, 'db' ) ); + + $query = "SELECT COUNT(ID) + FROM $wpdb->posts + WHERE 1=1 + AND ID IN (%s) + AND post_status IN ('draft', 'publish')"; - return 0; + return (int) $wpdb->get_var( $wpdb->prepare( $query, $ids ) ); } } From e3f233273d1514030b46ed04bb8b4ebde88e2701 Mon Sep 17 00:00:00 2001 From: Warwick Date: Wed, 20 Nov 2024 23:06:51 +0200 Subject: [PATCH 06/11] Moving the render block function --- includes/classes/blocks/class-bindings.php | 160 ----------------- .../classes/blocks/class-registration.php | 166 ++++++++++++++++++ 2 files changed, 166 insertions(+), 160 deletions(-) diff --git a/includes/classes/blocks/class-bindings.php b/includes/classes/blocks/class-bindings.php index 1bc7707e..67f9ddde 100644 --- a/includes/classes/blocks/class-bindings.php +++ b/includes/classes/blocks/class-bindings.php @@ -68,7 +68,6 @@ public function __construct() { add_filter( 'render_block', array( $this, 'render_units_block' ), 10, 3 ); add_filter( 'render_block', array( $this, 'render_gallery_block' ), 10, 3 ); add_filter( 'render_block', array( $this, 'render_map_block' ), 10, 3 ); - add_filter( 'render_block', array( $this, 'maybe_hide_varitaion' ), 10, 3 ); } public function register_block_bindings() { @@ -689,134 +688,6 @@ public function render_map_block( $block_content, $parsed_block, $block_obj ) { return $block_content; } - /** - * A function to detect variation, and alter the query args. - * - * Following the https://developer.wordpress.org/news/2022/12/building-a-book-review-grid-with-a-query-loop-block-variation/ - * - * @param string|null $pre_render The pre-rendered content. Default null. - * @param array $parsed_block The block being rendered. - * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block. - */ - public function maybe_hide_varitaion( $block_content, $parsed_block, $block_obj ) { - // Determine if this is the custom block variation. - if ( ! isset( $parsed_block['blockName'] ) || ! isset( $parsed_block['attrs'] ) ) { - return $block_content; - } - $allowed_blocks = array( - 'core/group', - ); - - if ( ! in_array( $parsed_block['blockName'], $allowed_blocks, true ) ) { - return $block_content; - } - if ( ! isset( $parsed_block['attrs']['className'] ) || '' === $parsed_block['attrs']['className'] || false === $parsed_block['attrs']['className'] ) { - return $block_content; - } - - $pattern = "/(lsx|facts)-(.*?)-wrapper/"; - preg_match( $pattern, $parsed_block['attrs']['className'], $matches ); - - if ( empty( $matches ) ) { - return $block_content; - } - - if ( ! empty( $matches ) && isset( $matches[0] ) ) { - // Save the first match to a variable - $key = str_replace( [ 'facts-', 'lsx-', '-wrapper' ], '', $matches[0] ); - } else { - return $block_content; - } - - /* - * 1 - Check if it is an itinerary or a units query - * 2 - See if it is a post query - * 3 - See if it is a taxonomy query - * 4 - Lastly default to the custom fields - */ - - if ( 0 < stripos( $key, '-query' ) ) { - - $query_key = str_replace( [ '-query' ], '', $key ); - $current_parent = get_post_parent( get_the_ID() ); - - switch ( $query_key ) { - case 'regions': - // If the current item is not a country - if ( null !== $current_parent ) { - return ''; - } - - if ( false === lsx_to_item_has_children( get_the_ID(), 'destination' ) ) { - return ''; - } - - break; - - case 'related-regions': - // If the current item is a country, then there wont be any other child regions. - if ( null === $current_parent ) { - return ''; - } - - if ( false === lsx_to_item_has_children( $current_parent, 'destination' ) ) { - return ''; - } - - break; - - case 'country': - // If the current item is not a country - if ( null === $current_parent ) { - return ''; - } - - break; - - default: - - - break; - } - } else if ( taxonomy_exists( $key ) ) { - // Check to see if this is a taxonomy or a custom field. - $tax_args = array( - 'fields' => 'ids' - ); - if ( empty( wp_get_post_terms( get_the_ID(), $key, $tax_args ) ) ) { - $block_content = ''; - } - } else { - $key = str_replace( '-', '_', $key ); - $key_array = [ $key ]; - $has_values = false; - - // If this is a wrapper that houses many fields, then we need to review them all. - if ( 'include_exclude' === $key ) { - $key_array = [ 'included', 'not_included' ]; - } - - foreach ( $key_array as $meta_key ) { - $value = lsx_to_custom_field_query( $meta_key, '', '', false ); - - // we need to see if the posts exist before we can use them - if ( stripos( $meta_key, '_to_' ) && 0 === $this->post_ids_exist( $value ) ) { - continue; - } - - if ( ! empty( $value ) && '' !== $value ) { - $has_values = true; - } - } - - if ( false === $has_values ) { - $block_content = ''; - } - } - - return $block_content; - } - /** * Takes an array of IDs and iterate to return the post links. * @@ -833,35 +704,4 @@ public function prep_links( $items ) { } return implode( ', ', $item_links ); } - - /** - * Determines if a post exists based on the ID. - * - * - * @global wpdb $wpdb WordPress database abstraction object. - * - * @param string $title Post title. - * @param string $content Optional. Post content. - * @param string $date Optional. Post date. - * @param string $type Optional. Post type. - * @param string $status Optional. Post status. - * @return int Post ID if post exists, 0 otherwise. - */ - protected function post_ids_exist( $ids ) { - global $wpdb; - - if ( is_array( $ids ) ) { - $ids = implode( ',', $ids ); - } - - $ids = wp_unslash( sanitize_post_field( 'id', $ids, 0, 'db' ) ); - - $query = "SELECT COUNT(ID) - FROM $wpdb->posts - WHERE 1=1 - AND ID IN (%s) - AND post_status IN ('draft', 'publish')"; - - return (int) $wpdb->get_var( $wpdb->prepare( $query, $ids ) ); - } } diff --git a/includes/classes/blocks/class-registration.php b/includes/classes/blocks/class-registration.php index ef26e083..7834cf91 100644 --- a/includes/classes/blocks/class-registration.php +++ b/includes/classes/blocks/class-registration.php @@ -18,6 +18,7 @@ class Registration { public function __construct() { add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_variations_script' ), 10 ); add_filter( 'query_loop_block_query_vars', array( $this, 'query_args_filter' ), 10, 2 ); + add_filter( 'render_block', array( $this, 'maybe_hide_varitaion' ), 10, 3 ); } /** @@ -94,6 +95,8 @@ public function query_args_filter( $query, $block ) { return $query; } + do_action( 'qm/debug', [ $key ] ); + switch ( $key ) { case 'regions': // We only restric this on the destination post type, in case the block is used on a landing page. @@ -174,6 +177,9 @@ public function query_args_filter( $query, $block ) { $query['post__in'] = $items; } } + + + $query['post__not_in'] = $excluded_items; break; @@ -212,4 +218,164 @@ public function query_args_filter( $query, $block ) { return $query; } + + /** + * A function to detect variation, and alter the query args. + * + * Following the https://developer.wordpress.org/news/2022/12/building-a-book-review-grid-with-a-query-loop-block-variation/ + * + * @param string|null $pre_render The pre-rendered content. Default null. + * @param array $parsed_block The block being rendered. + * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block. + */ + public function maybe_hide_varitaion( $block_content, $parsed_block, $block_obj ) { + // Determine if this is the custom block variation. + if ( ! isset( $parsed_block['blockName'] ) || ! isset( $parsed_block['attrs'] ) ) { + return $block_content; + } + $allowed_blocks = array( + 'core/group', + ); + + if ( ! in_array( $parsed_block['blockName'], $allowed_blocks, true ) ) { + return $block_content; + } + if ( ! isset( $parsed_block['attrs']['className'] ) || '' === $parsed_block['attrs']['className'] || false === $parsed_block['attrs']['className'] ) { + return $block_content; + } + + $pattern = "/(lsx|facts)-(.*?)-wrapper/"; + preg_match( $pattern, $parsed_block['attrs']['className'], $matches ); + + if ( empty( $matches ) ) { + return $block_content; + } + + if ( ! empty( $matches ) && isset( $matches[0] ) ) { + // Save the first match to a variable + $key = str_replace( [ 'facts-', 'lsx-', '-wrapper' ], '', $matches[0] ); + } else { + return $block_content; + } + + /* + * 1 - Check if it is an itinerary or a units query + * 2 - See if it is a post query + * 3 - See if it is a taxonomy query + * 4 - Lastly default to the custom fields + */ + + if ( 0 < stripos( $key, '-query' ) ) { + + $query_key = str_replace( [ '-query' ], '', $key ); + $current_parent = get_post_parent( get_the_ID() ); + + switch ( $query_key ) { + case 'regions': + // If the current item is not a country + if ( null !== $current_parent ) { + return ''; + } + + if ( false === lsx_to_item_has_children( get_the_ID(), 'destination' ) ) { + return ''; + } + + break; + + case 'related-regions': + // If the current item is a country, then there wont be any other child regions. + if ( null === $current_parent ) { + return ''; + } + + if ( false === lsx_to_item_has_children( $current_parent, 'destination' ) ) { + return ''; + } + + break; + + case 'country': + // If the current item is not a country + if ( null === $current_parent ) { + return ''; + } + + break; + + default: + + do_action( 'qm/debug', $query_key ); + + break; + } + } else if ( taxonomy_exists( $key ) ) { + // Check to see if this is a taxonomy or a custom field. + $tax_args = array( + 'fields' => 'ids' + ); + if ( empty( wp_get_post_terms( get_the_ID(), $key, $tax_args ) ) ) { + $block_content = ''; + } + } else { + $key = str_replace( '-', '_', $key ); + $key_array = [ $key ]; + $has_values = false; + + // If this is a wrapper that houses many fields, then we need to review them all. + if ( 'include_exclude' === $key ) { + $key_array = [ 'included', 'not_included' ]; + } + + foreach ( $key_array as $meta_key ) { + $value = lsx_to_custom_field_query( $meta_key, '', '', false ); + + // we need to see if the posts exist before we can use them + if ( stripos( $meta_key, '_to_' ) && 0 === $this->post_ids_exist( $value ) ) { + continue; + } + + if ( ! empty( $value ) && '' !== $value ) { + $has_values = true; + } + } + + if ( false === $has_values ) { + $block_content = ''; + } + } + + return $block_content; + } + + /** + * Determines if a post exists based on the ID. + * + * + * @global wpdb $wpdb WordPress database abstraction object. + * + * @param string $title Post title. + * @param string $content Optional. Post content. + * @param string $date Optional. Post date. + * @param string $type Optional. Post type. + * @param string $status Optional. Post status. + * @return int Post ID if post exists, 0 otherwise. + */ + protected function post_ids_exist( $ids ) { + global $wpdb; + + if ( is_array( $ids ) ) { + $ids = implode( ',', $ids ); + } + + $ids = wp_unslash( sanitize_post_field( 'id', $ids, 0, 'db' ) ); + + $query = "SELECT COUNT(ID) + FROM $wpdb->posts + WHERE 1=1 + AND ID IN (%s) + AND post_status IN ('draft', 'publish')"; + + return (int) $wpdb->get_var( $wpdb->prepare( $query, $ids ) ); + } } From fc3f23fcac54175740810f2d9a6acfa890733a0b Mon Sep 17 00:00:00 2001 From: Warwick Date: Wed, 20 Nov 2024 23:43:31 +0200 Subject: [PATCH 07/11] Updating the visibility for the featured and related blocks - #431 --- .../classes/blocks/class-registration.php | 59 +++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/includes/classes/blocks/class-registration.php b/includes/classes/blocks/class-registration.php index 7834cf91..9db094b1 100644 --- a/includes/classes/blocks/class-registration.php +++ b/includes/classes/blocks/class-registration.php @@ -8,6 +8,11 @@ * @author LightSpeed */ class Registration { + + protected $disabled = []; + + protected $featured = []; + /** * Initialize the plugin by setting localization, filters, and administration functions. * @@ -19,6 +24,8 @@ public function __construct() { add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_variations_script' ), 10 ); add_filter( 'query_loop_block_query_vars', array( $this, 'query_args_filter' ), 10, 2 ); add_filter( 'render_block', array( $this, 'maybe_hide_varitaion' ), 10, 3 ); + + add_filter( 'posts_pre_query', array( $this, 'posts_pre_query' ), 10, 2 ); } /** @@ -117,6 +124,7 @@ public function query_args_filter( $query, $block ) { case 'featured-accommodation': case 'featured-tours': case 'featured-destinations': + $query['meta_query'] = array( 'relation' => 'OR', array( @@ -126,6 +134,14 @@ public function query_args_filter( $query, $block ) { ), ); + $featured_items = $this->find_featured_items( $query ); + if ( ! empty( $featured_items ) ) { + $query['lsx_to_featured'] = $key; + $this->featured[ $key ] = $featured_items; + } else { + $this->disabled[ $key ] = true; + } + break; // Accommodation relating to the tour via the destinations. @@ -178,7 +194,9 @@ public function query_args_filter( $query, $block ) { } } - + if ( ! isset( $query['post__in'] ) ) { + $this->disabled[ $key ] = true; + } $query['post__not_in'] = $excluded_items; @@ -206,8 +224,8 @@ public function query_args_filter( $query, $block ) { } $query['post__in'] = $found_items; } else { - $query['no_relation'] = true; - $query['post__in'] = [ get_the_ID() ]; + $this->disabled[ $key ] = true; + $query['post__in'] = [ get_the_ID() ]; } break; @@ -304,8 +322,9 @@ public function maybe_hide_varitaion( $block_content, $parsed_block, $block_obj break; default: - - do_action( 'qm/debug', $query_key ); + if ( isset( $this->disabled[ $query_key ] ) ) { + return ''; + } break; } @@ -378,4 +397,34 @@ protected function post_ids_exist( $ids ) { return (int) $wpdb->get_var( $wpdb->prepare( $query, $ids ) ); } + + /** + * This function will grab our Featured query so we dont have to redo that. + * + * @param null $posts + * @param WP_Query $query + * @return null|array + */ + public function posts_pre_query( $posts, $query ) { + if ( isset( $query->query['lsx_to_featured'] ) && isset( $this->featured[ $query->query['lsx_to_featured'] ] ) ) { + do_action( 'qm/debug', $this->featured[ $query->query['lsx_to_featured'] ] ); + $posts = $this->featured[ $query->query['lsx_to_featured'] ]; + } + return $posts; + } + + /** + * Find the featured items for the current query + * + * @param array $query + * @return array + */ + public function find_featured_items( $query ) { + $items = []; + $item_query = new \WP_Query( $query ); + if ( $item_query->have_posts() ) { + $items = $item_query->posts; + } + return $items; + } } From bc36e3800388f3cd29ea2ac804944217e9fa3032 Mon Sep 17 00:00:00 2001 From: Warwick Date: Thu, 21 Nov 2024 00:23:20 +0200 Subject: [PATCH 08/11] Fixing the output of the tour custom field blocks. --- assets/js/blocks/general.js | 1 + assets/js/blocks/tour.js | 414 ++++++++++++++++++------------------ 2 files changed, 208 insertions(+), 207 deletions(-) diff --git a/assets/js/blocks/general.js b/assets/js/blocks/general.js index 6c9b0b2e..fbaf07b5 100644 --- a/assets/js/blocks/general.js +++ b/assets/js/blocks/general.js @@ -44,6 +44,7 @@ wp.domReady(() => { wp.blocks.registerBlockVariation("core/group", { name: "lsx-tour-operator/price", title: "Price", + category: 'lsx-tour-operator', icon: "bank", attributes: { metadata: { diff --git a/assets/js/blocks/tour.js b/assets/js/blocks/tour.js index 5b9f7abd..b009a6dd 100644 --- a/assets/js/blocks/tour.js +++ b/assets/js/blocks/tour.js @@ -159,136 +159,108 @@ wp.domReady(() => { allowedPostTypes: ['tour'] }); - // Price Included + Excluded - wp.registerBlockVariation( 'core/group', { - name: 'price-include-exclude', - title: 'Price Include & Exclude', - category: 'layout', + // Single Supplement + wp.blocks.registerBlockVariation('core/group', { + name: 'lsx-tour-operator/single-supplement-wrapper', + title: 'Single Supplement', + category: 'lsx-tour-operator', attributes: { - align: 'wide', - className: 'lsx-include-exclude-wrapper', + metadata: { + name: 'Single Supplement', + }, + className: 'lsx-single-supplement-wrapper', style: { spacing: { - padding: { - top: 'var:preset|spacing|x-small', - bottom: 'var:preset|spacing|x-small', - left: 'var:preset|spacing|x-small', - right: 'var:preset|spacing|x-small' - } - }, - border: { - radius: '8px', - width: '1px' + blockGap: '5px' } }, - backgroundColor: 'base', - borderColor: 'primary', layout: { - type: 'constrained' + type: 'flex', + flexWrap: 'nowrap' } }, innerBlocks: [ - [ - 'core/columns', { - align: 'wide', - style: { - spacing: { - blockGap: { - top: 'var:preset|spacing|medium', - left: 'var:preset|spacing|medium' - } - } - } - }, - [ - [ - 'core/column', { - width: '50%', - id: 'lsx-included-wrapper', + ['core/group', { style: { - spacing: { - blockGap: '0' - } - } + spacing: { + blockGap: '5px' + } + }, + layout: { + type: 'flex', + flexWrap: 'nowrap', + verticalAlignment: 'top' + } }, [ - [ - 'core/paragraph', { + ['core/image', { + id: 122733, + width: '20px', + sizeSlug: 'large', + linkDestination: 'none', + url: 'https://tour-operator.lsx.design/wp-content/uploads/2024/11/single-supplement-icon-black-52px-1.svg', + alt: '' + }], + ['core/paragraph', { style: { - elements: { - link: { - color: { - text: 'var:preset|color|primary-700' - } + spacing: { + padding: { + top: '2px', + bottom: '2px' + } } - } }, - textColor: 'primary-700', - fontSize: 'medium' - }, - [ 'Price Includes:' ] - ], - [ - 'core/paragraph', { - metadata: { - bindings: { - content: { - source: 'lsx/post-meta', - args: { key: 'included' } - } - } - } - }, - [] - ] + fontSize: 'x-small', + content: 'Single supplement:' + }] ] - ], - [ - 'core/column', { - width: '50%', - className: 'lsx-not-included-wrapper', + ], + ['core/group', { style: { - spacing: { - blockGap: '0' - } + spacing: { + blockGap: '5px' + }, + layout: { + type: 'flex', + flexWrap: 'nowrap' + } } }, [ - [ - 'core/paragraph', { - style: { - elements: { - link: { - color: { - text: 'var:preset|color|primary-700' + ['core/paragraph', { + metadata: { + bindings: { + content: { + source: 'lsx/post-meta', + args: { + key: 'single_supplement' + } + } } + }, + className: 'amount has-primary-color has-text-color has-link-color', + style: { + elements: { + link: { + color: { + text: 'var:preset|color|primary-700' + } + } + }, + spacing: { + padding: { + top: '2px', + bottom: '2px' + } } - } }, textColor: 'primary-700', - fontSize: 'medium' - }, - [ 'Price Excludes:' ] - ], - [ - 'core/paragraph', { - metadata: { - bindings: { - content: { - source: 'lsx/post-meta', - args: { key: 'not_included' } - } - } - } - }, - [] - ] - ] + content: '' + }] ] ] - ] ] - } ); + }); // Destination to Tour wp.blocks.registerBlockVariation("core/group", { @@ -326,7 +298,7 @@ wp.domReady(() => { [ 'core/image', { - width: 20, + width: '20px', sizeSlug: 'large', url: 'https://tour-operator.lsx.design/wp-content/uploads/2024/09/Typelocation-icon.png', alt: '' @@ -642,109 +614,6 @@ wp.domReady(() => { ] }); - // Single Supplement - wp.blocks.registerBlockVariation('core/group', { - name: 'lsx-tour-operator/single-supplement-wrapper', - title: 'Single Supplement', - category: 'lsx-tour-operator', - attributes: { - metadata: { - name: 'Single Supplement', - }, - className: 'lsx-single-supplement-wrapper', - style: { - spacing: { - blockGap: '5px' - } - }, - layout: { - type: 'flex', - flexWrap: 'nowrap' - } - }, - innerBlocks: [ - ['core/group', { - style: { - spacing: { - blockGap: '5px' - } - }, - layout: { - type: 'flex', - flexWrap: 'nowrap', - verticalAlignment: 'top' - } - }, - [ - ['core/image', { - id: 122733, - width: 20, - sizeSlug: 'large', - linkDestination: 'none', - url: 'https://tour-operator.lsx.design/wp-content/uploads/2024/11/single-supplement-icon-black-52px-1.svg', - alt: '' - }], - ['core/paragraph', { - style: { - spacing: { - padding: { - top: '2px', - bottom: '2px' - } - } - }, - fontSize: 'x-small', - content: 'Single supplement:' - }] - ] - ], - ['core/group', { - style: { - spacing: { - blockGap: '5px' - }, - layout: { - type: 'flex', - flexWrap: 'nowrap' - } - } - }, - [ - ['core/paragraph', { - metadata: { - bindings: { - content: { - source: 'lsx/post-meta', - args: { - key: 'single_supplement' - } - } - } - }, - className: 'amount has-primary-color has-text-color has-link-color', - style: { - elements: { - link: { - color: { - text: 'var:preset|color|primary-700' - } - } - }, - spacing: { - padding: { - top: '2px', - bottom: '2px' - } - } - }, - textColor: 'primary-700', - content: '' - }] - ] - ] - ] - }); - // Booking Validity wp.blocks.registerBlockVariation('core/group', { name: 'lsx-tour-operator/booking-validity-start', @@ -1086,4 +955,135 @@ wp.domReady(() => { ] ] }); + + // Price Included + Excluded + wp.blocks.registerBlockVariation( 'core/group', { + name: 'price-include-exclude', + title: 'Price Include & Exclude', + category: 'layout', + attributes: { + align: 'wide', + className: 'lsx-include-exclude-wrapper', + style: { + spacing: { + padding: { + top: 'var:preset|spacing|x-small', + bottom: 'var:preset|spacing|x-small', + left: 'var:preset|spacing|x-small', + right: 'var:preset|spacing|x-small' + } + }, + border: { + radius: '8px', + width: '1px' + } + }, + backgroundColor: 'base', + borderColor: 'primary', + layout: { + type: 'constrained' + } + }, + innerBlocks: [ + [ + 'core/columns', { + align: 'wide', + style: { + spacing: { + blockGap: { + top: 'var:preset|spacing|medium', + left: 'var:preset|spacing|medium' + } + } + } + }, + [ + [ + 'core/column', { + width: '50%', + id: 'lsx-included-wrapper', + style: { + spacing: { + blockGap: '0' + } + } + }, + [ + [ + 'core/paragraph', { + style: { + elements: { + link: { + color: { + text: 'var:preset|color|primary-700' + } + } + } + }, + textColor: 'primary-700', + fontSize: 'medium' + }, + [ 'Price Includes:' ] + ], + [ + 'core/paragraph', { + metadata: { + bindings: { + content: { + source: 'lsx/post-meta', + args: { key: 'included' } + } + } + } + }, + [] + ] + ] + ], + [ + 'core/column', { + width: '50%', + className: 'lsx-not-included-wrapper', + style: { + spacing: { + blockGap: '0' + } + } + }, + [ + [ + 'core/paragraph', { + style: { + elements: { + link: { + color: { + text: 'var:preset|color|primary-700' + } + } + } + }, + textColor: 'primary-700', + fontSize: 'medium' + }, + [ 'Price Excludes:' ] + ], + [ + 'core/paragraph', { + metadata: { + bindings: { + content: { + source: 'lsx/post-meta', + args: { key: 'not_included' } + } + } + } + }, + [] + ] + ] + ] + ] + ] + ] + } ); }); From 2944f6273bc706055116cef005627301184cbdc7 Mon Sep 17 00:00:00 2001 From: Warwick Date: Thu, 21 Nov 2024 00:48:20 +0200 Subject: [PATCH 09/11] Fixing the price includes and excludes innerBlock Structure --- assets/js/blocks/tour.js | 166 ++++++++---------- .../classes/blocks/class-registration.php | 6 +- 2 files changed, 81 insertions(+), 91 deletions(-) diff --git a/assets/js/blocks/tour.js b/assets/js/blocks/tour.js index b009a6dd..5b0c180b 100644 --- a/assets/js/blocks/tour.js +++ b/assets/js/blocks/tour.js @@ -958,11 +958,14 @@ wp.domReady(() => { // Price Included + Excluded wp.blocks.registerBlockVariation( 'core/group', { - name: 'price-include-exclude', + name: 'lsx-tour-operator/price-include-exclude', title: 'Price Include & Exclude', - category: 'layout', + category: 'lsx-tour-operator', attributes: { align: 'wide', + metadata: { + name: 'Price Include & Exclude', + }, className: 'lsx-include-exclude-wrapper', style: { spacing: { @@ -985,104 +988,91 @@ wp.domReady(() => { } }, innerBlocks: [ - [ - 'core/columns', { - align: 'wide', - style: { - spacing: { - blockGap: { - top: 'var:preset|spacing|medium', - left: 'var:preset|spacing|medium' - } - } - } - }, - [ - [ - 'core/column', { - width: '50%', - id: 'lsx-included-wrapper', + [ 'core/columns', { + align: 'wide', style: { - spacing: { - blockGap: '0' - } - } - }, - [ - [ - 'core/paragraph', { - style: { - elements: { - link: { - color: { - text: 'var:preset|color|primary-700' - } - } - } - }, - textColor: 'primary-700', - fontSize: 'medium' - }, - [ 'Price Includes:' ] - ], - [ - 'core/paragraph', { - metadata: { - bindings: { - content: { - source: 'lsx/post-meta', - args: { key: 'included' } + spacing: { + blockGap: { + top: 'var:preset|spacing|medium', + left: 'var:preset|spacing|medium' } } - } - }, - [] - ] - ] - ], - [ - 'core/column', { - width: '50%', - className: 'lsx-not-included-wrapper', - style: { - spacing: { - blockGap: '0' - } } }, [ - [ - 'core/paragraph', { - style: { - elements: { - link: { - color: { - text: 'var:preset|color|primary-700' - } + ['core/column', { + width: '50%', + id: 'lsx-included-wrapper', + style: { + spacing: { + blockGap: '0' + } } - } }, - textColor: 'primary-700', - fontSize: 'medium' - }, - [ 'Price Excludes:' ] + [ + [ 'core/paragraph', { + style: { + elements: { + link: { + color: { + text: 'var:preset|color|primary-700' + } + } + } + }, + textColor: 'primary-700', + fontSize: 'medium', + content: 'Price Includes:' + } ], + [ 'core/paragraph', { + metadata: { + bindings: { + content: { + source: 'lsx/post-meta', + args: { key: 'included' } + } + } + } + }] + ] ], - [ - 'core/paragraph', { - metadata: { - bindings: { - content: { - source: 'lsx/post-meta', - args: { key: 'not_included' } + [ 'core/column', { + width: '50%', + className: 'lsx-not-included-wrapper', + style: { + spacing: { + blockGap: '0' + } } - } - } - }, - [] + }, + [ + [ 'core/paragraph', { + style: { + elements: { + link: { + color: { + text: 'var:preset|color|primary-700' + } + } + } + }, + textColor: 'primary-700', + fontSize: 'medium', + content: 'Price Excludes:' + }], + [ 'core/paragraph', { + metadata: { + bindings: { + content: { + source: 'lsx/post-meta', + args: { key: 'not_included' } + } + } + } + }] + ] ] ] - ] - ] ] ] } ); diff --git a/includes/classes/blocks/class-registration.php b/includes/classes/blocks/class-registration.php index 9db094b1..5bd6db32 100644 --- a/includes/classes/blocks/class-registration.php +++ b/includes/classes/blocks/class-registration.php @@ -38,9 +38,9 @@ public function enqueue_block_variations_script() { $scripts = [ 'general' => '', 'tour' => '', - 'accommodation' => '', - 'destination' => '', - 'query-loops' => '', + //'accommodation' => '', + //'destination' => '', + //'query-loops' => '', ]; // Make sure the script is only enqueued in the block editor. From af885d7e77dba994219a9fd6d4e4503a8c5d425b Mon Sep 17 00:00:00 2001 From: Warwick Date: Thu, 21 Nov 2024 00:59:40 +0200 Subject: [PATCH 10/11] Fixing the display of the currencies --- includes/classes/legacy/class-accommodation.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/includes/classes/legacy/class-accommodation.php b/includes/classes/legacy/class-accommodation.php index 01e29bdb..b96d28ef 100644 --- a/includes/classes/legacy/class-accommodation.php +++ b/includes/classes/legacy/class-accommodation.php @@ -119,7 +119,8 @@ function entry_class( $classes ) { */ public function price_filter( $html = '', $meta_key = false, $value = false, $before = '', $after = '' ) { $currency_fields = [ - 'price' + 'price', + 'single_supplement' ]; if ( get_post_type() === 'accommodation' && in_array( $meta_key, $currency_fields ) ) { @@ -131,11 +132,9 @@ public function price_filter( $html = '', $meta_key = false, $value = false, $be $tour_operator = tour_operator(); $currency = ''; - if ( is_object( $tour_operator ) && isset( $tour_operator->options['general'] ) && is_array( $tour_operator->options['general'] ) ) { - if ( isset( $tour_operator->options['general']['currency'] ) && ! empty( $tour_operator->options['general']['currency'] ) ) { - $currency = $tour_operator->options['general']['currency']; - $currency = '' . $currency . ''; - } + if ( is_object( $tour_operator ) && isset( $tour_operator->options['currency'] ) && ! empty( $tour_operator->options['currency'] ) ) { + $currency = $tour_operator->options['currency']; + $currency = '' . $currency . ''; } $value = apply_filters( 'lsx_to_accommodation_price', $value, $price_type, $currency ); From cb02978da7f6160c94dbbaf081fe782c30ae9af3 Mon Sep 17 00:00:00 2001 From: Warwick Date: Thu, 21 Nov 2024 10:00:56 +0200 Subject: [PATCH 11/11] Removing the commented out code. --- includes/classes/blocks/class-registration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/classes/blocks/class-registration.php b/includes/classes/blocks/class-registration.php index 5bd6db32..9db094b1 100644 --- a/includes/classes/blocks/class-registration.php +++ b/includes/classes/blocks/class-registration.php @@ -38,9 +38,9 @@ public function enqueue_block_variations_script() { $scripts = [ 'general' => '', 'tour' => '', - //'accommodation' => '', - //'destination' => '', - //'query-loops' => '', + 'accommodation' => '', + 'destination' => '', + 'query-loops' => '', ]; // Make sure the script is only enqueued in the block editor.