Skip to content

Commit c590769

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

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ps_emailsubscription.php

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

506506
public function getSubscribers()
507507
{
508+
$shopIds = [];
509+
if (Shop::isFeatureActive()) {
510+
$shopIds = Shop::getContextListShopID();
511+
}
512+
508513
$dbquery = new DbQuery();
509514
$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`');
510515
$dbquery->from('customer', 'c');
@@ -517,6 +522,10 @@ public function getSubscribers()
517522
$dbquery->where('c.`email` LIKE \'%' . pSQL($this->_searched_email) . '%\' ');
518523
}
519524

525+
if (!empty($shopIds)) {
526+
$dbquery->where('c.`id_shop` IN (' . implode(',', $shopIds) . ')');
527+
}
528+
520529
$customers = Db::getInstance((bool) _PS_USE_SQL_SLAVE_)->executeS($dbquery->build());
521530

522531
$dbquery = new DbQuery();
@@ -529,6 +538,10 @@ public function getSubscribers()
529538
$dbquery->where('e.`email` LIKE \'%' . pSQL($this->_searched_email) . '%\' ');
530539
}
531540

541+
if (!empty($shopIds)) {
542+
$dbquery->where('e.`id_shop` IN (' . implode(',', $shopIds) . ')');
543+
}
544+
532545
$non_customers = Db::getInstance()->executeS($dbquery->build());
533546

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

0 commit comments

Comments
 (0)