Load subscription products for segments form

[MAILPOET-3471]
This commit is contained in:
Rostislav Wolny
2021-04-07 17:43:39 +02:00
committed by Veljko V
parent 6a7cf8677f
commit 0728bc2e12
3 changed files with 14 additions and 0 deletions

View File

@ -81,6 +81,7 @@ class Segments {
$data['product_categories'] = $this->wpPostListLoader->getWooCommerceCategories();
$data['products'] = $this->wpPostListLoader->getProducts();
$data['subscription_products'] = $this->wpPostListLoader->getSubscriptionProducts();
$data['is_woocommerce_active'] = $this->woocommerceHelper->isWooCommerceActive();
$this->pageRenderer->displayPage('segments.html', $data);

View File

@ -21,6 +21,18 @@ class AutocompletePostListLoader {
return $this->formatPosts($products);
}
public function getSubscriptionProducts() {
$products = $this->wp->getResultsFromWpDb(
"SELECT `ID`, `post_title` FROM {$this->wp->getWPTableName('posts')} AS p
INNER JOIN {$this->wp->getWPTableName('term_relationships')} AS trel ON trel.object_id = p.id
INNER JOIN {$this->wp->getWPTableName('term_taxonomy')} AS ttax ON ttax.term_taxonomy_id = trel.term_taxonomy_id
INNER JOIN {$this->wp->getWPTableName('terms')} AS t ON ttax.term_id = t.term_id AND t.slug IN ('subscription', 'variable-subscription')
WHERE `p`.`post_type` = %s ORDER BY `post_title` ASC;",
'product'
);
return $this->formatPosts($products);
}
public function getWooCommerceCategories() {
return $this->formatTerms($this->wp->getCategories(['taxonomy' => 'product_cat', 'orderby' => 'name']));
}

View File

@ -26,6 +26,7 @@
var mailpoet_newsletters_list = <%= json_encode(newsletters_list) %>;
var mailpoet_product_categories = <%= json_encode(product_categories) %>;
var mailpoet_products = <%= json_encode(products) %>;
var mailpoet_subscription_products = <%= json_encode(subscription_products) %>;
var is_woocommerce_active = <%= json_encode(is_woocommerce_active) %>;
</script>