From 8255399d245ef6eba1570fee3d86c10c7f812851 Mon Sep 17 00:00:00 2001 From: Raymon Akladious Date: Wed, 26 Mar 2025 18:08:53 +0000 Subject: [PATCH] Relaxing sync validation --- includes/ProductSync/ProductValidator.php | 89 ----------------------- 1 file changed, 89 deletions(-) diff --git a/includes/ProductSync/ProductValidator.php b/includes/ProductSync/ProductValidator.php index 8ac8d9f56..06655fa9b 100644 --- a/includes/ProductSync/ProductValidator.php +++ b/includes/ProductSync/ProductValidator.php @@ -28,20 +28,6 @@ class ProductValidator { */ public const SYNC_ENABLED_META_KEY = '_wc_facebook_sync_enabled'; - /** - * Maximum length of product description. - * - * @var int - */ - public const MAX_DESCRIPTION_LENGTH = 5000; - - /** - * Maximum length of product title. - * - * @var int - */ - public const MAX_TITLE_LENGTH = 150; - /** * Maximum allowed attributes in a variation; * @@ -134,11 +120,8 @@ public function validate() { $this->validate_sync_enabled_globally(); $this->validate_product_status(); $this->validate_product_sync_field(); - $this->validate_product_price(); $this->validate_product_visibility(); $this->validate_product_terms(); - $this->validate_product_description(); - $this->validate_product_title(); } /** @@ -151,11 +134,8 @@ public function validate() { public function validate_but_skip_status_check() { $this->validate_sync_enabled_globally(); $this->validate_product_sync_field(); - $this->validate_product_price(); $this->validate_product_visibility(); $this->validate_product_terms(); - $this->validate_product_description(); - $this->validate_product_title(); } /** @@ -166,11 +146,8 @@ public function validate_but_skip_status_check() { */ public function validate_but_skip_sync_field() { $this->validate_sync_enabled_globally(); - $this->validate_product_price(); $this->validate_product_visibility(); $this->validate_product_terms(); - $this->validate_product_description(); - $this->validate_product_title(); } /** @@ -361,72 +338,6 @@ protected function validate_product_sync_field() { } } - /** - * "allow simple or variable products (and their variations) with zero or empty price - exclude other product types with zero or empty price" - * unsure why but that's what we're doing - * - * @throws ProductExcludedException If product should not be synced. - */ - protected function validate_product_price() { - $primary_product = $this->product_parent ? $this->product_parent : $this->product; - - // Variable and simple products are allowed to have no price. - if ( in_array( $primary_product->get_type(), [ 'simple', 'variable' ], true ) ) { - return; - } - - if ( ! Products::get_product_price( $this->product ) ) { - throw new ProductExcludedException( __( 'If product is not simple, variable or variation it must have a price.', 'facebook-for-woocommerce' ) ); - } - } - - /** - * Check if the description field has correct format according to: - * Product Description Specifications for Catalogs : https://www.facebook.com/business/help/2302017289821154 - * - * @throws ProductInvalidException If product description does not meet the requirements. - */ - protected function validate_product_description() { - /* - * First step is to select the description that we want to evaluate. - * Main description is the one provided for the product in the Facebook. - * If it is blank, product description will be used. - * If product description is blank, shortname will be used. - */ - $description = $this->facebook_product->get_fb_description(); - - /* - * Requirements: - * - No all caps descriptions. - * - Max length 5000. - * - Min length 30 ( tested and not required, will not enforce until this will become a hard requirement ) - */ - if ( \WC_Facebookcommerce_Utils::is_all_caps( $description ) ) { - throw new ProductInvalidException( __( 'Product description is all capital letters. Please change the description to sentence case in order to allow synchronization of your product.', 'facebook-for-woocommerce' ) ); - } - if ( strlen( $description ) > self::MAX_DESCRIPTION_LENGTH ) { - throw new ProductInvalidException( __( 'Product description is too long. Maximum allowed length is 5000 characters.', 'facebook-for-woocommerce' ) ); - } - } - - /** - * Check if the title field has correct format according to: - * Product Title Specifications for Catalogs : https://www.facebook.com/business/help/2104231189874655 - * - * @throws ProductInvalidException If product title does not meet the requirements. - */ - protected function validate_product_title() { - $title = $this->product->get_title(); - - /* - * Requirements: - * - Max length 150. - */ - 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' ) ); - } - } - /** * Check if variation product has proper settings. *