Developer forum

Forum » Ecommerce - Standard features » Display Unit of measure name for variant

Display Unit of measure name for variant

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have a project running on 9.17.9.

Products are organized in Master and variants, we have defined units for the Master products and Base units for Master products, all seem to be inherited to variants according to the interface.

However, the ProductViewModel definition does not include any information about the base unit no matter what I do. All corresponding nodes are empty.

I have tried using the Dynamicweb.Ecommerce.Stocks.UnitOfMeasureService() but I can only get the default "UnitId", without any option to get the "UnitName" or label.

First, I need to understand why I don't get any information about Units. Then, how should I get the Unit name of the default unit ID, assuming I can get, somehow, the DefaultUnitID?

Thank you,
Adrian


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

Anybody?

Thank you,
Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

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";
    }

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

I assume that you mean ProductViewModel.DefaultUnitId? That value comes directly from the product (Product.DefaultUnitId) and is stored in [EcomProducts].[ProductDefaultUnitId]

Maybe there is some confusion here about UnitOfMeasure vs Unit? These are separate things.
A UnitOfMeasure contains a UnitId which is a reference to a Unit.

In DW9 a Unit is represented as a VariantOption. You will have to fetch the unit through Dynamicweb.Ecommerce.Services.VariantOptions (as you have already found out) if you need additional information about the unit. If you only need the name you can use Dynamicweb.Ecommerce.Services.Variants.GetUnitName(string unitId, string languageId).

The confusion between Units and VariantOptions has been solved in DW10 where we added a separate UnitService (Dynamicweb.Ecommerce.Services.Units) and we also moved all units data to a separate EcomUnits table in the database.

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Maybe what you need is the stock units? These are included in ProductViewModel.StockUnits as instances of StockUnitViewModel.
The StockUnitViewModel has both UnitId and UnitName.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Morten,

Thank you for the answers. I am glad this confusion has been solved din DW10, as it will be much easier to avoid confusion.

What I needed was to display the DefaultUnit of the product regardless of the stock availability. Apparently, using one of the methods available, I could get the UnitID of a specific ProductId but the ProductViewModel would not include this information (DefaultUnitId, DefaultUnitName) in the ProductViewModel response. The values are correctly saved in the database. All Unit information was added through the interface, no funny business with integration.

I guess, this is the part that needs clarification. If the configuration is off for some reason, it would be good to know how to fix it. If it's a bug, we will need a fix.

If you think it's easier, I can submit a case to DW Care.

Thank you,

Adrian

 

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

ProductViewModel has a DefaultUnitId, but not a DefaultUnitName. You can use the DefaultUnitId in combination with the StockUnits though.
In a razor template you can use the methods I have already mentioned to retrieve the unit name.

Maybe I don't understand what the actual issue is here :)
I think we need more information about what you are trying to achieve, where and how you are trying to get this information and have a look at the current configuration of the solution.
Submiting a case to DW Care is probably a good idea. It's a lot easier if we can get access the solution and take a look at your current setup.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Morten,

In my case, even the DefaultUnitId is empty.

Regarding StockUnitViewModel, I could not find the corresponding Service or Method for identifying the StockUnitViewModel based on the UnitId.

I will send a request to DW care.

Thank you,
Adrian

 

You must be logged in to post in the forum