| @@ -1,121 +1,106 @@ | ||
| 1 | -<?php namespace TierPricingTable\Admin\Export; | |
| 1 | +<?php | |
| 2 | 2 | |
| 3 | -use TierPricingTable\PriceManager; | |
| 4 | -use WC_Product; | |
| 3 | +namespace TierPricingTable\Admin\Export; | |
| 5 | 4 | |
| 5 | +use TierPricingTable\PriceManager ; | |
| 6 | +use WC_Product ; | |
| 6 | 7 | /** |
| 7 | 8 | * Class WooCommerce Export |
| 8 | 9 | */ |
| 9 | -class Woocommerce { | |
| 10 | +class Woocommerce | |
| 11 | +{ | |
| 12 | + /** | |
| 13 | + * Export constructor. | |
| 14 | + */ | |
| 15 | + public function __construct() | |
| 16 | + { | |
| 17 | + add_filter( | |
| 18 | + 'woocommerce_product_export_column_names', | |
| 19 | + [ $this, 'addExportColumn' ], | |
| 20 | + 1, | |
| 21 | + 10 | |
| 22 | + ); | |
| 23 | + add_filter( | |
| 24 | + 'woocommerce_product_export_product_default_columns', | |
| 25 | + [ $this, 'addExportColumn' ], | |
| 26 | + 1, | |
| 27 | + 10 | |
| 28 | + ); | |
| 29 | + add_filter( | |
| 30 | + 'woocommerce_product_export_product_column_tiered_price_fixed', | |
| 31 | + [ $this, 'addExportFixedData' ], | |
| 32 | + 10, | |
| 33 | + 2 | |
| 34 | + ); | |
| 35 | + add_filter( | |
| 36 | + 'woocommerce_product_export_product_column_tiered_price_percentage', | |
| 37 | + [ $this, 'addExportPercentageData' ], | |
| 38 | + 10, | |
| 39 | + 2 | |
| 40 | + ); | |
| 41 | + } | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Register the 'Fixed tier price' column in the exporter. | |
| 45 | + * | |
| 46 | + * @param array $columns | |
| 47 | + * | |
| 48 | + * @return array $options | |
| 49 | + */ | |
| 50 | + public function addExportColumn( $columns ) | |
| 51 | + { | |
| 52 | + $columns['tiered_price_fixed'] = __( 'Fixed Tiered Prices', 'tier-pricing-table' ); | |
| 53 | + return $columns; | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Provide the data to be exported for one item in the column. | |
| 58 | + * | |
| 59 | + * @param WC_Product $product | |
| 60 | + * @param string $type | |
| 61 | + * | |
| 62 | + * @return mixed $value | |
| 63 | + */ | |
| 64 | + public function addExportData( $product, $type = 'fixed' ) | |
| 65 | + { | |
| 66 | + | |
| 67 | + if ( $type == 'percentage' ) { | |
| 68 | + $tiered_pricing = PriceManager::getPercentagePriceRules( $product->get_id() ); | |
| 69 | + } else { | |
| 70 | + $tiered_pricing = PriceManager::getFixedPriceRules( $product->get_id() ); | |
| 71 | + } | |
| 72 | + | |
| 73 | + $str = ''; | |
| 74 | + foreach ( $tiered_pricing as $quantity => $price ) { | |
| 75 | + $str .= $quantity . ":" . $price . ","; | |
| 76 | + } | |
| 77 | + return ( mb_strlen( $str ) > 0 ? trim( $str, ',' ) : null ); | |
| 78 | + } | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * Export fixed pricing rules | |
| 82 | + * | |
| 83 | + * @param mixed $value | |
| 84 | + * @param WC_product $product | |
| 85 | + * | |
| 86 | + * @return mixed | |
| 87 | + */ | |
| 88 | + public function addExportFixedData( $value, $product ) | |
| 89 | + { | |
| 90 | + return $this->addExportData( $product, 'fixed' ); | |
| 91 | + } | |
| 92 | + | |
| 93 | + /** | |
| 94 | + * Export percentage pricing rules | |
| 95 | + * | |
| 96 | + * @param mixed $value | |
| 97 | + * @param WC_product $product | |
| 98 | + * | |
| 99 | + * @return mixed | |
| 100 | + */ | |
| 101 | + public function addExportPercentageData( $value, $product ) | |
| 102 | + { | |
| 103 | + return $this->addExportData( $product, 'percentage' ); | |
| 104 | + } | |
| 10 | 105 | |
| 11 | - /** | |
| 12 | - * Export constructor. | |
| 13 | - */ | |
| 14 | - public function __construct() { | |
| 15 | - add_filter( 'woocommerce_product_export_column_names', [ $this, 'addExportColumn' ], 1, 10 ); | |
| 16 | - add_filter( 'woocommerce_product_export_product_default_columns', [ $this, 'addExportColumn' ], 1, 10 ); | |
| 17 | - add_filter( 'woocommerce_product_export_product_column_tiered_price_fixed', [ $this, 'addExportFixedData' ], 10, | |
| 18 | - 2 ); | |
| 19 | - add_filter( 'woocommerce_product_export_product_column_tiered_price_percentage', | |
| 20 | - [ $this, 'addExportPercentageData' ], 10, 2 ); | |
| 21 | - | |
| 22 | - add_filter( 'woocommerce_product_export_product_column_tiered_price_type', | |
| 23 | - array( $this, 'addExportPricingTypeData' ), 10, 2 ); | |
| 24 | - | |
| 25 | - add_filter( 'woocommerce_product_export_product_column_tiered_price_minimum', | |
| 26 | - array( $this, 'addExportPricingMinimumData' ), 10, 2 ); | |
| 27 | - } | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * Register the 'Fixed tier price' column in the exporter. | |
| 31 | - * | |
| 32 | - * @param array $columns | |
| 33 | - * | |
| 34 | - * @return array $options | |
| 35 | - */ | |
| 36 | - public function addExportColumn( $columns ) { | |
| 37 | - $columns['tiered_price_fixed'] = __( 'Fixed Tiered Prices', 'tier-pricing-table' ); | |
| 38 | - | |
| 39 | - if ( tpt_fs()->is__premium_only() ) { | |
| 40 | - $columns['tiered_price_type'] = __( 'Tiered pricing type', 'tier-pricing-table' ); | |
| 41 | - $columns['tiered_price_minimum'] = __( 'Tiered pricing minimum product quantity', 'tier-pricing-table' ); | |
| 42 | - $columns['tiered_price_percentage'] = __( 'Percentage Tiered Prices', 'tier-pricing-table' ); | |
| 43 | - } | |
| 44 | - | |
| 45 | - return $columns; | |
| 46 | - } | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * Provide the data to be exported for one item in the column. | |
| 50 | - * | |
| 51 | - * @param WC_Product $product | |
| 52 | - * @param string $type | |
| 53 | - * | |
| 54 | - * @return mixed $value | |
| 55 | - */ | |
| 56 | - public function addExportData( $product, $type = 'fixed' ) { | |
| 57 | - | |
| 58 | - if ( $type == 'percentage' ) { | |
| 59 | - $tiered_pricing = PriceManager::getPercentagePriceRules( $product->get_id() ); | |
| 60 | - } else { | |
| 61 | - $tiered_pricing = PriceManager::getFixedPriceRules( $product->get_id() ); | |
| 62 | - } | |
| 63 | - | |
| 64 | - $str = ''; | |
| 65 | - | |
| 66 | - foreach ( $tiered_pricing as $quantity => $price ) { | |
| 67 | - $str .= $quantity . ":" . $price . ","; | |
| 68 | - } | |
| 69 | - | |
| 70 | - return mb_strlen( $str ) > 0 ? trim( $str, ',' ) : null; | |
| 71 | - } | |
| 72 | - | |
| 73 | - /** | |
| 74 | - * Export fixed pricing rules | |
| 75 | - * | |
| 76 | - * @param mixed $value | |
| 77 | - * @param WC_product $product | |
| 78 | - * | |
| 79 | - * @return mixed | |
| 80 | - */ | |
| 81 | - public function addExportFixedData( $value, $product ) { | |
| 82 | - return $this->addExportData( $product, 'fixed' ); | |
| 83 | - } | |
| 84 | - | |
| 85 | - /** | |
| 86 | - * Export percentage pricing rules | |
| 87 | - * | |
| 88 | - * @param mixed $value | |
| 89 | - * @param WC_product $product | |
| 90 | - * | |
| 91 | - * @return mixed | |
| 92 | - */ | |
| 93 | - public function addExportPercentageData( $value, $product ) { | |
| 94 | - return $this->addExportData( $product, 'percentage' ); | |
| 95 | - } | |
| 96 | - | |
| 97 | - /** | |
| 98 | - * Export tiered pricing type | |
| 99 | - * | |
| 100 | - * @param mixed $value | |
| 101 | - * @param WC_product $product | |
| 102 | - * | |
| 103 | - * @return mixed | |
| 104 | - */ | |
| 105 | - public function addExportPricingTypeData( $value, $product ) { | |
| 106 | - $type = PriceManager::getPricingType( $product->get_id(), false, 'edit' ); | |
| 107 | - return $type ? $type : ''; | |
| 108 | - } | |
| 109 | - | |
| 110 | - /** | |
| 111 | - * Export tiered pricing minimum product quantity | |
| 112 | - * | |
| 113 | - * @param mixed $value | |
| 114 | - * @param WC_product $product | |
| 115 | - * | |
| 116 | - * @return mixed | |
| 117 | - */ | |
| 118 | - public function addExportPricingMinimumData( $value, $product ) { | |
| 119 | - return PriceManager::getProductQtyMin( $product->get_id(), 'edit' ); | |
| 120 | - } | |
| 121 | 106 | } |