← All changes
|
src/Addons/RoleBasedPricing/Import/RoleBasedPricingImport.php
+34
-15
6.4.0
→
8.1.0
View file →
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php namespace TierPricingTable\Addons\RoleBasedPricing\Import; |
| 2 | 2 | |
| 3 | 3 | use TierPricingTable\Addons\RoleBasedPricing\RoleBasedPricingRule; |
| 4 | -use TierPricingTable\Services\ImportExport\WoocommerceImportService; | |
| 4 | +use TierPricingTable\Addons\ImportExport\WoocommerceImportService; | |
| 5 | 5 | use WC_Product; |
| 6 | 6 | |
| 7 | 7 | class RoleBasedPricingImport { |
| 8 | 8 | |
| @@ -14,10 +14,16 @@ | ||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function processImport( WC_Product $product, array $data ): WC_Product { |
| 17 | 17 | |
| 18 | + $disabled_roles = apply_filters( 'tiered_pricing_table/role_based_rules/import_export_disabled_roles', array( 'editor', 'author', 'contributor', 'shop_manager' ) ); | |
| 19 | + | |
| 18 | 20 | foreach ( wp_roles()->roles as $WPRole => $role_data ) { |
| 19 | 21 | |
| 22 | + if ( in_array( $WPRole, $disabled_roles, true ) ) { | |
| 23 | + continue; | |
| 24 | + } | |
| 25 | + | |
| 20 | 26 | $roleBasedRule = new RoleBasedPricingRule( $product->get_id(), $WPRole ); |
| 21 | 27 | $needUpdate = false; |
| 22 | 28 | |
| 23 | 29 | if ( isset( $data[ $WPRole . '_tiered_price_pricing_type' ] ) ) { |
| @@ -98,10 +104,15 @@ | ||
| 98 | 104 | |
| 99 | 105 | public function addColumnsToImporter( $columns ): array { |
| 100 | 106 | |
| 101 | 107 | global $wp_roles; |
| 108 | + $disabled_roles = apply_filters( 'tiered_pricing_table/role_based_rules/import_export_disabled_roles', array( 'editor', 'author', 'contributor', 'shop_manager' ) ); | |
| 102 | 109 | |
| 103 | 110 | foreach ( wp_roles()->roles as $WPRole => $role_data ) { |
| 111 | + if ( in_array( $WPRole, $disabled_roles, true ) ) { | |
| 112 | + continue; | |
| 113 | + } | |
| 114 | + | |
| 104 | 115 | $roleName = isset( $wp_roles->role_names[ $WPRole ] ) ? translate_user_role( $wp_roles->role_names[ $WPRole ] ) : $WPRole; |
| 105 | 116 | |
| 106 | 117 | $columns[ 'tpt_' . $WPRole ] = array( |
| 107 | 118 | 'name' => __( 'Tiered Pricing', 'tier-pricing-table' ) . ': ' . $roleName, |
| @@ -131,27 +142,35 @@ | ||
| 131 | 142 | |
| 132 | 143 | public function addColumnsToMapper( array $columns ): array { |
| 133 | 144 | |
| 134 | 145 | global $wp_roles; |
| 146 | + $disabled_roles = apply_filters( 'tiered_pricing_table/role_based_rules/import_export_disabled_roles', array( 'editor', 'author', 'contributor', 'shop_manager' ) ); | |
| 135 | 147 | |
| 136 | 148 | foreach ( wp_roles()->roles as $WPRole => $role_data ) { |
| 149 | + if ( in_array( $WPRole, $disabled_roles, true ) ) { | |
| 150 | + continue; | |
| 151 | + } | |
| 152 | + | |
| 137 | 153 | $roleName = isset( $wp_roles->role_names[ $WPRole ] ) ? translate_user_role( $wp_roles->role_names[ $WPRole ] ) : $WPRole; |
| 138 | 154 | |
| 139 | - $columns[ 'Tiered Pricing — [' . $roleName . '] Regular pricing type' ] = $WPRole . '_tiered_price_pricing_type'; | |
| 155 | + $labels = array( | |
| 156 | + 'Regular pricing type' => $WPRole . '_tiered_price_pricing_type', | |
| 157 | + 'Regular price' => $WPRole . '_tiered_price_regular_price', | |
| 158 | + 'Sale price' => $WPRole . '_tiered_price_sale_price', | |
| 159 | + 'Percentage discount' => $WPRole . '_tiered_price_discount', | |
| 160 | + 'Fixed pricing rules' => $WPRole . '_tiered_price_fixed', | |
| 161 | + 'Percentage pricing rules' => $WPRole . '_tiered_price_percentage', | |
| 162 | + 'Tiered pricing type' => $WPRole . '_tiered_price_type', | |
| 163 | + 'Minimum order quantity' => $WPRole . '_tiered_price_minimum', | |
| 164 | + ); | |
| 140 | 165 | |
| 141 | - $columns[ 'Tiered Pricing — [' . $roleName . '] Regular price' ] = $WPRole . '_tiered_price_regular_price'; | |
| 142 | - | |
| 143 | - $columns[ 'Tiered Pricing — [' . $roleName . '] Sale price' ] = $WPRole . '_tiered_price_sale_price'; | |
| 144 | - | |
| 145 | - $columns[ 'Tiered Pricing — [' . $roleName . '] Percentage discount' ] = $WPRole . '_tiered_price_discount'; | |
| 146 | - | |
| 147 | - $columns[ 'Tiered Pricing — [' . $roleName . '] Fixed pricing rules' ] = $WPRole . '_tiered_price_fixed'; | |
| 148 | - | |
| 149 | - $columns[ 'Tiered Pricing — [' . $roleName . '] Percentage pricing rules' ] = $WPRole . '_tiered_price_percentage'; | |
| 150 | - | |
| 151 | - $columns[ 'Tiered Pricing — [' . $roleName . '] Tiered pricing type' ] = $WPRole . '_tiered_price_type'; | |
| 152 | - | |
| 153 | - $columns[ 'Tiered Pricing — [' . $roleName . '] Minimum order quantity' ] = $WPRole . '_tiered_price_minimum'; | |
| 166 | + foreach ( $labels as $label => $column ) { | |
| 167 | + // The exporter writes "Tiered Pricing — [Role] Label". Files exported before 8.0.3 / 10.0.3 carried | |
| 168 | + // two (three for the pricing type) spaces before the bracket; they must keep mapping automatically. | |
| 169 | + foreach ( array( ' ', ' ', ' ' ) as $spacing ) { | |
| 170 | + $columns[ 'Tiered Pricing —' . $spacing . '[' . $roleName . '] ' . $label ] = $column; | |
| 171 | + } | |
| 172 | + } | |
| 154 | 173 | } |
| 155 | 174 | |
| 156 | 175 | return $columns; |
| 157 | 176 | } |