From a02ecb30d773205dd02b584ead47bf1817054177 Mon Sep 17 00:00:00 2001 From: Kruti Dugade Date: Thu, 20 Jul 2023 11:12:50 +0100 Subject: [PATCH 1/6] Validates if product name is in ALL CAPS when product is updated or published. --- facebook-commerce.php | 19 +++++++++++++++++++ includes/ProductSync/ProductValidator.php | 4 ---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/facebook-commerce.php b/facebook-commerce.php index db9c82518..c42af0404 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -374,6 +374,25 @@ public function __construct( WC_Facebookcommerce $facebook_for_woocommerce ) { // Product Set hooks. add_action( 'fb_wc_product_set_sync', [ $this, 'create_or_update_product_set_item' ], 99, 2 ); add_action( 'fb_wc_product_set_delete', [ $this, 'delete_product_set_item' ], 99 ); + + // Show notice if a product with ALL CAPS name is published or updated. + add_action( 'woocommerce_new_product', [ $this, 'show_all_caps_notice' ], 10, 2 ); + add_action( 'woocommerce_update_product', [ $this, 'show_all_caps_notice' ], 10, 2 ); + } + + /** + * Validate if product name contains ALL CAPS. + * Show notice if true. + * + * @param int $product_id + * @param object $product + */ + public function show_all_caps_notice( $product_id, $product ) { + + // Checks if product title contains ALL CAPS. + if ( \WC_Facebookcommerce_Utils::is_all_caps( $product->get_name() ) ) { + //TODO: pop up modal window to show notice + } } /** diff --git a/includes/ProductSync/ProductValidator.php b/includes/ProductSync/ProductValidator.php index 1dd076b90..77e3362fa 100644 --- a/includes/ProductSync/ProductValidator.php +++ b/includes/ProductSync/ProductValidator.php @@ -388,12 +388,8 @@ protected function validate_product_title() { /* * Requirements: - * - No all caps title. * - Max length 150. */ - if ( \WC_Facebookcommerce_Utils::is_all_caps( $title ) ) { - throw new ProductInvalidException( __( 'Product title is all capital letters. Please change the title to sentence case in order to allow synchronization of your product.', 'facebook-for-woocommerce' ) ); - } if ( mb_strlen( $title, 'UTF-8' ) > self::MAX_TITLE_LENGTH ) { throw new ProductInvalidException( __( 'Product title is too long. Maximum allowed length is 150 characters.', 'facebook-for-woocommerce' ) ); } From b3f5d2ed91b24d808d057333242ff1ed4b982b51 Mon Sep 17 00:00:00 2001 From: Kruti Dugade Date: Mon, 24 Jul 2023 15:01:37 +0100 Subject: [PATCH 2/6] Revert "Validates if product name is in ALL CAPS when product is updated or published." This reverts commit a02ecb30d773205dd02b584ead47bf1817054177. --- facebook-commerce.php | 19 ------------------- includes/ProductSync/ProductValidator.php | 4 ++++ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/facebook-commerce.php b/facebook-commerce.php index c42af0404..db9c82518 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -374,25 +374,6 @@ public function __construct( WC_Facebookcommerce $facebook_for_woocommerce ) { // Product Set hooks. add_action( 'fb_wc_product_set_sync', [ $this, 'create_or_update_product_set_item' ], 99, 2 ); add_action( 'fb_wc_product_set_delete', [ $this, 'delete_product_set_item' ], 99 ); - - // Show notice if a product with ALL CAPS name is published or updated. - add_action( 'woocommerce_new_product', [ $this, 'show_all_caps_notice' ], 10, 2 ); - add_action( 'woocommerce_update_product', [ $this, 'show_all_caps_notice' ], 10, 2 ); - } - - /** - * Validate if product name contains ALL CAPS. - * Show notice if true. - * - * @param int $product_id - * @param object $product - */ - public function show_all_caps_notice( $product_id, $product ) { - - // Checks if product title contains ALL CAPS. - if ( \WC_Facebookcommerce_Utils::is_all_caps( $product->get_name() ) ) { - //TODO: pop up modal window to show notice - } } /** diff --git a/includes/ProductSync/ProductValidator.php b/includes/ProductSync/ProductValidator.php index 77e3362fa..1dd076b90 100644 --- a/includes/ProductSync/ProductValidator.php +++ b/includes/ProductSync/ProductValidator.php @@ -388,8 +388,12 @@ protected function validate_product_title() { /* * Requirements: + * - No all caps title. * - Max length 150. */ + if ( \WC_Facebookcommerce_Utils::is_all_caps( $title ) ) { + throw new ProductInvalidException( __( 'Product title is all capital letters. Please change the title to sentence case in order to allow synchronization of your product.', 'facebook-for-woocommerce' ) ); + } if ( mb_strlen( $title, 'UTF-8' ) > self::MAX_TITLE_LENGTH ) { throw new ProductInvalidException( __( 'Product title is too long. Maximum allowed length is 150 characters.', 'facebook-for-woocommerce' ) ); } From 1c485d37047658dc9c7daac0d4b13fc2a1b1035f Mon Sep 17 00:00:00 2001 From: Kruti Dugade Date: Mon, 24 Jul 2023 17:24:00 +0100 Subject: [PATCH 3/6] Syncs products with All Caps product title. Displays warning in Facebook metabox about potential issue with synchronization of the product. --- includes/Admin/Product_Sync_Meta_Box.php | 5 +++++ includes/ProductSync/ProductValidator.php | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/includes/Admin/Product_Sync_Meta_Box.php b/includes/Admin/Product_Sync_Meta_Box.php index afc0db2c2..a1e0fe50d 100644 --- a/includes/Admin/Product_Sync_Meta_Box.php +++ b/includes/Admin/Product_Sync_Meta_Box.php @@ -83,6 +83,11 @@ public static function output() { + get_title() ) ) { + echo esc_html__( 'may have issue with synchronisation as product title is all capital letters. Please change the title to sentence case to ensure product is synchronized.', 'facebook-for-woocommerce' ); ?>
+ + get_type() ) ) : ?> self::MAX_TITLE_LENGTH ) { throw new ProductInvalidException( __( 'Product title is too long. Maximum allowed length is 150 characters.', 'facebook-for-woocommerce' ) ); } From 2b39868964ca68188e39c4bbf262e8ced619539c Mon Sep 17 00:00:00 2001 From: Kruti Dugade Date: Mon, 24 Jul 2023 18:44:59 +0100 Subject: [PATCH 4/6] Fixes PHPCS issue. --- includes/Admin/Product_Sync_Meta_Box.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/Admin/Product_Sync_Meta_Box.php b/includes/Admin/Product_Sync_Meta_Box.php index a1e0fe50d..2f5d0663b 100644 --- a/includes/Admin/Product_Sync_Meta_Box.php +++ b/includes/Admin/Product_Sync_Meta_Box.php @@ -83,10 +83,16 @@ public static function output() { - get_title() ) ) { - echo esc_html__( 'may have issue with synchronisation as product title is all capital letters. Please change the title to sentence case to ensure product is synchronized.', 'facebook-for-woocommerce' ); ?>
+ get_title() ) ) { + echo esc_html__( 'may have issue with synchronisation as product title is all capital letters. Please change the title to sentence case to ensure product is synchronized.', 'facebook-for-woocommerce' ); + ?> +
+ + } + ?> get_type() ) ) : ?> From 6db191bb3277b175eff2281d7e859d734496e8ed Mon Sep 17 00:00:00 2001 From: Kruti Dugade Date: Wed, 26 Jul 2023 16:37:36 +0100 Subject: [PATCH 5/6] Displays product title all caps notice below FB and variant IDs in FB metabox. --- includes/Admin/Product_Sync_Meta_Box.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/includes/Admin/Product_Sync_Meta_Box.php b/includes/Admin/Product_Sync_Meta_Box.php index 2f5d0663b..0084869ab 100644 --- a/includes/Admin/Product_Sync_Meta_Box.php +++ b/includes/Admin/Product_Sync_Meta_Box.php @@ -83,17 +83,6 @@ public static function output() { - get_title() ) ) { - echo esc_html__( 'may have issue with synchronisation as product title is all capital letters. Please change the title to sentence case to ensure product is synchronized.', 'facebook-for-woocommerce' ); - ?> -
- - - get_type() ) ) : ?> + + + get_title() ) ): ?> +

+ From adb797cb9908bd2bc3ea69d3346431e30a7dedfb Mon Sep 17 00:00:00 2001 From: Kruti Dugade Date: Wed, 26 Jul 2023 16:42:08 +0100 Subject: [PATCH 6/6] Fixes PHPCS issue. --- includes/Admin/Product_Sync_Meta_Box.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Admin/Product_Sync_Meta_Box.php b/includes/Admin/Product_Sync_Meta_Box.php index 0084869ab..058025b03 100644 --- a/includes/Admin/Product_Sync_Meta_Box.php +++ b/includes/Admin/Product_Sync_Meta_Box.php @@ -119,7 +119,7 @@ public static function output() { - get_title() ) ): ?> + get_title() ) ) : ?>