← All changes
|
src/Addons/ImportExport/WoocommerceImportService.php
+11
-8
7.1.5
→
8.1.0
View file →
| @@ -82,22 +82,25 @@ | ||
| 82 | 82 | return $product; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | - * Decode export string format to array of pricing rules | |
| 86 | + * Decode the export string format ("10:90,20:80") into an array of pricing rules. | |
| 87 | + * | |
| 88 | + * Each rule is "quantity:price" (or "quantity=price", which spreadsheets leave alone, while they | |
| 89 | + * turn "20:100" into a time). Anything else, for example a cell a spreadsheet already turned | |
| 90 | + * into "21:40:00", is ignored instead of being imported as a wrong tier. | |
| 87 | 91 | */ |
| 88 | 92 | public static function decodeExport( string $data ): array { |
| 89 | 93 | $rules = explode( TierPricingTablePlugin::getRulesSeparator(), $data ); |
| 90 | 94 | |
| 95 | + // ":" and "=" always work; a store may export with another separator through the filter. | |
| 96 | + $separators = preg_quote( ':=' . TierPricingTablePlugin::getRuleSeparator(), '/' ); | |
| 97 | + | |
| 91 | 98 | $data = array(); |
| 92 | 99 | |
| 93 | - if ( $rules ) { | |
| 94 | - foreach ( $rules as $rule ) { | |
| 95 | - $rule = explode( ':', $rule ); | |
| 96 | - | |
| 97 | - if ( isset( $rule[0] ) && isset( $rule[1] ) ) { | |
| 98 | - $data[ intval( $rule[0] ) ] = $rule[1]; | |
| 99 | - } | |
| 100 | + foreach ( $rules as $rule ) { | |
| 101 | + if ( preg_match( '/^\s*(\d+)\s*[' . $separators . ']\s*(\d+(?:\.\d+)?)\s*$/', $rule, $matches ) ) { | |
| 102 | + $data[ intval( $matches[1] ) ] = $matches[2]; | |
| 100 | 103 | } |
| 101 | 104 | } |
| 102 | 105 | |
| 103 | 106 | $data = array_filter( $data ); |