Products in alphabetical order.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 лет назад
Anyone know how to sort the products in alphabetical order, without having to change the Display order of the products.
14 лет назад
You will have to edit the stored procedure for loading products like this (the change is in bold and used to be ORDER BY do.DisplayOrder):

CREATE PROCEDURE [dbo].[Nop_ProductLoadAllPaged]
(
  @CategoryID      int = 0,
  @ManufacturerID    int = 0,
  @FeaturedProducts  bit = null,  --0 featured only , 1 not featured only, null - load all products
  @PriceMin      money = null,
  @PriceMax      money = null,
  @Keywords      nvarchar(MAX),  
  @SearchDescriptions bit = 0,
  @ShowHidden      bit = 0,
  @PageIndex      int = 0,
  @PageSize      int = 2147483644,
  @FilteredSpecs    nvarchar(300) = null,  --filter by attributes (comma-separated list). e.g. 14,15,16
  @TotalRecords    int = null OUTPUT
)
AS
BEGIN
  
  --init
  SET @Keywords = isnull(@Keywords, '')
  SET @Keywords = '%' + rtrim(ltrim(@Keywords)) + '%'

  SET @PriceMin = isnull(@PriceMin, 0)
  SET @PriceMax = isnull(@PriceMax, 2147483644)

  --display order
  CREATE TABLE #DisplayOrder
  (
    ProductID int not null PRIMARY KEY,
    DisplayOrder int not null
  )  

  IF @CategoryID IS NOT NULL AND @CategoryID > 0
    BEGIN
      INSERT #DisplayOrder
      SELECT pcm.ProductID, pcm.DisplayOrder
      FROM [Nop_Product_Category_Mapping] pcm WHERE pcm.CategoryID = @CategoryID
    END
    ELSE IF @ManufacturerID IS NOT NULL AND @ManufacturerID > 0
    BEGIN
      INSERT #DisplayOrder
      SELECT pmm.ProductID, pmm.Displayorder
      FROM [Nop_Product_Manufacturer_Mapping] pmm WHERE pmm.ManufacturerID = @ManufacturerID
    END
  ELSE
    BEGIN
      INSERT #DisplayOrder
      SELECT p.ProductID, 1
      FROM [Nop_Product] p
      ORDER BY p.[Name]
    END
  
  --filter by attributes
  SET @FilteredSpecs = isnull(@FilteredSpecs, '')
  CREATE TABLE #FilteredSpecs
  (
    SpecificationAttributeOptionID int not null
  )
  INSERT INTO #FilteredSpecs (SpecificationAttributeOptionID)
  SELECT CAST(data as int) FROM dbo.[NOP_splitstring_to_table](@FilteredSpecs, ',');
  
  DECLARE @SpecAttributesCount int  
  SELECT @SpecAttributesCount = COUNT(1) FROM #FilteredSpecs

  --paging
  DECLARE @PageLowerBound int
  DECLARE @PageUpperBound int
  DECLARE @RowsToReturn int
  
  SET @RowsToReturn = @PageSize * (@PageIndex + 1)  
  SET @PageLowerBound = @PageSize * @PageIndex
  SET @PageUpperBound = @PageLowerBound + @PageSize + 1
  
  CREATE TABLE #PageIndex
  (
    IndexID int IDENTITY (1, 1) NOT NULL,
    ProductID int NOT NULL,
    DisplayOrder int NOT NULL,
  )
  INSERT INTO #PageIndex (ProductID, DisplayOrder)
  SELECT DISTINCT p.ProductID, do.DisplayOrder
  FROM Nop_Product p with (NOLOCK)
  LEFT OUTER JOIN Nop_Product_Category_Mapping pcm with (NOLOCK) ON p.ProductID=pcm.ProductID
  LEFT OUTER JOIN Nop_Product_Manufacturer_Mapping pmm with (NOLOCK) ON p.ProductID=pmm.ProductID
  LEFT OUTER JOIN Nop_ProductVariant pv with (NOLOCK) ON p.ProductID = pv.ProductID
  JOIN #DisplayOrder do on p.ProductID = do.ProductID
  WHERE
    (
      (
        @ShowHidden = 1 OR p.Published = 1
      )
    AND
      (
        @ShowHidden = 1 OR pv.Published = 1
      )
    AND
      (
        p.Deleted=0
      )
    AND (
        @CategoryID IS NULL OR @CategoryID=0
        OR (pcm.CategoryID=@CategoryID AND (@FeaturedProducts IS NULL OR pcm.IsFeaturedProduct=@FeaturedProducts))
      )
    AND (
        @ManufacturerID IS NULL OR @ManufacturerID=0
        OR (pmm.ManufacturerID=@ManufacturerID AND (@FeaturedProducts IS NULL OR pmm.IsFeaturedProduct=@FeaturedProducts))
      )
    AND (
        pv.Price BETWEEN @PriceMin AND @PriceMax
      )
    AND  (
        patindex(@Keywords, isnull(p.name, '')) > 0
        or patindex(@Keywords, isnull(pv.name, '')) > 0
        or patindex(@Keywords, isnull(pv.sku , '')) > 0
        or (@SearchDescriptions = 1 and patindex(@Keywords, isnull(p.ShortDescription, '')) > 0)
        or (@SearchDescriptions = 1 and patindex(@Keywords, isnull(p.FullDescription, '')) > 0)
        or (@SearchDescriptions = 1 and patindex(@Keywords, isnull(pv.Description, '')) > 0)
      )
    AND
      (
        @ShowHidden = 1
        OR
        (getutcdate() between isnull(pv.AvailableStartDateTime, '1/1/1900') and isnull(pv.AvailableEndDateTime, '1/1/2999'))
      )
    AND
      (
        --filter by specs
        @SpecAttributesCount = 0
        OR
        (
          NOT EXISTS(
            SELECT 1
            FROM #FilteredSpecs [fs]
            WHERE [fs].SpecificationAttributeOptionID NOT IN (
              SELECT psam.SpecificationAttributeOptionID
              FROM dbo.Nop_Product_SpecificationAttribute_Mapping psam
              WHERE psam.AllowFiltering = 1 AND psam.ProductID = p.ProductID
              )
            )
          
        )
      )
    )
  ORDER BY p.Name

  --total records
  SET @TotalRecords = @@rowcount  
  SET ROWCOUNT @RowsToReturn
  
  --return
  SELECT  
    p.*
  FROM
    #PageIndex [pi]
    INNER JOIN Nop_Product p on p.ProductID = [pi].ProductID
  WHERE
    [pi].IndexID > @PageLowerBound AND
    [pi].IndexID < @PageUpperBound
  ORDER BY
    IndexID
  
  SET ROWCOUNT 0

  DROP TABLE #DisplayOrder
  DROP TABLE #FilteredSpecs
  DROP TABLE #PageIndex
END
GO
14 лет назад
THanks, but I cant make this work, I get server error when changing this, Im running Nop 1.3, so there is a little bit less code in that stored procedure.

Are you shoure it works, have you tried this?
14 лет назад
Thanks for pointing me in the right direction, but unfortunately that did not work for me, but I found this post that worked:
https://www.nopcommerce.com/boards/topic.aspx?topicid=879
14 лет назад
So it worked for you?  I did not test what I posted earlier...I should have but through my previous knowledge of SQL, I assumed it would work.  Teaches me for assuming.  I will test before I post next time.  I appreciate your follow up with what you found out.  I will be able to add this to my own memory for future use.  Thank you for you follow through.

So you have to do this right?

ORDER BY p.NAME, do.DisplayOrder
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.