| @@ -3,9 +3,8 @@ | ||
| 3 | 3 | namespace TierPricingTable\Addons\GlobalTieredPricing; |
| 4 | 4 | |
| 5 | 5 | use TierPricingTable\PricingRule; |
| 6 | 6 | use TierPricingTable\Addons\TieredPricingCart\CartOptionsSubsection; |
| 7 | -use TierPricingTable\PriceManager; | |
| 8 | 7 | class PricingService { |
| 9 | 8 | public function __construct() { |
| 10 | 9 | /** |
| 11 | 10 | * Main function to filter the tiered pricing rules |
| @@ -65,9 +64,8 @@ | ||
| 65 | 64 | } |
| 66 | 65 | |
| 67 | 66 | public function addFlexibleGlobalPricing( PricingRule $pricingRule, GlobalPricingRule $globalPricingRule ) : PricingRule { |
| 68 | 67 | $updateRegularPricing = false; |
| 69 | - $updateQuantityLimits = false; | |
| 70 | 68 | $updateTieredPricing = false; |
| 71 | 69 | /** |
| 72 | 70 | * Regular prices |
| 73 | 71 | */ |
| @@ -80,20 +78,25 @@ | ||
| 80 | 78 | } |
| 81 | 79 | /** |
| 82 | 80 | * Quantity Limits |
| 83 | 81 | */ |
| 82 | + $updateMinimum = false; | |
| 83 | + $updateMixAndMatch = false; | |
| 84 | 84 | if ( $globalPricingRule->getSettings()->getQuantityLimitsPriority() === 'prefer-role-based-product' ) { |
| 85 | - // Update only if there are no quantity limits set in the product or role-based | |
| 86 | 85 | if ( $pricingRule->provider !== 'role-based' ) { |
| 87 | - $updateQuantityLimits = true; | |
| 86 | + $updateMinimum = true; | |
| 87 | + $updateMixAndMatch = true; | |
| 88 | 88 | } |
| 89 | 89 | } elseif ( $globalPricingRule->getSettings()->getQuantityLimitsPriority() === 'prefer-product' ) { |
| 90 | - // Update only if there are no quantity limits set in the product | |
| 91 | 90 | if ( empty( $pricingRule->getMinimum() ) ) { |
| 92 | - $updateQuantityLimits = true; | |
| 91 | + $updateMinimum = true; | |
| 93 | 92 | } |
| 93 | + if ( get_post_meta( $pricingRule->getProductId(), '_tiered_price_mix_and_match_minimum', true ) === '' ) { | |
| 94 | + $updateMixAndMatch = true; | |
| 95 | + } | |
| 94 | 96 | } else { |
| 95 | - $updateQuantityLimits = true; | |
| 97 | + $updateMinimum = true; | |
| 98 | + $updateMixAndMatch = true; | |
| 96 | 99 | } |
| 97 | 100 | /** |
| 98 | 101 | * Tiered Pricing |
| 99 | 102 | */ |
| @@ -109,9 +112,9 @@ | ||
| 109 | 112 | $updateTieredPricing = true; |
| 110 | 113 | } |
| 111 | 114 | if ( $updateRegularPricing ) { |
| 112 | 115 | } |
| 113 | - if ( $updateQuantityLimits ) { | |
| 116 | + if ( $updateMinimum || $updateMixAndMatch ) { | |
| 114 | 117 | } |
| 115 | 118 | if ( $updateTieredPricing ) { |
| 116 | 119 | $pricingRule->setRules( $globalPricingRule->getTieredPricingRules() ); |
| 117 | 120 | $pricingRule->setType( $globalPricingRule->getTieredPricingType() ); |