diff --git a/includes/fbproduct.php b/includes/fbproduct.php index f864b29c..22bcd392 100644 --- a/includes/fbproduct.php +++ b/includes/fbproduct.php @@ -457,31 +457,31 @@ public function add_sale_price( $product_data, $for_items_batch = false ) { $sale_price = $this->woo_product->get_sale_price(); $sale_price_effective_date = ''; - - $sale_start = - ( $date = $this->woo_product->get_date_on_sale_from() ) - ? date_i18n( WC_DateTime::ATOM, $date->getOffsetTimestamp() ) - : self::MIN_DATE_1 . self::MIN_TIME; - - $sale_end = - ( $date = $this->woo_product->get_date_on_sale_to() ) - ? date_i18n( WC_DateTime::ATOM, $date->getOffsetTimestamp() ) - : self::MAX_DATE . self::MAX_TIME; + $sale_start = ''; + $sale_end = ''; // check if sale exist if ( is_numeric( $sale_price ) && $sale_price > 0 ) { + $sale_start = + ( $date = $this->woo_product->get_date_on_sale_from() ) + ? date_i18n( WC_DateTime::ATOM, $date->getOffsetTimestamp() ) + : self::MIN_DATE_1 . self::MIN_TIME; + $sale_end = + ( $date = $this->woo_product->get_date_on_sale_to() ) + ? date_i18n( WC_DateTime::ATOM, $date->getOffsetTimestamp() ) + : self::MAX_DATE . self::MAX_TIME; $sale_price_effective_date = ( $sale_start == self::MIN_DATE_1 . self::MIN_TIME && $sale_end == self::MAX_DATE . self::MAX_TIME ) ? '' : $sale_start . '/' . $sale_end; $sale_price = intval( round( $this->get_price_plus_tax( $sale_price ) * 100 ) ); - } - // Set Sale start and end as empty if set to default values - if ( $sale_start == self::MIN_DATE_1 . self::MIN_TIME && $sale_end == self::MAX_DATE . self::MAX_TIME ) { - $sale_start = ''; - $sale_end = ''; + // Set Sale start and end as empty if set to default values + if ( $sale_start == self::MIN_DATE_1 . self::MIN_TIME && $sale_end == self::MAX_DATE . self::MAX_TIME ) { + $sale_start = ''; + $sale_end = ''; + } } // check if sale is expired and sale time range is valid diff --git a/tests/Unit/fbproductTest.php b/tests/Unit/fbproductTest.php index cff16d3b..36b1b2bf 100644 --- a/tests/Unit/fbproductTest.php +++ b/tests/Unit/fbproductTest.php @@ -107,7 +107,7 @@ public function test_filter_fb_description() { /** * Test Data Provider for sale_price related fields */ - public function provideSalePriceData() { + public function provide_sale_price_data() { return [ [ 11.5, @@ -139,6 +139,16 @@ public function provideSalePriceData() { '', '', ], + [ + null, + '2024-08-08', + '2024-08-18', + 0, + '', + '', + '', + '', + ], [ 11, '2024-08-08', @@ -175,7 +185,7 @@ public function provideSalePriceData() { /** * Test that sale_price related fields are being set correctly while preparing product. * - * @dataProvider provideSalePriceData + * @dataProvider provide_sale_price_data * @return void */ public function test_sale_price_and_effective_date(