← All changes
|
src/Addons/GlobalTieredPricing/GlobalTieredPricingAddon.php
+30
-2
6.1.0
→
8.1.0
View file →
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php namespace TierPricingTable\Addons\GlobalTieredPricing; |
| 2 | 2 | |
| 3 | 3 | use TierPricingTable\Addons\AbstractAddon; |
| 4 | 4 | use TierPricingTable\Addons\GlobalTieredPricing\CPT\GlobalTieredPricingCPT; |
| 5 | +use TierPricingTable\Addons\GlobalTieredPricing\CPT\PricingTestLinks; | |
| 5 | 6 | |
| 6 | 7 | class GlobalTieredPricingAddon extends AbstractAddon { |
| 7 | 8 | |
| 8 | 9 | public function getName(): string { |
| @@ -15,8 +16,9 @@ | ||
| 15 | 16 | add_filter( 'tiered_pricing_table/services/pricing_service_enabled', '__return_true' ); |
| 16 | 17 | |
| 17 | 18 | new LookupService(); |
| 18 | 19 | new GlobalTieredPricingCPT(); |
| 20 | + new PricingTestLinks(); | |
| 19 | 21 | new GlobalTieredPricingCartManager(); |
| 20 | 22 | new PricingService(); |
| 21 | 23 | |
| 22 | 24 | GlobalPricingRulesRepository::getInstance(); |
| @@ -24,10 +26,33 @@ | ||
| 24 | 26 | add_action( 'tiered_pricing_table/admin/pricing_tab_end', array( |
| 25 | 27 | $this, |
| 26 | 28 | 'showMessageOnProductsTieredPricingTab', |
| 27 | 29 | ), 999 ); |
| 30 | + | |
| 31 | + // The set of rules in force changes with schedules and priorities, so cached prices must change with it: | |
| 32 | + // WooCommerce's variable price ranges and the plugin's own product data are keyed by this fingerprint. | |
| 33 | + add_filter( 'woocommerce_get_variation_prices_hash', function ( $hash ) { | |
| 34 | + if ( is_array( $hash ) ) { | |
| 35 | + $hash[] = 'tpt-rules:' . self::getActiveRulesFingerprint(); | |
| 36 | + } | |
| 37 | + | |
| 38 | + return $hash; | |
| 39 | + } ); | |
| 40 | + | |
| 41 | + add_filter( 'tiered_pricing_table/cache/product_cache_key_salt', function ( $salt ) { | |
| 42 | + return $salt . '|rules:' . self::getActiveRulesFingerprint(); | |
| 43 | + } ); | |
| 28 | 44 | } |
| 29 | 45 | |
| 46 | + /** | |
| 47 | + * The rules in force right now with their priorities, as one string. | |
| 48 | + */ | |
| 49 | + public static function getActiveRulesFingerprint(): string { | |
| 50 | + return implode( ',', array_map( function ( GlobalPricingRule $rule ) { | |
| 51 | + return $rule->getId() . ':' . $rule->getPriority(); | |
| 52 | + }, GlobalTieredPricingCPT::getGlobalRules() ) ); | |
| 53 | + } | |
| 54 | + | |
| 30 | 55 | public function showMessageOnProductsTieredPricingTab() { |
| 31 | 56 | $globalRules = GlobalTieredPricingCPT::getGlobalRules( false ); |
| 32 | 57 | |
| 33 | 58 | if ( empty( $globalRules ) ) { |
| @@ -35,10 +60,13 @@ | ||
| 35 | 60 | } |
| 36 | 61 | } |
| 37 | 62 | |
| 38 | 63 | public function getDescription(): string { |
| 39 | - return __( 'Create pricing rules for user roles or specific users, and apply them to selected products or product categories.', | |
| 40 | - 'tier-pricing-table' ); | |
| 64 | + return __( 'Create reusable pricing rules and apply them globally.', 'tier-pricing-table' ); | |
| 65 | + } | |
| 66 | + | |
| 67 | + public function getIcon(): string { | |
| 68 | + return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/></svg>'; | |
| 41 | 69 | } |
| 42 | 70 | |
| 43 | 71 | public function getSlug(): string { |
| 44 | 72 | return 'global-tier-pricing'; |