VariationOptions.php
9 years ago
VariationOptionsFactory.php
9 years ago
VariationOptionsInterface.php
9 years ago
VariationOptions.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\VariationOptions; |
| 4 | |
| 5 | |
| 6 | class VariationOptions implements VariationOptionsInterface |
| 7 | { |
| 8 | public function getQueryWhere($wpdb, $where, $join, $closeBracket = false) |
| 9 | { |
| 10 | return $this->defaultQuery($wpdb, $where, $join, $closeBracket); |
| 11 | } |
| 12 | |
| 13 | public function preProcessPost(\WP_Post $entry) |
| 14 | { |
| 15 | return $entry; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * @param $wpdb |
| 20 | * @param $where |
| 21 | * @param $join |
| 22 | * @param $closeBracket |
| 23 | * @return string |
| 24 | * |
| 25 | * TODO: Remove $closeBracket flag |
| 26 | */ |
| 27 | protected function defaultQuery($wpdb, $where, $join, $closeBracket) |
| 28 | { |
| 29 | if($closeBracket) { |
| 30 | return " AND $wpdb->posts.post_type = 'product' ) OR ($wpdb->posts.post_type = 'product_variation' AND $wpdb->posts.post_parent IN ( |
| 31 | SELECT DISTINCT $wpdb->posts.ID |
| 32 | FROM $wpdb->posts $join |
| 33 | WHERE $where |
| 34 | )) GROUP BY $wpdb->posts.ID"; |
| 35 | } else { |
| 36 | return " AND $wpdb->posts.post_type = 'product' OR ($wpdb->posts.post_type = 'product_variation' AND $wpdb->posts.post_parent IN ( |
| 37 | SELECT DISTINCT $wpdb->posts.ID |
| 38 | FROM $wpdb->posts $join |
| 39 | WHERE $where |
| 40 | )) GROUP BY $wpdb->posts.ID"; |
| 41 | } |
| 42 | |
| 43 | } |
| 44 | } |