SQL |
SELECT
tblShoppersBasketItems.shopperBasketItemID AS basket_item_id,
tblShoppersBasketItems.shopperID AS shopper_id,
tblShoppersBasketItems.optionID AS option_id,
tblShoppersBasketItems.shopperbasketitemQuantity AS quantity,
tblShoppersBasketItems.categoryID AS category_id,
tblShoppersBasketItems.ShopperBasketItemCreatedDate AS created_date,
tblShoppersBasketItems.ShopperBasketItemCreatedDate AS date_created,
tblManufacturers.Name AS manufacturer_title,
tblManufacturers.ID AS manufacturer_id,
tblProducts.ManufacturerCode AS manufacturer_code,
tblProducts.ID AS product_id,
tblProducts.Title AS title,
tblProducts.Colour AS colour,
tblProducts.PostageSizeClass AS postage_size_class,
tblProducts.AgeRestricted AS age_restricted,
tblProducts.AllowDeliveryAddress AS allow_delivery_address,
tblProducts.AllowInternationalDelivery AS allow_international_delivery,
tblProducts.RFDRestricted AS rfd_restricted,
tblProducts.URLSafeTitle AS url_safe_title,
tblProducts.ImageThumb_URL AS image_thumb_url,
tblProducts.isSpecialOffer AS special_offer,
ISNULL(tblProducts.AllowFinance, 1) AS allow_finance,
tblOptions.Title AS option_title,
tblOptions.Price AS price,
tblOptions.StockCode AS stock_code,
tblOptions.ManufacturerCode AS option_manufacturer_code,
tblOptions.Quantity AS stock_pack_size,
shopperbasketitemCreatedDate AS date_created,
dbo.sf_getStockLevel_V3(tblOptions.StockCode, 1) AS stock_level,
tblCategories.Title AS category_title,
0 AS free_item,
(
SELECT SUM(shopperbasketitemQuantity)
FROM tblShoppersBasketItems
WHERE (shopperID = ?)
AND (shopperbasketitemQuantity > 0)
) AS total_items
FROM
tblShoppersBasketItems
INNER JOIN tblOptions ON tblShoppersBasketItems.optionID = tblOptions.ID
INNER JOIN tblProducts ON tblOptions.ProductID = tblProducts.ID
INNER JOIN tblManufacturers ON tblManufacturers.ID = tblProducts.ManufacturerID
INNER JOIN tblCategories ON tblCategories.ID = tblShoppersBasketItems.categoryID
WHERE
(tblShoppersBasketItems.shopperID = ?)
AND (tblShoppersBasketItems.shopperbasketitemQuantity > 0)
ORDER BY
tblShoppersBasketItems.ShopperBasketItemCreatedDate |