Skip to content

Commit 6e88c8d

Browse files
committed
Filter newsletter subscribers by selected shop context in module configuration
1 parent cacf793 commit 6e88c8d

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

ps_emailsubscription.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,19 @@ public function newsletterRegistration($hookName = null)
505505

506506
public function getSubscribers()
507507
{
508+
$shopIds = [];
509+
if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE')) {
510+
$context = Context::getContext();
511+
$shopContext = Shop::getContext();
512+
513+
if ($shopContext === Shop::CONTEXT_SHOP) {
514+
$shopIds = [(int) $context->shop->id];
515+
} elseif ($shopContext === Shop::CONTEXT_GROUP) {
516+
$shops = ShopGroup::getShopsFromGroup((int) $context->shop->id_shop_group);
517+
$shopIds = array_column($shops, 'id_shop');
518+
}
519+
}
520+
508521
$dbquery = new DbQuery();
509522
$dbquery->select('c.`id_customer` AS `id`, s.`name` AS `shop_name`, gl.`name` AS `gender`, c.`lastname`, c.`firstname`, c.`email`, c.`newsletter` AS `subscribed`, c.`newsletter_date_add`, l.`iso_code`');
510523
$dbquery->from('customer', 'c');
@@ -517,6 +530,10 @@ public function getSubscribers()
517530
$dbquery->where('c.`email` LIKE \'%' . pSQL($this->_searched_email) . '%\' ');
518531
}
519532

533+
if (!empty($shopIds)) {
534+
$dbquery->where('c.`id_shop` IN (' . implode(',', $shopIds) . ')');
535+
}
536+
520537
$customers = Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS($dbquery->build());
521538

522539
$dbquery = new DbQuery();
@@ -529,6 +546,10 @@ public function getSubscribers()
529546
$dbquery->where('e.`email` LIKE \'%' . pSQL($this->_searched_email) . '%\' ');
530547
}
531548

549+
if (!empty($shopIds)) {
550+
$dbquery->where('e.`id_shop` IN (' . implode(',', $shopIds) . ')');
551+
}
552+
532553
$non_customers = Db::getInstance()->executeS($dbquery->build());
533554

534555
$subscribers = array_merge($customers, $non_customers);

0 commit comments

Comments
 (0)