I am currently stuck with my SQL.
We want to pull the top 3 products in a category on the product page. We will use this if the alternative products are empty. Thus we will always have alternative products for the customer regardless if we pre set them or not.
My problem is the code runs and pulls the top products from all categories and just shows the category id as the product been displayed.
note. I am only pulling pc.CategoryID and p.Looks for testing to see what is being returned. They will be removed once I have it working.
C#/VB.NET Code:
SELECT TOP 3
pc.CategoryID,
p.Looks,
p.ProductID,
p.SEName,
p.Summary,
p.SKU,
pv.SKUSuffix,
p.Name AS ProductName,
ISNULL(pv.SalePrice, pv.Price) AS ProductPrice
FROM
dbo.Product p WITH (nolock)
JOIN
dbo.ProductVariant pv WITH (nolock) ON pv.ProductID = p.ProductID
JOIN
dbo.ProductCategory pc WITH (nolock) ON pc.ProductID = 94
WHERE
p.Deleted = 0
and p.Published = 1
and pv.IsDefault = 1
and p.IsCallToOrder = 0
and p.productid != 94
ORDER BY
p.Looks desc
Can anyone shed some light on why I can not pull products in a set category correctly.
Also the number '94' is just a product ID we have, in the XML package the '94' would be replaced by the currently viewed product ID.
Many thanks in advance.