VariationOptions.php
2 years ago
VariationOptionsFactory.php
9 years ago
VariationOptionsInterface.php
9 years ago
VariationOptions.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\App\Service\VariationOptions; |
| 4 | |
| 5 | |
| 6 | use Wpae\Pro\Filtering\FilteringCPT; |
| 7 | |
| 8 | class VariationOptions implements VariationOptionsInterface |
| 9 | { |
| 10 | public function getQueryWhere($wpdb, $where, $join, $closeBracket = false) |
| 11 | { |
| 12 | return $this->defaultQuery($wpdb, $where, $join, $closeBracket); |
| 13 | } |
| 14 | |
| 15 | public function preProcessPost(\WP_Post $entry) |
| 16 | { |
| 17 | return $entry; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * @param $wpdb |
| 22 | * @param $where |
| 23 | * @param $join |
| 24 | * @param $closeBracket |
| 25 | * @return string |
| 26 | * |
| 27 | * TODO: Remove $closeBracket flag |
| 28 | */ |
| 29 | protected function defaultQuery($wpdb, $where, $join, $closeBracket) |
| 30 | { |
| 31 | |
| 32 | |
| 33 | if($closeBracket) { |
| 34 | $sql = " AND $wpdb->posts.post_type = 'product' AND $wpdb->posts.ID NOT IN (SELECT o.ID FROM $wpdb->posts o |
| 35 | LEFT OUTER JOIN $wpdb->posts r |
| 36 | ON o.post_parent = r.ID |
| 37 | WHERE r.post_status = 'trash' AND o.post_type = 'product_variation')) |
| 38 | OR ($wpdb->posts.post_type = 'product_variation' AND $wpdb->posts.post_status <> 'trash' |
| 39 | |
| 40 | AND $wpdb->posts.post_parent IN ( |
| 41 | SELECT DISTINCT $wpdb->posts.ID |
| 42 | FROM $wpdb->posts $join |
| 43 | WHERE $where |
| 44 | ) |
| 45 | ".$this->getVariationsWhere($where, $join)." |
| 46 | |
| 47 | )"; |
| 48 | } else { |
| 49 | $sql = " AND $wpdb->posts.post_type = 'product' AND $wpdb->posts.ID NOT IN (SELECT o.ID FROM $wpdb->posts o |
| 50 | LEFT OUTER JOIN $wpdb->posts r |
| 51 | ON o.post_parent = r.ID |
| 52 | WHERE r.post_status = 'trash' AND o.post_type = 'product_variation') |
| 53 | OR ($wpdb->posts.post_type = 'product_variation' AND $wpdb->posts.post_status <> 'trash' |
| 54 | |
| 55 | |
| 56 | AND $wpdb->posts.post_parent IN ( |
| 57 | SELECT DISTINCT $wpdb->posts.ID |
| 58 | FROM $wpdb->posts $join |
| 59 | WHERE $where |
| 60 | ) |
| 61 | |
| 62 | ".$this->getVariationsWhere($where, $join)." |
| 63 | |
| 64 | |
| 65 | )"; |
| 66 | } |
| 67 | |
| 68 | return $sql; |
| 69 | |
| 70 | } |
| 71 | } |