Use WooCommerce wrapper instead of native functions, test if WC is active

[MAILPOET-5092]
This commit is contained in:
David Remer
2023-06-19 09:00:45 +03:00
committed by Aschepikov
parent 8b1d51fcd6
commit 190da3b0e5
2 changed files with 31 additions and 9 deletions

View File

@ -24,6 +24,7 @@ use MailPoet\Tracy\DIPanel\DIPanel;
use MailPoet\Util\Installation; use MailPoet\Util\Installation;
use MailPoet\Util\License\Features\Subscribers as SubscribersFeature; use MailPoet\Util\License\Features\Subscribers as SubscribersFeature;
use MailPoet\Util\License\License; use MailPoet\Util\License\License;
use MailPoet\WooCommerce;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
use MailPoet\WP\Notice as WPNotice; use MailPoet\WP\Notice as WPNotice;
use MailPoetVendor\Carbon\Carbon; use MailPoetVendor\Carbon\Carbon;
@ -74,6 +75,9 @@ class PageRenderer {
/*** @var AssetsController */ /*** @var AssetsController */
private $assetsController; private $assetsController;
/** @var WooCommerce\Helper */
private $wooCommerceHelper;
public function __construct( public function __construct(
Bridge $bridge, Bridge $bridge,
Renderer $renderer, Renderer $renderer,
@ -89,7 +93,8 @@ class PageRenderer {
TrackingConfig $trackingConfig, TrackingConfig $trackingConfig,
TransientCache $transientCache, TransientCache $transientCache,
WPFunctions $wp, WPFunctions $wp,
AssetsController $assetsController AssetsController $assetsController,
WooCommerce\Helper $wooCommerceHelper
) { ) {
$this->bridge = $bridge; $this->bridge = $bridge;
$this->renderer = $renderer; $this->renderer = $renderer;
@ -106,6 +111,7 @@ class PageRenderer {
$this->transientCache = $transientCache; $this->transientCache = $transientCache;
$this->wp = $wp; $this->wp = $wp;
$this->assetsController = $assetsController; $this->assetsController = $assetsController;
$this->wooCommerceHelper = $wooCommerceHelper;
} }
/** /**
@ -182,7 +188,7 @@ class PageRenderer {
'automationEditor' => admin_url('admin.php?page=mailpoet-automation-editor'), 'automationEditor' => admin_url('admin.php?page=mailpoet-automation-editor'),
'automationTemplates' => admin_url('admin.php?page=mailpoet-automation-templates'), 'automationTemplates' => admin_url('admin.php?page=mailpoet-automation-templates'),
], ],
'woocommerce_store_config' => $this->woocommerceStoreConfig(), 'woocommerce_store_config' => $this->wooCommerceHelper->isWooCommerceActive() ? $this->woocommerceStoreConfig() : null,
'tags' => array_map(function (TagEntity $tag): array { 'tags' => array_map(function (TagEntity $tag): array {
return [ return [
'id' => $tag->getId(), 'id' => $tag->getId(),
@ -219,13 +225,13 @@ class PageRenderer {
private function woocommerceStoreConfig() { private function woocommerceStoreConfig() {
return [ return [
'precision' => wc_get_price_decimals(), 'precision' => $this->wooCommerceHelper->wcGetPriceDecimals(),
'decimalSeparator' => wc_get_price_decimal_separator(), 'decimalSeparator' => $this->wooCommerceHelper->wcGetPriceDecimalSeperator(),
'thousandSeparator' => wc_get_price_thousand_separator(), 'thousandSeparator' => $this->wooCommerceHelper->wcGetPriceThousandSeparator(),
'code' => get_woocommerce_currency(), 'code' => $this->wooCommerceHelper->getWoocommerceCurrency(),
'symbol' => html_entity_decode(get_woocommerce_currency_symbol()), 'symbol' => html_entity_decode($this->wooCommerceHelper->getWoocommerceCurrencySymbol()),
'symbolPosition' => get_option('woocommerce_currency_pos'), 'symbolPosition' => $this->wp->getOption('woocommerce_currency_pos'),
'priceFormat' => get_woocommerce_price_format(), 'priceFormat' => $this->wooCommerceHelper->getWoocommercePriceFormat(),
]; ];
} }

View File

@ -82,6 +82,22 @@ class Helper {
return null; return null;
} }
public function wcGetPriceDecimals(): int {
return wc_get_price_decimals();
}
public function wcGetPriceDecimalSeperator(): string {
return wc_get_price_decimal_separator();
}
public function wcGetPriceThousandSeparator(): string {
return wc_get_price_thousand_separator();
}
public function getWoocommercePriceFormat(): string {
return get_woocommerce_price_format();
}
public function getWoocommerceCurrency() { public function getWoocommerceCurrency() {
return get_woocommerce_currency(); return get_woocommerce_currency();
} }