PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / trunk
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel vtrunk
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / src / App / Service / Pro / VariationOptions / VariationOptions.php
wp-all-export / src / App / Service / Pro / VariationOptions Last commit date
VariationOptions.php 2 years ago
VariationOptions.php
85 lines
1 <?php
2
3 namespace Wpae\App\Service\Pro\VariationOptions;
4
5
6 use Wpae\App\Service\VariationOptions\VariationOptionsInterface;
7 use Wpae\App\Service\VariationOptions\VariationOptions as BasicVariationOptions;
8
9 class VariationOptions extends BasicVariationOptions implements VariationOptionsInterface
10 {
11 public function preprocessPost(\WP_Post $entry)
12 {
13 $productVariationMode = \XmlExportEngine::getProductVariationMode();
14
15 if (!$this->shouldTitleBeProcessed($productVariationMode)) {
16 return $entry;
17 }
18
19 if($entry->post_type != 'product_variation') {
20 return $entry;
21 }
22
23 if ($entry->post_type == 'product_variation') {
24 $entryId = $entry->ID;
25 $entryTitle = $entry->post_title;
26 $entryStatus = $entry->post_status;
27 $entryOrder = $entry->menu_order;
28 $parentId = $entry->post_parent;
29 $parent = get_post($parentId);
30 if ( ! empty($parent) ){
31 /** @noinspection PhpDynamicFieldDeclarationInspection */
32 $parent->originalPost = clone $entry;
33 $entry = $parent;
34 $entry->ID = $entryId;
35 $entry->post_status = $entryStatus;
36 $entry->menu_order = $entryOrder;
37 $entry->post_parent = $parentId;
38 if (\XmlExportEngine::getProductVariationTitleMode() == \XmlExportEngine::VARIATION_USE_DEFAULT_TITLE) {
39 $entry->post_title = $entryTitle;
40 }
41 $entry->post_type = 'product_variation';
42 }
43 }
44
45 return $entry;
46 }
47
48 public function getQueryWhere($wpdb, $where, $join, $closeBracket = false)
49 {
50 if (\XmlExportEngine::getProductVariationMode() == \XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_PARENT) {
51 return " AND ($wpdb->posts.post_type = 'product') ";
52 } else if (\XmlExportEngine::getProductVariationMode() == \XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_VARIATION) {
53
54 return " AND $wpdb->posts.ID NOT IN (
55 SELECT DISTINCT $wpdb->posts.post_parent
56 FROM $wpdb->posts
57 WHERE $wpdb->posts.post_type = 'product_variation'
58 ) AND $wpdb->posts.ID NOT IN (SELECT o.ID FROM $wpdb->posts o
59 LEFT OUTER JOIN $wpdb->posts r
60 ON o.post_parent = r.ID
61 WHERE r.post_status = 'trash' AND o.post_type = 'product_variation')
62 OR ($wpdb->posts.post_type = 'product_variation' AND $wpdb->posts.post_status <> 'trash'
63
64 AND $wpdb->posts.post_parent IN (
65 SELECT DISTINCT $wpdb->posts.ID
66 FROM $wpdb->posts $join
67 WHERE $where
68 )
69 ".$this->getVariationsWhere($where, $join)."
70 )";
71 } else {
72 return $this->defaultQuery($wpdb, $where, $join, $closeBracket);
73 }
74 }
75
76 /**
77 * @param $productVariationMode
78 * @return bool
79 */
80 private function shouldTitleBeProcessed($productVariationMode)
81 {
82 return $productVariationMode != \XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_PARENT ||
83 $productVariationMode == \XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_VARIATION;
84 }
85 }