Friday, April 19, 2024 7:59:12 PM
if @LanguageId>0
begin
declare @countLanguage int
set @countLanguage=0
select @countLanguage=count(*)
from Language L WITH (NOLOCK)
/* where L.Published=1
and (@StoreId=0 or L.LimitedToStores=0 or Exists(select Top 1 Id from StoreMapping sm WITH (NOLOCK)
where sm.EntityName = 'Language' and sm.StoreId=@StoreId and sm.EntityId=L.Id))*/
if @countLanguage=1
begin
set @LanguageId=0
end
end
if @LanguageId>0
begin
create table #tmpLocalizedProperty (EntityId int, LocaleKey nvarchar(400), LocaleValue nvarchar(max))
insert into #tmpLocalizedProperty (EntityId, LocaleKey, LocaleValue)
select L.EntityId, L.LocaleKey, L.LocaleValue
from LocalizedProperty L
where L.LocaleKeyGroup='Category'
and L.LanguageId=@LanguageId
and L.EntityId in (select Id from #tmpCategory)
update G
set Name=ISNULL(L.LocaleValue,G.name)
from #tmpCategory G left join #tmpLocalizedProperty L on G.Id=L.EntityId
and L.LocaleKey='Name'
update G
set [Description]=ISNULL(L.LocaleValue,G.[Description])
from #tmpCategory G left join #tmpLocalizedProperty L on G.Id=L.EntityId
and L.LocaleKey='Description'
update G
set MetaKeywords=ISNULL(L.LocaleValue,G.MetaKeywords)
from #tmpCategory G left join #tmpLocalizedProperty L on G.Id=L.EntityId
and L.LocaleKey='MetaKeywords'
update G
set MetaDescription=ISNULL(L.LocaleValue,G.MetaDescription)
from #tmpCategory G left join #tmpLocalizedProperty L on G.Id=L.EntityId
and L.LocaleKey='MetaDescription'
update G
set MetaTitle=ISNULL(L.LocaleValue,G.MetaTitle)
from #tmpCategory G left join #tmpLocalizedProperty L on G.Id=L.EntityId
and L.LocaleKey='MetaTitle'
drop table #tmpLocalizedProperty
update C
set SeName=ltrim(rtrim(Substring(US.Slug,1,400)))
from #tmpCategory C, (select TOP 1 WITH TIES U.EntityId,U.Slug
from UrlRecord U WITH (NOLOCK)
where U.EntityId in (select Id from #tmpCategory)
and U.EntityName='Category' and U.LanguageId=@LanguageId and U.IsActive=1
and ltrim(rtrim(U.Slug))!=''
ORDER BY ROW_NUMBER() OVER(PARTITION BY U.EntityId ORDER BY U.Id DESC)) US
where C.Id=US.EntityId
end
--category position (display order)
IF @CategoryIdsCount > 0 SET @sql_orderby = ' pcm.DisplayOrder ASC'
--manufacturer position (display order)
IF @ManufacturerId > 0
BEGIN
IF LEN(@sql_orderby) > 0 SET @sql_orderby = @sql_orderby + ', '
SET @sql_orderby = @sql_orderby + ' pmm.DisplayOrder ASC'
END
--name
IF LEN(@sql_orderby) > 0 SET @sql_orderby = @sql_orderby + ', '
SET @sql_orderby = @sql_orderby + ' p.[Name] ASC'