VariationOptions.php
4 years ago
VariationOptionsFactory.php
4 years ago
VariationOptionsInterface.php
4 years ago
VariationOptions.php
85 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 | $langQuery = ''; |
| 32 | |
| 33 | if($this->isLanguageFilterEnabled()) { |
| 34 | $langQuery .= " AND t.language_code = '".\XmlExportEngine::$exportOptions['wpml_lang']."' "; |
| 35 | } |
| 36 | |
| 37 | if($closeBracket) { |
| 38 | $sql = " AND $wpdb->posts.post_type = 'product' " . $langQuery . " AND $wpdb->posts.ID NOT IN (SELECT o.ID FROM $wpdb->posts o |
| 39 | LEFT OUTER JOIN $wpdb->posts r |
| 40 | ON o.post_parent = r.ID |
| 41 | WHERE r.post_status = 'trash' AND o.post_type = 'product_variation')) |
| 42 | OR ($wpdb->posts.post_type = 'product_variation' AND $wpdb->posts.post_status <> 'trash' |
| 43 | |
| 44 | AND $wpdb->posts.post_parent IN ( |
| 45 | SELECT DISTINCT $wpdb->posts.ID |
| 46 | FROM $wpdb->posts $join |
| 47 | WHERE $where |
| 48 | ) |
| 49 | ".$this->getVariationsWhere($where, $join)." |
| 50 | |
| 51 | )"; |
| 52 | } else { |
| 53 | $sql = " AND $wpdb->posts.post_type = 'product' " . $langQuery . " AND $wpdb->posts.ID NOT IN (SELECT o.ID FROM $wpdb->posts o |
| 54 | LEFT OUTER JOIN $wpdb->posts r |
| 55 | ON o.post_parent = r.ID |
| 56 | WHERE r.post_status = 'trash' AND o.post_type = 'product_variation') |
| 57 | OR ($wpdb->posts.post_type = 'product_variation' AND $wpdb->posts.post_status <> 'trash' |
| 58 | |
| 59 | |
| 60 | AND $wpdb->posts.post_parent IN ( |
| 61 | SELECT DISTINCT $wpdb->posts.ID |
| 62 | FROM $wpdb->posts $join |
| 63 | WHERE $where |
| 64 | ) |
| 65 | |
| 66 | ".$this->getVariationsWhere($where, $join)." |
| 67 | |
| 68 | |
| 69 | )"; |
| 70 | } |
| 71 | |
| 72 | return $sql; |
| 73 | |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @return bool |
| 78 | */ |
| 79 | private function isLanguageFilterEnabled() |
| 80 | { |
| 81 | return class_exists('SitePress') && |
| 82 | !empty(\XmlExportEngine::$exportOptions['wpml_lang']) && |
| 83 | (\XmlExportEngine::$exportOptions['wpml_lang'] !== 'all'); |
| 84 | } |
| 85 | } |