November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi,
Although there is no existing API:s to do so, but it's quite simple to do so.
In eCF system, Markets are represented by _ExcludedCatalogEntryMarkets metafield. It's a Dictionary which contains the "Excluded" market ids - there for if you add a market id to this metafield, then the entry will be unavailable in that market.
You can use the metafield API:s to manipulate this to archive your targets.
Regards.
/Q
So by default the entry is available to all the markets? If that is the case, I think that is what I want for now...
I'm having trouble with this also - see below:
MetaField marketsField = MetaField.Load(metaContext, "_ExcludedCatalogEntryMarkets");
MetaDictionary markets = MetaDictionary.Load(metaContext, marketsField);
foreach (string market in product.MarketExclusions.Split(','))
{
MetaDictionaryItem mdi = new MetaDictionaryItem(market);
}
MetaHelper.SetMetaFieldValue(metaContext, metaObj, "_ExcludedCatalogEntryMarkets", new object[] { markets });
product.MarketExclusions contains our market IDs, eg. 'AU', 'DE'. The error I'm receiving implies that market IDs must be numeric, which is contrary to the info in Commerce Manager. Or do we need to retrieve EPiServer's internal database ID for these markets first?
Thanks,
Jim
forgot this line:
markets.Add(market);
Still the same error though...any ideas?
Hi,
What is the error you're getting. MarketID should be the "code" of market when you create it, such as US, UK ...
/Q
Hi,
The error is on this line:
MetaHelper.SetMetaFieldValue(metaContext, metaObj, "_ExcludedCatalogEntryMarkets", new object[] { markets });
"Input string was not in a correct format."
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)\r\n at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)\r\n at System.Int32.Parse(String s)\r\n at Mediachase.Commerce.Storage.MetaHelper.
So something is trying to convert from string to number, but I don't know what. I thought at first the market exclusions were being added without calling this line, but a second look reveals that not to be the case.
For clarity here is the whole snippet again:
MetaField marketsField = MetaField.Load(metaContext, "_ExcludedCatalogEntryMarkets");
MetaDictionary markets = MetaDictionary.Load(metaContext, marketsField);
foreach (string market in product.MarketExclusions.Split(','))
{
MetaDictionaryItem mdi = new MetaDictionaryItem(market);
markets.Add(market);
}
MetaHelper.SetMetaFieldValue(metaContext, metaObj, "_ExcludedCatalogEntryMarkets", new object[] { markets });
metaObj.AcceptChanges(metaContext);
Thanks,
Jim
OK I see where I was going wrong here...what my code was doing was adding new values to the Markets metafield, rather than for the specific product.
So I've found that once I retrieve the market ID from the system, I can add that to the metafield value successfully. New code snippet:
MetaField marketsField = MetaField.Load(metaContext, "_ExcludedCatalogEntryMarkets");
MetaDictionary markets = MetaDictionary.Load(metaContext, marketsField);
foreach (string market in product.MarketExclusions.Split(','))
{
MetaDictionaryItem mdi = markets.GetItem(market);
MetaHelper.SetMetaFieldValue(metaContext, metaObj, "_ExcludedCatalogEntryMarkets", new object[] { mdi.Id });
}
metaObj.AcceptChanges(metaContext);
This appears to work. But is this the best way to add market exclusion data to a product? And would the same sort of method be the best way to add any MultiValue meta-data to a product?
Thanks,
Jim
From my point of view as a developer, I think this is too much work required for this task. Of course this is another metafield, but it's so special that it needs some proper treatment.
I'll discuss with our team to see if we can improve this.
Thanks.
/Q
OK I still had it wrong, when attempting to add multiple values to this field. But this works:
MetaField marketsField = MetaField.Load(metaContext, "_ExcludedCatalogEntryMarkets");
MetaDictionary markets = MetaDictionary.Load(metaContext, marketsField);
List
I guess I'll be using a similar method to update other multi-valued meta fields. Is there any existing helper method to do this sort of thing under the hood for multi-value meta fields?
Thanks.
You should be able to call this
metaObj["_ExcludedCatalogEntryMarkets"] = marketsToExclude.ToArray()
then save metaObj by AcceptChanges. The call to SetMetaFieldValue was not necessary.
Regards.
/Q
Hi Quan,
Thanks - this looks like it'll be simpler. Do you know if this call is any more efficient than
MetaHelper.SetMetaFieldValue(metaContext, metaObj, [fieldName], [arrayOfValues]);
? Or will it do exactly the same thing underneath?
Jim
Here's the different:
var dictionaryItemKeys = new HashSet<>>int>(values.Select(v => int.Parse(v.ToString())));
var selectedItems = new List
foreach (var dictionaryItem in mf.Dictionary.Cast
{
if (dictionaryItemKeys.Contains(dictionaryItem.Id))
{
selectedItems.Add(dictionaryItem);
}
}
this extra processing seems to be why you're getting the error. You can go with the simpler approach.
/Q
Hi,
We are writing a catalog import tool. Any idea how to associate Market an catalog entry?
Currently, our import tool will import all other information accept that the entry is not visible in any market.
Thanks,
Syed