Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 0 additions & 89 deletions includes/ProductSync/ProductValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
*
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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();
}

/**
Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down