November Happy Hour will be moved to Thursday December 5th.

Get CtalogEntryId and catalog Entries based on CatalogNodeId and CatalogId

Vote:
 

Hi Team,

I need to export all the products under Catalog in to an excel in Episerver6 R2.I am able to get selected CatalogNodeId and CatalogId by using FrameworkContext.Current.CatalogSystem.GetCatalogNode(CatalogNode).Please let me know how I can get CatalogEntryId and Catalog Entries.

#148358
May 11, 2016 8:48
Vote:
 

Hi,

If you look into ICatalogSystem, you'll find plenty methods that can help you that. Check out 

FindCatalogItemsTable(ItemSearchParameters parameters)


#148360
May 11, 2016 10:25
Vote:
 

Hi,

I used FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)) for getting the entries from catalog.But I have total 44 enteries it is showing only 20 enteries but the entries.TotalResults were showing 44.Please let me know how can I retrieve other entry items.

#148499
May 16, 2016 8:25
Vote:
 

Hi,

CatalogSearchOptions have RecordsToRetrieve and StartingRecord properties, make sure to set them to right value (should be int.MaxValue and 0, respectively)

Regards,

/Q

#148500
Edited, May 16, 2016 8:51
Vote:
 

Thank you Quan...

#148501
May 16, 2016 8:54
Vote:
 

Hi Quan,

Can you please provide me some sample code for importing the data from csv file to Commerce manager catlalog.

I need to simply update the IsActive field column values availble in csv to commerce manager based on Catalog entryid and Node Id

#148509
May 16, 2016 11:05
Vote:
 

I have no such sample code at hand. But you should be able to read the field (IsActive), the CatalogEntryId and CatalogNodeId from the CSV, then use ICatalogSystem/CatalogContext to load the CatalogEntryDto/CatalogNodeDto, update the value then save it. It should be easier and more flexible that way.

Regards,

/Q

#148511
May 16, 2016 11:10
Vote:
 

Hi Quan,

I am able to load the CatalogEntryDto.My requirement is to update the meatfield value and save.I have created a new metafield(customsortorder) for catalog.How can I get the value of that metafield particular to an entry.If my output is an entry I can simply use entry.ItemAttributes["customsortorder"].Value[0] to get the value of my metafiled.but here the output I receive is CatalogEntryDto.

Please help me in getting the metafield value for each entry?

#148804
May 24, 2016 13:44
Vote:
 

Hi,

If you want to update the metafield, then it'll be a little complicated. You will have to use MetaObject to load the metaobject, something like this:

MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, entryDto.CatalogEntry[0].CatalogEntryId, entryDto.CatalogEntry[0].MetaClassId);

metaObject["customsortorder"] = <something>;

metaObject.AcceptChanges();

Note that R2 SP2 is just too old for me - the APIs might have changed a bit, so the code above might not be entirely correct, but you get the idea.

Regards,

/Q

#148807
May 24, 2016 14:00
Vote:
 

Thanq Quan ....

sample code helped me with minimal changes.

#148824
May 24, 2016 15:36
Vote:
 

Hi Quan,

I am exporting the catalaog data to excel using finditems() and importing the data from excel. I am updating the custom meta field and importing in to catalog.Everything looks fine.The updated metafields are stored in DB but when i tried to export the data it still shows old excel values not the updated one.

Please suggest on this.

#148855
May 25, 2016 12:21
Vote:
 

I don't really know why it happens, but perhaps you have a cached issue - there is a scheduled job "Serialized data" you can run before exporting data.

Regards,

/Q

#148856
May 25, 2016 12:24
Vote:
 

I had the similar issue with this custom metafield.If i try to update the value from DB the changes are not getting reflected until unless i manually edit the metafiled value from commerce manager.

#148857
May 25, 2016 12:28
Vote:
 

Hi Quan,

I haven't found "Serialized data" job in EPISERVER CMS6R2.

#148866
May 25, 2016 13:52
Vote:
 

Its name is Serialize Catalog Meta Data Job - I could not remember its name and had to look it up :)

#148868
May 25, 2016 14:00
Vote:
 

Hi Quan,

The problem is there with all custom metafields under catalog entries. What ever changes I am  doing from Database are storing in the metafileds but not reflecting the changes exactly .I tried rebuild index still no use. The changes are refelcting only once I click on OK button on the catalog entry. 

Please help how can I able to resolve this.

#149197
May 26, 2016 6:53
Vote:
 

Hi,

So if I understand you correctly, then you use MetaObject to update the MetaField's value in the context of front-end (CMS site), then export the data from that. The database is updated, but the data exported is not correct?

And it's not "Rebuild index", I meant you will have to run Serialize Catalog Meta Data Job and wait for it to complete.

/Q

#149201
May 26, 2016 9:47
Vote:
 

Quan,

 Serialize Catalog Meta Data Job is available in Episerver 7.5.Is it availble in Episerver 6r2? I did not find this job in CMS6r2.

#149204
May 26, 2016 10:13
Vote:
 

OK so it looks like that scheduled job was added in Commerce R3 - my bad - R2SP2 was too far in the past.

When you edit your CatalogEntryDto, you should be able to do this:

        private static void IndexCatalogEntryDto(CatalogEntryDto.CatalogEntryRow entryRow, string[] languages)
        {
            CatalogContext.MetaDataContext.UseCurrentUICulture = false;
            MetaObjectSerialized serialized = new MetaObjectSerialized();
            foreach (string language in languages)
            {
                CatalogContext.MetaDataContext.Language = language;
                MetaObject metaObj = null;
                metaObj = MetaObject.Load(CatalogContext.MetaDataContext, entryRow.CatalogEntryId, entryRow.MetaClassId);

                if (metaObj == null)
                    continue;

                serialized.AddMetaObject(language, metaObj);
            }

            entryRow.SerializedData = serialized.BinaryValue;
            CatalogContext.MetaDataContext.UseCurrentUICulture = true;
        }

Where languages are the available languages.
Regards,
/Q
#149206
May 26, 2016 10:23
Vote:
 

Hi Quan,

still there is no luck.Please find my sample code.

private static void IndexCatalogEntryDto(CatalogEntryDto.CatalogEntryRow entryRow, string[] languages)
{
CatalogContext.MetaDataContext.UseCurrentUICulture = false;
MetaObjectSerialized serialized = new MetaObjectSerialized();
foreach (string language in languages)
{
CatalogContext.MetaDataContext.Language = language;
//MetaObject metaObj = null;
// metaObj = MetaObject.Load(CatalogContext.MetaDataContext, entryRow.CatalogEntryId, entryRow.MetaClassId);
MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, entryRow.CatalogEntryId, entryRow.MetaClassId);
if (metaObject == null)
continue;
MetaHelper.SetMetaFieldValue(CatalogContext.MetaDataContext, metaObject, "customsortorder", new object[] { "100" });
metaObject.AcceptChanges(CatalogContext.MetaDataContext);
serialized.AddMetaObject(language, metaObject);
}

entryRow.SerializedData = serialized.BinaryValue;
CatalogContext.MetaDataContext.UseCurrentUICulture = true;
}

All the entries has customsortorder as 100 in DB.But when i start exporting the entries it has the old ones.

#149207
May 26, 2016 11:34
Vote:
 

You should save the value first, then load the MetaObject again before serializing its data to SerializedData 

#149208
May 26, 2016 11:46
Vote:
 

Quan,

Did i missed anything here.still i am facing the same issue after loading metaobject again

MetaDataContext metaContext = new MetaDataContext();
MetaObject metaObject = MetaObject.Load(metaContext, entryDto.CatalogEntry[0].CatalogEntryId, entryDto.CatalogEntry[0].MetaClassId);

MetaHelper.SetMetaFieldValue(metaContext, metaObject, "customsortorder", new object[] { Item.SortOrder });
metaObject.AcceptChanges(metaContext);
MetaObject metaObj = MetaObject.Load(metaContext, entryDto.CatalogEntry[0].CatalogEntryId, entryDto.CatalogEntry[0].MetaClassId);
MetaObjectSerialized serialized = new MetaObjectSerialized();
serialized.AddMetaObject("en-ca", metaObj);
entryDto.CatalogEntry[0].SerializedData = serialized.BinaryValue;
CatalogContext.MetaDataContext.UseCurrentUICulture = true;

#149210
May 26, 2016 12:29
Vote:
 

entryDto.CatalogEntry[0].SerializedData = serialized.BinaryValue;

You should save the entryDto :)

/Q

#149212
May 26, 2016 12:42
Vote:
 

Thank you Quan :) ....finally resolved.

#149218
May 26, 2016 13:06
Vote:
 

Hi Quan,

Instead of passing product name as serachphrase criteria I need to pass meta field value.

Can you please let me know how this can be done

Thanks,

Nymisha

#149505
Jun 02, 2016 8:59
Vote:
 

Here' an example of how it can be done:

private void testCatalogEntiresSearch()
{
    CatalogSearchParameters parameters = new CatalogSearchParameters();
    parameters.SqlMetaWhereClause = "Meta.DisplayName = 'Canon'";
    CatalogSearchOptions options = new CatalogSearchOptions();
    options.Classes.Add("Brands");
    options.RecordsToRetrieve = 20;
    Entries result = CatalogContext.Current.FindItems (parameters, options, new CatalogEntryResponseGroup());
}

You're searching entries with DisplayName = 'Canon'

Regards,

/Q

#149506
Jun 02, 2016 9:15
Vote:
 

Thanq Quan for the sample code.

Can I directly add class"CatalogEntryEx_Variant_Localization" for  Options,as my metafiled values are avaible under CatalogEntryEx_Variant_Localization table.

But enteries were null when I add CatalogEntryEx_Variant_Localization as Class for options.

#149525
Jun 02, 2016 15:13
Vote:
 

You should add "Variant" - it's the metaclass's name, not the table name.

/Q

#149526
Jun 02, 2016 15:16
Vote:
 

Hi Quan,

Below is the peice of code I used to update the metafield "custom sort order" with the value in Excel sheet.But after running the below code rest of the metafields under catalog are showing the value as Null.Could you please help me out on this.

MetaHelper.SetMetaFieldValue(metaContext, metaObject, "customsortorder", new object[] { Item.SortOrder });
metaObject.AcceptChanges(metaContext);
CatalogContext.Current.SaveCatalogEntry(entryDto);

MetaObject metaObj = MetaObject.Load(metaContext, entryDto.CatalogEntry[0].CatalogEntryId, entryDto.CatalogEntry[0].MetaClassId);
MetaObjectSerialized serialized = new MetaObjectSerialized();
serialized.AddMetaObject("en-ca", metaObj);
entryDto.CatalogEntry[0].SerializedData = serialized.BinaryValue;
CatalogContext.MetaDataContext.UseCurrentUICulture = true;
CatalogContext.Current.SaveCatalogEntry(entryDto);

Thanks

#151022
Jul 07, 2016 8:51
Vote:
 

You should call CatalogContext.MetaDataContext.UseCurrentUICulture = false; before then CatalogContext.MetaDataContext.UseCurrentUICulture = true; after the operation. I think this should work:

CatalogContext.MetaDataContext.UseCurrentUICulture = false

//Load metaObject

MetaHelper.SetMetaFieldValue(metaContext, metaObject, "customsortorder", new object[] { Item.SortOrder });

MetaObjectSerialized serialized = new MetaObjectSerialized();

serialized.AddMetaObject("en-ca", metaObject);

entryDto.CatalogEntry[0].SerializedData = serialized.BinaryValue;

CatalogContext.Current.SaveCatalogEntry(entryDto);

CatalogContext.MetaDataContext.UseCurrentUICulture = true;

#151023
Edited, Jul 07, 2016 9:00
Vote:
 

No Quan.Still same issue.

CatalogContext.MetaDataContext.UseCurrentUICulture = false;
MetaHelper.SetMetaFieldValue(metaContext, metaObject, "customsortorder", new object[] { Item.SortOrder });
metaObject.AcceptChanges(metaContext);
CatalogContext.Current.SaveCatalogEntry(entryDto);

MetaObject metaObj = MetaObject.Load(metaContext, entryDto.CatalogEntry[0].CatalogEntryId, entryDto.CatalogEntry[0].MetaClassId);
MetaObjectSerialized serialized = new MetaObjectSerialized();
serialized.AddMetaObject("en-ca", metaObj);
entryDto.CatalogEntry[0].SerializedData = serialized.BinaryValue;

CatalogContext.Current.SaveCatalogEntry(entryDto);
CatalogContext.MetaDataContext.UseCurrentUICulture = true;

#151025
Jul 07, 2016 9:44
Vote:
 

If i manullay click on 'OK' of Catalog entry from commercemanager then only other metafield values are populating.Once i run the above code,then the below values are null

Description = GetMetadDataValue(entry, ENTRY_META_DESCRIPTION_BRIEF),
ProductSecondHeadline = GetMetadDataValue(entry, ENTRY_META_HEADLINE_SECOND),
ProductThirdHeadline = GetMetadDataValue(entry, ENTRY_META_HEADLINE_THIRD),

private string GetMetadDataValue(Entry entry, string metaDataFieldName)
{
if (!String.IsNullOrEmpty(metaDataFieldName) && entry != null)
{
var _object = entry.ItemAttributes[metaDataFieldName];
if (_object != null)
{
return Convert.ToString(entry.ItemAttributes[metaDataFieldName], CultureInfo.InvariantCulture);
}
}
return string.Empty;
}

#151026
Jul 07, 2016 9:50
Vote:
 

Hi Quan,

Any solution for my problem with metafield?

Thanks

#151053
Jul 08, 2016 15:39
Vote:
 

Hi,

Can you post the entire code here. metaContext comes some somewhere - you should be using CatalogContext.MetaDataContext, after 

CatalogContext.MetaDataContext.UseCurrentUICulture = false;

CatalogContext.MetaDataContext.Language = language;

This is important as I suspect metaContext.Language was not properly set.

/Q

#151071
Jul 11, 2016 8:49
Vote:
 

Hi Quan,

Below is the code for updating the excel values in to 'custom sort order' meta field Of catalog.

int CtalgEntryId = Convert.ToInt32(Item.CatalogEntryId);
var entryDto = CatalogContext.Current.GetCatalogEntryDto(CtalgEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

MetaDataContext metaContext = new MetaDataContext();
MetaObject metaObject = MetaObject.Load(metaContext, entryDto.CatalogEntry[0].CatalogEntryId, entryDto.CatalogEntry[0].MetaClassId);
if (string.IsNullOrEmpty(Item.SortOrder))
{
Item.SortOrder = "0";
}
IsIntOrNot = int.TryParse(Item.SortOrder, out EnteredIntValue);
if (IsIntOrNot)
{
CatalogContext.MetaDataContext.UseCurrentUICulture = false;
MetaHelper.SetMetaFieldValue(metaContext, metaObject, "customsortorder", new object[] { Item.SortOrder });
// MetaHelper.SetMetaFieldValue(metaContext, metaObject, "customsortorder", new object[] { Item.SortOrder });
metaObject.AcceptChanges(metaContext);
CatalogContext.Current.SaveCatalogEntry(entryDto);
System.IO.File.AppendAllText(@"C:\test\sortorder.txt", "Metaclassid" + Convert.ToString(entryDto.CatalogEntry[0].MetaClassId) + System.Environment.NewLine);
MetaObject metaObj = MetaObject.Load(metaContext, entryDto.CatalogEntry[0].CatalogEntryId, entryDto.CatalogEntry[0].MetaClassId);
MetaObjectSerialized serialized = new MetaObjectSerialized();
serialized.AddMetaObject("en-ca", metaObj);
serialized.AddMetaObject("fr-ca", metaObj);
//entryDto.CatalogEntry[0].SerializedData = serialized.BinaryValue;
CatalogContext.Current.SaveCatalogEntry(entryDto);

CatalogContext.MetaDataContext.UseCurrentUICulture = true;
lblUpdated.Style["display"] = "";
lblUpdated.Text = "Imported succesfully";

}

After importing, all the other metafields in the catalog are having null.In DB values are there.But the below code which fect the other metafield value is returning empty.

    private string GetMetadDataValue(Entry entry, string metaDataFieldName) 

      {            if (!String.IsNullOrEmpty(metaDataFieldName) && entry != null)       

    {                var _object = entry.ItemAttributes[metaDataFieldName];         

      if (_object != null)         

      {                    return Convert.ToString(entry.ItemAttributes[metaDataFieldName], CultureInfo.InvariantCulture);           

    }           

}           

return string.Empty;   

    }
.

#151074
Jul 11, 2016 9:32
Vote:
 

Hi,

I think this can be problematic: MetaDataContext metaContext = new MetaDataContext();, because this MetaDataContext instance lacks of crucial information (Language, for example) 

You should be using this:

CatalogContext.MetaDataContext.UseCurrentUICulture = false;

MetaDataContext metaContext = CatalogContext.MetaDataContext;

metaContext .Language = "en-ca";

//do your stuffs here

metaContext .Language = "fa-ca";

//do your stuffs here

CatalogContext.MetaDataContext.UseCurrentUICulture = true;

/Q

#151079
Jul 11, 2016 10:16
Vote:
 

Quan,

Working now.Thans for the help :)

#151083
Jul 11, 2016 13:26
Vote:
 

Hi Quan,

I need to display an logo in email.Can I able to  do this from CMS ?I tried plaing the image in cms but it is not showing up in mails.Do we need to give any permissions?If so please let me know what kind of permission need to assigned to get the logo in mails.

Please help me on this.

#151556
Jul 28, 2016 14:32
Vote:
 

Hi,

The new question should be asked in CMS forum.

However, make sure two things:

- The image is set to public, so everyone can read it.

- You insert the public URL of the image in the mail.

Regards,

/Q

#151557
Jul 28, 2016 14:41
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.