Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: "group by" error #407

Merged
merged 12 commits into from
Jan 20, 2025
264 changes: 132 additions & 132 deletions e2e/src/fixtures/1.7/modules.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Handler/ErrorHandler/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class ErrorHandler
public function __construct($sentryDsn, $sentryEnv)
{
try {
/** @var \ModuleCore $accountsModule */
/** @var false|\ModuleCore $accountsModule */
$accountsModule = \Module::getInstanceByName('ps_accounts');
/** @var mixed $accountService */
$accountService = $accountsModule->get('PrestaShop\Module\PsAccounts\Service\PsAccountsService');
$accountService = $accountsModule->getService('PrestaShop\Module\PsAccounts\Service\PsAccountsService');

/** @var \ModuleCore $eventbusModule */
$eventbusModule = \Module::getInstanceByName('ps_eventbus');
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/BundleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BundleRepository extends AbstractRepository implements RepositoryInterface
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down Expand Up @@ -103,7 +103,7 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso)

$this->query
->where('pac.id_product_pack IN(' . implode(',', array_map('intval', $contentIds)) . ')')
// ->limit($limit) Sub shop content depend from another, temporary disabled
->limit($limit)
;

return $this->runQuery();
Expand Down
12 changes: 6 additions & 6 deletions src/Repository/CarrierDetailRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,28 @@ class CarrierDetailRepository extends AbstractRepository implements RepositoryIn
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'ca');

// minimal query for countable query
$this->query
->innerJoin('delivery', 'd', 'ca.id_carrier = d.id_carrier AND d.id_zone IS NOT NULL')
->innerJoin('country', 'co', 'd.id_zone = co.id_zone AND co.iso_code IS NOT NULL AND co.active = 1')
->leftJoin('range_weight', 'rw', 'ca.id_carrier = rw.id_carrier AND d.id_range_weight = rw.id_range_weight')
->leftJoin('range_price', 'rp', 'ca.id_carrier = rp.id_carrier AND d.id_range_price = rp.id_range_price')
->leftJoin('state', 's', 'co.id_zone = s.id_zone AND co.id_country = s.id_country AND s.active = 1')
->leftJoin('configuration', 'conf', 'conf.name = "PS_SHIPPING_METHOD"')
->select('ca.id_reference')
->groupBy('ca.id_reference, co.id_zone, id_range')
;

if ($withSelecParameters) {
$this->query
->select('ca.id_reference')
->select('d.id_zone')
->select('
CASE
Expand Down Expand Up @@ -111,8 +113,6 @@ public function generateFullQuery($langIso, $withSelecParameters)
) AS price
')
;

$this->query->groupBy('ca.id_reference, co.id_zone, id_range');
}
}

Expand Down Expand Up @@ -176,10 +176,10 @@ public function countFullSyncContentLeft($offset, $limit, $langIso)
$this->generateFullQuery($langIso, true);

$result = $this->db->executeS('
SELECT (COUNT(*) - ' . (int) $offset . ') AS count
SELECT COUNT(*) - ' . (int) $offset . ' AS count
FROM (' . $this->query->build() . ') as subquery;
');

return is_array($result) ? $result[0]['count'] : [];
return is_array($result) ? $result[0]['count'] : 0;
}
}
2 changes: 1 addition & 1 deletion src/Repository/CarrierRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CarrierRepository extends AbstractRepository implements RepositoryInterfac
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
15 changes: 6 additions & 9 deletions src/Repository/CarrierTaxeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,29 @@ class CarrierTaxeRepository extends AbstractRepository implements RepositoryInte
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
public function generateFullQuery($langIso, $withSelecParameters)
{
$this->generateMinimalQuery(self::TABLE_NAME, 'ca');

// minimal query for countable query
$this->query
->innerJoin('carrier_tax_rules_group_shop', 'ctrgs', 'ca.id_carrier = ctrgs.id_carrier')
->innerJoin('tax_rule', 'tr', 'ctrgs.id_tax_rules_group = tr.id_tax_rules_group')
->innerJoin('country', 'co', 'tr.id_country = co.id_country AND co.iso_code IS NOT NULL AND co.active = 1')
->innerJoin('delivery', 'd', 'ca.id_carrier = d.id_carrier AND d.id_zone IS NOT NULL')
->innerJoin('tax', 't', 'tr.id_tax = t.id_tax AND t.active = 1')
->leftJoin('state', 's', 'tr.id_state = s.id_state AND s.active = 1')
;

$this->query
->where('(co.id_zone = d.id_zone OR s.id_zone = d.id_zone)')
->select('ca.id_reference')
->groupBy('ca.id_reference, co.id_zone, id_range, country_id')
;

if ($withSelecParameters) {
$this->query
->select('ca.id_reference')
->select('co.id_zone')
->select('
CASE
Expand All @@ -81,8 +80,6 @@ public function generateFullQuery($langIso, $withSelecParameters)
')
->select('t.rate AS tax_rate')
;

$this->query->groupBy('ca.id_reference, co.id_zone, id_range, country_id');
}
}

Expand Down Expand Up @@ -146,10 +143,10 @@ public function countFullSyncContentLeft($offset, $limit, $langIso)
$this->generateFullQuery($langIso, true);

$result = $this->db->executeS('
SELECT (COUNT(*) - ' . (int) $offset . ') AS count
SELECT COUNT(*) - ' . (int) $offset . ' AS count
FROM (' . $this->query->build() . ') as subquery;
');

return is_array($result) ? $result[0]['count'] : [];
return is_array($result) ? $result[0]['count'] : 0;
}
}
2 changes: 1 addition & 1 deletion src/Repository/CartProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CartProductRepository extends AbstractRepository implements RepositoryInte
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/CartRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CartRepository extends AbstractRepository implements RepositoryInterface
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/CartRuleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CartRuleRepository extends AbstractRepository implements RepositoryInterfa
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CategoryRepository extends AbstractRepository implements RepositoryInterfa
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/CurrencyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CurrencyRepository extends AbstractRepository implements RepositoryInterfa
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/CustomProductCarrierRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CustomProductCarrierRepository extends AbstractRepository implements Repos
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/CustomerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CustomerRepository extends AbstractRepository implements RepositoryInterfa
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/EmployeeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EmployeeRepository extends AbstractRepository implements RepositoryInterfa
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/ImageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ImageRepository extends AbstractRepository implements RepositoryInterface
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/ImageTypeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ImageTypeRepository extends AbstractRepository implements RepositoryInterf
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/LanguageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LanguageRepository extends AbstractRepository implements RepositoryInterfa
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/ManufacturerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ManufacturerRepository extends AbstractRepository implements RepositoryInt
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/ModuleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ModuleRepository extends AbstractRepository implements RepositoryInterface
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/OrderCarrierRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class OrderCarrierRepository extends AbstractRepository implements RepositoryInt
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Repository/OrderCartRuleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class OrderCartRuleRepository extends AbstractRepository implements RepositoryIn
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand Down Expand Up @@ -101,8 +101,8 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
$this->generateFullQuery($langIso, true);

$this->query
->where('ocr.id_order IN(' . implode(',', array_map('intval', $contentIds)) . ')')
// ->limit($limit) Sub shop content depend from another, temporary disabled
->where('ocr.id_order_cart_rule IN(' . implode(',', array_map('intval', $contentIds)) . ')')
->limit($limit)
;

return $this->runQuery();
Expand Down
23 changes: 12 additions & 11 deletions src/Repository/OrderDetailRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class OrderDetailRepository extends AbstractRepository implements RepositoryInte
* @param string $langIso
* @param bool $withSelecParameters
*
* @return mixed
* @return void
*
* @throws \PrestaShopException
*/
Expand All @@ -56,18 +56,20 @@ public function generateFullQuery($langIso, $withSelecParameters)

$this->generateMinimalQuery(self::TABLE_NAME, 'od');

// minimal query for countable query
$this->query
->where('od.id_shop = ' . $context->shop->id)
->innerJoin('orders', 'o', 'od.id_order = o.id_order')
->leftJoin('order_slip_detail', 'osd', 'od.id_order_detail = osd.id_order_detail')
->leftJoin('product_shop', 'ps', 'od.product_id = ps.id_product AND ps.id_shop = ' . (int) $context->shop->id)
->leftJoin('currency', 'c', 'c.id_currency = o.id_currency')
->leftJoin('lang', 'l', 'o.id_lang = l.id_lang')
->select('od.id_order_detail')
->groupBy('od.id_order_detail')
;

if ($withSelecParameters) {
$this->query
->select('od.id_order_detail')
->select('od.id_order')
->select('od.product_id')
->select('od.product_attribute_id')
Expand Down Expand Up @@ -98,8 +100,6 @@ public function retrieveContentsForFull($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, true);

$this->query->groupBy('od.id_order_detail');

$this->query->limit((int) $limit, (int) $offset);

return $this->runQuery();
Expand All @@ -124,8 +124,8 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
$this->generateFullQuery($langIso, true);

$this->query
->where('od.id_order IN(' . implode(',', array_map('intval', $contentIds)) . ')')
// ->limit($limit) Sub shop content depend from another, temporary disabled
->where('od.id_order_detail IN(' . implode(',', array_map('intval', $contentIds)) . ')')
->limit($limit)
;

return $this->runQuery();
Expand All @@ -143,12 +143,13 @@ public function retrieveContentsForIncremental($limit, $contentIds, $langIso)
*/
public function countFullSyncContentLeft($offset, $limit, $langIso)
{
$this->generateFullQuery($langIso, false);

$this->query->select('(COUNT(*) - ' . (int) $offset . ') as count');
$this->generateFullQuery($langIso, true);

$result = $this->runQuery(true);
$result = $this->db->executeS('
SELECT COUNT(*) - ' . (int) $offset . ' AS count
FROM (' . $this->query->build() . ') as subquery;
');

return $result[0]['count'];
return is_array($result) ? $result[0]['count'] : 0;
}
}
Loading
Loading