Posted on 06/11/2024 13:10:31
Hi guys,
Since I got no answers to this issue, I had to dig it up on my own.
I have managed to get a hold of the UnitName but not using one of the Unit related services or Stock related services but using the VariantsOptions service:
var unit = Dynamicweb.Ecommerce.Services.VariantOptions.GetVariantOption(unitId);
string unitName = unit is object ? unit.GetName(Dynamicweb.Ecommerce.Common.Context.LanguageID) : string.Empty;
It still does not explain why the DefaultUnit information in the ProductViewModel is empty, although the information is correctly filled on the product and also localized. I believe someone from Dynamicweb should answer if this is a known bug of 9.17.9 or some other weird reason.
Another thing that I think should be solved is this confusion between Units and VariantOptions. My expectation would be to get the relevant information from one place. As long as the GetUnitOfMeasures(product.Id) will return a list of units, I should be able to get also the UnitName not just the UnitID. Maybe a new method that would use also the LanguageID could do the trick. The way it is configured right now, it's simply confusing.
One more thing, in this process I have tried the Dynamicweb ChatBot for trying to find this information. It has provided a lot of "Hypothetical" methods for retrieving the UnitName, none of which worked. But the logic of the ChatBot was actually what I was expecting to have available:
// Assuming UnitService includes a method like GetUnitById
var unit = Dynamicweb.Ecommerce.Services.Units.GetUnitById(unitId);
if (unit != null)
{
return unit.Name; // Returns the Unit name
}
else
{
return "Unit not found";
}