Developer forum

Forum » Development » Properties for groups, products, orders

Properties for groups, products, orders


Reply

Hi!

Is there any general fields that need to be set when creating products, groups or orders?

I'm using this to create a product with an associated group. The product is created and I can se that the product belongs to this group, but the group isn't showed in the menu in the Product catalog tree:

My code:

Product p = new Product("");

            p.ID = id;

            p.Name = name;

            p.Active = true;

            p.Number = id;

            p.DefaultShopID = Shop.getShops("SHOP1").get_Item(0).ID;    //set shop ID

            p.Language = Dynamicweb.eCommerce.Common.Application.DefaultLanguage;   //set language ID

            Group group1 = new Group("");

            group1.Name = "My group1";

            group1.ShopID = Shop.getShops("SHOP1").get_Item(0).ID;

            group1.LanguageID = Dynamicweb.eCommerce.Common.Application.DefaultLanguage.LanguageID;
            group1.Save("group67");

            p.Groups.Add(group1);

            p.Save();

One problem with the DW api I think, is that when certain fields are mandatory for a successful creation, there is no exception telling what's missing when these fields a left out.

And the last thing I wonder is if there's some fields that applies to both products, groups and orders when you want to accomplish a successful creation of these types?

Best regards,

Per

Best regards,
Per


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
Hi Per

Which version of Dynamicweb are you using? I ask because we changed some of the API regarding this issue in 7.2 to automatically create Product-Group relations and Group-Shop relations so you don't have to worry about that.

Your code looks fine, so I think this issue has to do with caching. Does you group appear under the Shop node in eCommerce after your AppPool recycles?

- Jeppe
 
Reply
Hi, it's version 19.2.1.3.

What do you mean by "AppPool recycling?" The code I'm running is hosted on the dw server.

Best regards,
Per
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
Hi Per

What I mean by AppPool recycling is when the web server resets it's current state and releases all allocated memory for your website. This happens automatically evey night at 4 AM (at least in the HostNordic environments), when the allocated memory for the given site reaches a predefined limit, when a new assembly is added to the bin folder of your website or when triggered manually by "iisreset" or through the IIS Manager.

If you have Terminal access to the webserver, you should be able to trigger a AppPool recycle manually and check to see if the Group has appeared under the Shop node in eCommerce.

Is the solution hosted by HostNordic or do you host it yourself? If it's hosted by HostNordic and you tell me the name of the solution, I can recycle it for you.

- Jeppe
 
Reply
Hi!

I created this group several days ago so it should have been recycled.

As I said the group is attached to the product, but the group isn't shown in the tree.

Best regards,
Per
 
Reply
The code is hosted on the hostnordic server.
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
Hi Per

I've done some digging, and it turns out, that the GroupShopRelation is not automatically created correctly. I have added this as a bug in our BackLog and I suspect that it will be fixed with version 19.2.2.2 (I won't be able to get it into the current release).

In the meantime you can use the "old" way of doing it, where you create the GroupShopRelation yourself. This is the way it was done before 7.2. You can use the following code to do that:

var gsr = new GroupShopRelation();
gsr.ShopID = "SHOP1";
gsr.GroupID = "GROUP1";
gsr.Save(gsr.GroupID, gsr.ShopID);

On a side note, the way you specify what ID you want your Group to have is not entirely complete. If you want to specify the ID yourself and not have it be an auto generated value, then you need to make sure, that Group.ID contains something at least a dummy value. The value you specify in the Group.Save("ID") will then be used as the ID of that Group. For example:

var group1 = new Group("");
group1.Save("MyID");

var group2 = new Group("");
group2.ID = "MyID";
group2.Save("MyID");

var group3 = new Group("");
group3.ID = "dummy";
group3.Save("MyID");

Here group1 will be given an auto generated ID, whereas group2 and group3 will have "MyID" as ID.

Hope this helps :)

- Jeppe
 
Reply
What were you smoking when you came up with this API? I think from a developer's perspective, this is what I'd expect:

var group1 = new Group();
group1.ID = "MyId";
group1.Save();

This would create a new Group and use MyID as the ID. Alternatively, I could use this:

var group2 = new Group();
group2.Save();

This would save the group and assign an ID automatically.

Any chance we're going to see enhancements like this in DW 8? I never quite understood why you need to pass the ID to  the constructor, set a property and pass it to the Save method. That's as WET as it can be.... ;-)

Imar
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
Hi Imar

I have no idea what was inhaled at the time, but you're from Holland so you tell me, what could it have been? ;)

I agree that it would make for a much cleaner API, and it is something we would like to change. We are looking into making those enhancements for DW8, but as of now there are no guarantees.

- Jeppe
 
Reply
Must have been some of our best stuff.... ;-)

Anyway, glad to see changes are made. I recently was involved with a large coded API import, and currently a lot of work is involved to do simple things. The changes you're proposing (such as auto-creating group-relations) are very welcome.

Kind regards,

Imar

 

You must be logged in to post in the forum