Skip to content

Commit

Permalink
new campaigns filter
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspijak committed Dec 18, 2018
1 parent 3bbf05b commit 652b0ca
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions prestasms/src/Customers.php
Expand Up @@ -18,20 +18,20 @@ public function __construct(Extensions\Database\IDatabase $db)

public function getTotal()
{
return (int) $this->db->execute("SELECT COUNT(`id_customer`) AS `total` FROM `{$this->db->table('address')}` WHERE `id_customer` != 0 AND (`phone_mobile` OR `phone`) AND `active` = 1")->getRow()->total;
return (int) $this->db->execute("SELECT COUNT(DISTINCT `id_customer`) AS `total` FROM `{$this->db->table('address')}` WHERE `id_customer` != 0 AND (`phone_mobile` OR `phone`) AND `active` = 1")->getRow()->total;
}


public function getFilteredTotal(array $customers)
{
return (int) $this->db->execute("SELECT COUNT(`id_customer`) AS `total` FROM `{$this->db->table('address')}` WHERE `id_customer` IN ('".implode("','", $customers)."') AND (`phone_mobile` OR `phone`) AND `active` = 1")->getRow()->total;
return (int) $this->db->execute("SELECT COUNT(DISTINCT `id_customer`) AS `total` FROM `{$this->db->table('address')}` WHERE `id_customer` IN ('".implode("','", $customers)."') AND (`phone_mobile` OR `phone`) AND `active` = 1")->getRow()->total;
}


protected function loadCustomers(array $customers, $limit = null)
{
return $this->db->execute("
SELECT
SELECT
`{$this->db->table('customer')}`.`email`,
`{$this->db->table('address')}`.`firstname` AS `first_name`,
`{$this->db->table('address')}`.`lastname` AS `last_name`,
Expand All @@ -53,6 +53,7 @@ protected function loadCustomers(array $customers, $limit = null)
". (count($customers) > 0 ? "`{$this->db->table('customer')}`.`id_customer` IN ('".implode("','", $customers)."') AND" : "") . "
`{$this->db->table('address')}`.`active` = 1 AND
(`{$this->db->table('address')}`.`phone_mobile` OR `{$this->db->table('address')}`.`phone`)
GROUP BY `{$this->db->table('customer')}`.`id_customer`
". ($limit !== null ? ("LIMIT ".(int) $limit) : "")
)->getRows();
}
Expand Down Expand Up @@ -113,7 +114,14 @@ protected function filter(array $filters)
case 'order_date':
$customers = $this->getCustomers($this->db->execute("SELECT `id_customer` FROM `{$this->db->table('orders')}` WHERE {$this->getSql($filter, 'date_add')}"), $customers);
break;
case 'order_status':
$customers = $this->getCustomers($this->db->execute("SELECT `id_customer` FROM `{$this->db->table('orders')}` WHERE {$this->getSql($filter, 'current_state')}"), $customers);
break;
case 'store':
$customers = $this->getCustomers($this->db->execute("SELECT `id_customer` FROM `{$this->db->table('customer')}` WHERE {$this->getSql($filter, 'id_shop')}"), $customers);
break;
}

$filtered = true;
}
}
Expand Down

0 comments on commit 652b0ca

Please sign in to comment.