It seems like ByCustomerNumber on Carts doesn't work as intended. Whenever I call it, it doesn't add the OrderCustomerNumber clause to the select statement
exec sp_executesql N'
DECLARE @DefaultRate float;
SET ARITHABORT OFF;
SET @DefaultRate = IsNull((SELECT TOP 1 CurrencyRate FROM EcomCurrencies WHERE CurrencyIsDefault = 1), 100);
DECLARE @Time datetime;
SET @Time = @p0;
WITH
OrderedOrders AS (
SELECT ROW_NUMBER() OVER(ORDER BY OrderDate DESC) AS RowNumber, EcomOrders.OrderId, ShopName, EcomRecurringOrder.* , AccessUser.AccessUserName AS OrderSecondaryUserName FROM EcomOrders WITH (NOLOCK)
LEFT JOIN EcomCurrencies ON EcomOrders.OrderCurrencyCode = EcomCurrencies.CurrencyCode AND EcomCurrencies.CurrencyLanguageID = @p1
LEFT JOIN EcomOrderStates ON EcomOrders.OrderStateID = EcomOrderStates.OrderStateID
LEFT JOIN EcomShops ON EcomOrders.OrderShopID = EcomShops.ShopID
LEFT JOIN EcomRmas ON EcomOrders.OrderID = EcomRmas.RmaReplacementOrderId
LEFT JOIN AccessUser ON EcomOrders.OrderSecondaryUserID = AccessUser.AccessUserID
LEFT JOIN EcomRecurringOrder ON EcomOrders.OrderRecurringOrderId = EcomRecurringOrder.RecurringOrderID
LEFT JOIN EcomTrackAndTrace ON EcomOrders.OrderTrackAndTraceId = EcomTrackAndTrace.TrackAndTraceId
WHERE
EcomOrders.OrderDeleted = 0 AND
EcomOrders.OrderComplete = 0 AND
(EcomOrders.OrderIsQuote = 0 OR EcomOrders.OrderComplete = 1) AND
EcomOrders.OrderIsLedgerEntry = @p2 AND
EcomOrders.OrderCart = 1 AND
(EcomOrders.OrderIsRecurringOrderTemplate = 0 or OrderIsRecurringOrderTemplate is NULL)
),
OrdersCount as ( SELECT COUNT(*) AS TotalOrdersCount FROM OrderedOrders )
SELECT * FROM OrdersCount, OrderedOrders WITH (NOLOCK)
WHERE RowNumber BETWEEN @p3 AND @p4 ORDER BY RowNumber',N'@p0 datetime,@p1 nvarchar(5),@p2 int,@p3 int,@p4 int',@p0='2023-08-25 06:27:20.367',@p1=N'LANG1',@p2=0,@p3=101,@p4=200
It seems to be a problem with the logic in CartController and OrderRepository. The Customer clause is only added if CustomerId > 0 and if ByCustomerNumber is true, only CustomerNumber is set.
CartController:
OrderRepository: