Skip to content

Instantly share code, notes, and snippets.

@ig0r74
Last active February 25, 2022 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ig0r74/f7e6dddb1d5fa1b72929d158eba9797c to your computer and use it in GitHub Desktop.
Save ig0r74/f7e6dddb1d5fa1b72929d158eba9797c to your computer and use it in GitHub Desktop.
MODX вычисляем сумму остатков по TV и выводим с нулевым остатком в конце. При этом сохраняется сортировка по menuindex у остальных товаров.
{set $goods = 'msProducts' | snippet : [
'sortby' => '{"null_total_remains":"DESC", "menuindex":"DESC"}',
'tpl' => 'good.category3',
'leftJoin' => [
"remains" => [
"class" => "modTemplateVarResource",
"on" => "msProduct.id = remains.contentid AND remains.tmplvarid IN (29,30,31,32,33,34,52)" // id TV с остатками
],
],
'select' => [
"remains" => "
CASE
WHEN SUM(remains.value) IS NULL THEN 0
WHEN SUM(remains.value) = 0 THEN 0
ELSE 1
END
as null_total_remains"
],
]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment