diff --git a/Repository/CustomerRepository.php b/Repository/CustomerRepository.php index 16a2708..79c27a2 100644 --- a/Repository/CustomerRepository.php +++ b/Repository/CustomerRepository.php @@ -59,12 +59,30 @@ public function fetch($offset = 0, $limit = 250) $query->leftJoin('defaultpayment', 's_core_paymentmeans_attributes', 'defaultpayment_attributes', 'defaultpayment.id = defaultpayment_attributes.paymentmeanID'); $this->addTableSelection($query, 's_core_paymentmeans_attributes', 'defaultpayment_attributes'); - $query->leftJoin('customer', 's_core_locales', 'customerlanguage', 'customer.language = customerlanguage.id'); - $this->addTableSelection($query, 's_core_locales', 'customerlanguage'); - - $query->leftJoin('customer', 's_core_shops', 'shop', 'customer.subshopID = shop.id'); + $query->leftJoin( + 'customer', + 's_core_shops', + 'shop', + 'customer.subshopID = shop.id' + ); $this->addTableSelection($query, 's_core_shops', 'shop'); + // customer.language maps to the shopID and not the localeID + $query->leftJoin( + 'customer', + 's_core_shops', + 'customerlanguageshop', + 'customer.language = customerlanguageshop.id' + ); + + $query->leftJoin( + 'customer', + 's_core_locales', + 'customerlanguage', + 'customerlanguage.id = customerlanguageshop.locale_id' + ); + $this->addTableSelection($query, 's_core_locales', 'customerlanguage'); + $query->where('customer.id IN (:ids)'); $query->setParameter('ids', $ids, Connection::PARAM_STR_ARRAY); diff --git a/Service/LanguageService.php b/Service/LanguageService.php index 49c0258..65a9b11 100644 --- a/Service/LanguageService.php +++ b/Service/LanguageService.php @@ -87,8 +87,25 @@ private function fetchCustomerLocaleIds() { $query = $this->connection->createQueryBuilder(); $query->from('s_user', 'customer'); - $query->addSelect('DISTINCT customer.language'); + $query->leftJoin( + 'customer', + 's_core_shops', + 'customerlanguageshop', + 'customer.language = customerlanguageshop.id' + ); + + $query->leftJoin( + 'customerlanguageshop', + 's_core_locales', + 'customerlocales', + 'customerlanguageshop.locale_id = customerlocales.id' + ); + + $query->addSelect('customerlocales.id'); + $query->distinct(); $query->where('customer.language IS NOT NULL'); + $query->andWhere('customerlanguageshop.locale_id IS NOT NULL'); + $query->andWhere('customerlocales.id IS NOT NULL'); return $query->execute()->fetchAll(\PDO::FETCH_COLUMN); }