Skip to content

Commit

Permalink
(refactor): remove ',-' from old lege prices while executing WP Cron …
Browse files Browse the repository at this point in the history
…event LegesPricesSaveFormat
  • Loading branch information
Mike van den Hoek committed Sep 24, 2024
1 parent 2aeca9f commit dd56084
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 2.2.2

### Changed

- Remove ',-' from old lege prices while executing WP Cron event LegesPricesSaveFormat

## 2.2.1

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pdc-leges.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: PDC Leges
* Plugin URI: https://www.openwebconcept.nl
* Description: PDC Leges
* Version: 2.2.1
* Version: 2.2.2
* Author: Yard | Digital agency
* Author URI: https://www.yard.nl/
* License: EUPL-1.2
Expand Down
2 changes: 1 addition & 1 deletion src/Leges/Foundation/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Plugin extends BasePlugin
* Version of the plugin.
* Used for setting versions of enqueue scripts and styles.
*/
const VERSION = '2.2.1';
const VERSION = '2.2.2';

protected function checkForUpdate()
{
Expand Down
20 changes: 18 additions & 2 deletions src/Leges/WPCron/Events/LegesPricesSaveFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,29 @@ protected function sanitizeAndUpdatePriceMeta(WP_Post $legesPost): void
$newPrice = get_post_meta($legesPost->ID, self::META_KEY_NEW_PRICE, true);

if (! empty($oldPrice)) {
$oldPrice = str_replace(',', '.', $oldPrice);
$oldPrice = $this->prepareFloatSanitation($oldPrice);
update_post_meta($legesPost->ID, self::META_KEY_OLD_PRICE, $this->sanitizeFloat($oldPrice));
}

if (! empty($newPrice)) {
$newPrice = str_replace(',', '.', $newPrice);
$newPrice = $this->prepareFloatSanitation($newPrice);
update_post_meta($legesPost->ID, self::META_KEY_NEW_PRICE, $this->sanitizeFloat($newPrice));
}
}

/**
* Converts a price string from a non-standard format (e.g., with commas as decimal separators
* or trailing currency symbols) into a sanitized format with a dot (.) as the decimal separator.
*
* This method:
* - Removes trailing currency indicators like ",-" from the price string.
* - Replaces commas (",") used as decimal separators with dots (".") for consistency.
*/
protected function prepareFloatSanitation(string $price): string
{
$price = str_replace(',-', '', $price);
$price = str_replace(',', '.', $price);

return $price;
}
}

0 comments on commit dd56084

Please sign in to comment.