← All changes
|
src/Addons/GlobalTieredPricing/CPT/Columns/Settings.php
+35
-46
7.1.4
→
8.1.0
View file →
| @@ -1,60 +1,49 @@ | ||
| 1 | 1 | <?php namespace TierPricingTable\Addons\GlobalTieredPricing\CPT\Columns; |
| 2 | 2 | |
| 3 | 3 | use TierPricingTable\Addons\GlobalTieredPricing\GlobalPricingRule; |
| 4 | -use TierPricingTable\CalculationLogic; | |
| 5 | 4 | |
| 5 | +/** | |
| 6 | + * Settings that differ from the defaults: how the rule meets product-level pricing, and whatever | |
| 7 | + * add-ons append (tax settings, for instance) through the after_tab_render action. | |
| 8 | + */ | |
| 6 | 9 | class Settings { |
| 7 | - | |
| 10 | + | |
| 8 | 11 | public function getName(): string { |
| 9 | - return __( 'Priority Settings', 'tier-pricing-table' ); | |
| 12 | + return __( 'Settings', 'tier-pricing-table' ); | |
| 10 | 13 | } |
| 11 | - | |
| 14 | + | |
| 12 | 15 | public function render( GlobalPricingRule $rule ) { |
| 13 | - | |
| 14 | - $prioritySlug = $rule->getSettings()->getPriorityType(); | |
| 15 | - | |
| 16 | - if ( $prioritySlug === 'default' ) { | |
| 17 | - $realPriority = CalculationLogic::globalRulesOverrideProductLevelRules() ? 'override' : 'prefer-product'; | |
| 18 | - } else { | |
| 19 | - $realPriority = $prioritySlug; | |
| 20 | - } | |
| 21 | - | |
| 22 | - $priorities = array( | |
| 23 | - 'default' => __( 'Global', 'tier-pricing-table' ), | |
| 24 | - 'prefer-product' => __( 'Prefer Product', 'tier-pricing-table' ), | |
| 25 | - 'prefer-role-based-product' => __( 'Prefer Product', 'tier-pricing-table' ), | |
| 26 | - 'override' => __( 'Override', 'tier-pricing-table' ), | |
| 27 | - 'flexible' => __( 'Flexible', 'tier-pricing-table' ), | |
| 16 | + $settings = $rule->getSettings(); | |
| 17 | + $labels = array( | |
| 18 | + 'prefer-product' => __( 'prefer product', 'tier-pricing-table' ), | |
| 19 | + 'prefer-role-based-product' => __( 'prefer product role prices', 'tier-pricing-table' ), | |
| 20 | + 'override' => __( 'override product', 'tier-pricing-table' ), | |
| 28 | 21 | ); |
| 29 | - | |
| 30 | - | |
| 31 | - if ( ! array_key_exists( $prioritySlug, $priorities ) ) { | |
| 32 | - return; | |
| 22 | + | |
| 23 | + switch ( $settings->getPriorityType() ) { | |
| 24 | + case 'prefer-product': | |
| 25 | + $this->renderTag( __( 'Prefers product pricing', 'tier-pricing-table' ) ); | |
| 26 | + break; | |
| 27 | + case 'override': | |
| 28 | + $this->renderTag( __( 'Overrides product pricing', 'tier-pricing-table' ) ); | |
| 29 | + break; | |
| 30 | + case 'flexible': | |
| 31 | + $this->renderTag( __( 'Custom priorities', 'tier-pricing-table' ), sprintf( | |
| 32 | + /* translators: 1, 2, 3: the three priority choices */ | |
| 33 | + __( 'Base prices: %1$s. Tiers: %2$s. Quantity limits: %3$s.', 'tier-pricing-table' ), | |
| 34 | + $labels[ $settings->getRegularPricingPriority() ] ?? $settings->getRegularPricingPriority(), | |
| 35 | + $labels[ $settings->getTieredPricingPriority() ] ?? $settings->getTieredPricingPriority(), | |
| 36 | + $labels[ $settings->getQuantityLimitsPriority() ] ?? $settings->getQuantityLimitsPriority() | |
| 37 | + ) ); | |
| 38 | + break; | |
| 39 | + default: | |
| 40 | + echo '<span class="tpt-rules-list__muted">' . esc_html__( 'Default', 'tier-pricing-table' ) . '</span>'; | |
| 33 | 41 | } |
| 34 | - | |
| 42 | + } | |
| 43 | + | |
| 44 | + public static function renderTag( string $text, string $title = '' ) { | |
| 35 | 45 | ?> |
| 36 | - <div style="margin-bottom: 12px;"> | |
| 37 | - <div style="display: flex; flex-wrap: wrap; gap: 4px;"> | |
| 38 | - <span style="display: inline-block; background: #e0f0fa; color: #0070bc; border: 1px solid #bae0ff; padding: 4px 10px; border-radius: 4px; font-size: 13px; font-weight: 500; line-height: 1.4;"> | |
| 39 | - <?php echo esc_html( $priorities[ $realPriority ] ); ?> | |
| 40 | - </span> | |
| 41 | - </div> | |
| 42 | - | |
| 43 | - <?php if ( $prioritySlug === 'flexible' ) : ?> | |
| 44 | - <div style="margin-top: 8px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start;"> | |
| 45 | - <span style="display: inline-block; padding: 2px 8px; background: #f0f0f1; border-radius: 3px; font-size: 12px; color: #3c434a; border: 1px solid #dcdcdc; line-height: 1.4;"> | |
| 46 | - <?php esc_html_e( 'Regular prices:', 'tier-pricing-table' ); ?> <b><?php echo esc_html( $priorities[ $rule->getSettings()->getRegularPricingPriority() ] ); ?></b> | |
| 47 | - </span> | |
| 48 | - <span style="display: inline-block; padding: 2px 8px; background: #f0f0f1; border-radius: 3px; font-size: 12px; color: #3c434a; border: 1px solid #dcdcdc; line-height: 1.4;"> | |
| 49 | - <?php esc_html_e( 'Tiered pricing:', 'tier-pricing-table' ); ?> <b><?php echo esc_html( $priorities[ $rule->getSettings()->getTieredPricingPriority() ] ); ?></b> | |
| 50 | - </span> | |
| 51 | - <span style="display: inline-block; padding: 2px 8px; background: #f0f0f1; border-radius: 3px; font-size: 12px; color: #3c434a; border: 1px solid #dcdcdc; line-height: 1.4;"> | |
| 52 | - <?php esc_html_e( 'Quantity limits:', 'tier-pricing-table' ); ?> <b><?php echo esc_html( $priorities[ $rule->getSettings()->getQuantityLimitsPriority() ] ); ?></b> | |
| 53 | - </span> | |
| 54 | - </div> | |
| 55 | - <?php endif; ?> | |
| 56 | - </div> | |
| 57 | - | |
| 46 | + <span class="tpt-rules-list__tag" <?php echo $title ? 'title="' . esc_attr( $title ) . '"' : ''; ?>><?php echo esc_html( $text ); ?></span> | |
| 58 | 47 | <?php |
| 59 | 48 | } |
| 60 | 49 | } |