Developer forum

Forum » Templates » update variant number

update variant number

Davor Zlotrg
Reply

I have a custom code for inserting products/variants and I have issues when I want to edit variant information (in my case productnumber).

This is what I tried and it didn’t work.

 

var var = new VariantCombination();

var.ProductID = dwProduct.ID;

var.VariantID = combo;

var.Product.Number = bp.sku;  --this line is not working

var.Save(dwProduct.ID, combo);

 

I also tried this:

 

var varProd = Product.GetProductByID(var.ProductID, var.VariantID);

varProd.Number = bp.sku;

varProd.SaveAndConfirm(varProd.ID, varProd.VariantID);

 

Calling Save() did not work, SaveAndConfirm() did work but it only took the last sku and set it to all variants.

 

Dynamicweb version is 8.8.1.6

 


Replies

 
Nicolai Pedersen
Reply

Hi Davor

What do you mean when you say "It does not work". Do you get an exception, does the death star implode or your wife starts to scream :-)?

NP

 
Davor Zlotrg
Reply

The value doesn't change. 

 
Nicolai Pedersen
Reply

How many languages do you have in ecommerce - and in which language context do you execute the code? And how are your fields configured in terms of inheritance (Fields section in MC/Ecommerce/Advanced)

BR Nicolai

 
Davor Zlotrg
Reply

We have 5 languages. 

"Which language context do you execute the code?" - I am not setting language context anywher in the code - shoud I?

How are your fields configured in terms of inheritance (Fields section in MC/Ecommerce/Advanced) - we use the default setup, we did not touch anything there.

 

 
Nicolai Pedersen
Reply

Hi Davor

If you have more languages, you should take that into consideration. Otherwise you do not know which language you save the data into - it could be that you edit in context of english, but see it in danish. The save method has an overload to specifically save to a language.

Can you screen dump your field setttings (there are no defaults) and your language configuration?

If you add a SQL profiler to the DB that you work on, can you spot the SQL coming in?

BR Nicolai

 
Davor Zlotrg
Reply

Hi Nicolai,

I tried this and it updates the main product and all variants

 

var varProd = Product.GetProductByID(var.ProductID, var.VariantID);
varProd.Number = "1111";
varProd.SaveAndConfirm(varProd.ID, varProd.VariantID, dwProduct.LanguageID);

Could you give me your email and I would send you the url to the website where you can check all the settings?

 
Nicolai Pedersen
Reply

Hi Davor

So, it works. If you want it to not save on product number on all main products and variants, you need to configure your fields differently.

See this section: http://manual.dynamicweb-cms.com/Dynamicweb-On-line-Manual/Management-Center/eCommerce/Advanced-configuration/Fields.aspx

BR Nicolai

 
Davor Zlotrg
Reply

Hi Nicolai,

I tried it and it still doesn't work. I attached the image with the configuration. 

When I uncheck "Number/Across all variants" - it creates a new product. 

 

It works when I just update variant number in the interface but not from the code. 

Pasted_image_at_2017_03_23_09_46_AM.png
 
Nicolai Pedersen
Reply

Hi Davor

And what did the SQL profiler say?

Just noted that you load the product by ID and variantid, but saves on id, variantid and language id. That is not good - it could be saving to another record.

 
Davor Zlotrg
Reply

Here is the update from sql profiler:

 

exec sp_executesql N'UPDATE [EcomProducts] SET [ProductNumber] = @p1 WHERE (([ProductID] = @p2) AND ([ProductLanguageID] = @p3) AND ([ProductVariantID] = @p4) AND ((@p5 = 1 AND [ProductDefaultShopID] IS NULL) OR ([ProductDefaultShopID] = @p6)) AND ((@p7 = 1 AND [ProductNumber] IS NULL) OR ([ProductNumber] = @p8)) AND ((@p9 = 1 AND [ProductName] IS NULL) OR ([ProductName] = @p10)) AND ((@p11 = 1 AND [ProductImageSmall] IS NULL) OR ([ProductImageSmall] = @p12)) AND ((@p13 = 1 AND [ProductImageMedium] IS NULL) OR ([ProductImageMedium] = @p14)) AND ((@p15 = 1 AND [ProductImageLarge] IS NULL) OR ([ProductImageLarge] = @p16)) AND ((@p17 = 1 AND [ProductLink1] IS NULL) OR ([ProductLink1] = @p18)) AND ((@p19 = 1 AND [ProductLink2] IS NULL) OR ([ProductLink2] = @p20)) AND ((@p21 = 1 AND [ProductPrice] IS NULL) OR ([ProductPrice] = @p22)) AND ((@p23 = 1 AND [ProductStock] IS NULL) OR ([ProductStock] = @p24)) AND ((@p25 = 1 AND [ProductStockGroupID] IS NULL) OR ([ProductStockGroupID] = @p26)) AND ((@p27 = 1 AND [ProductWeight] IS NULL) OR ([ProductWeight] = @p28)) AND ((@p29 = 1 AND [ProductVolume] IS NULL) OR ([ProductVolume] = @p30)) AND ((@p31 = 1 AND [ProductVatGrpID] IS NULL) OR ([ProductVatGrpID] = @p32)) AND ((@p33 = 1 AND [ProductManufacturerID] IS NULL) OR ([ProductManufacturerID] = @p34)) AND ((@p35 = 1 AND [ProductActive] IS NULL) OR ([ProductActive] = @p36)) AND ((@p37 = 1 AND [ProductPeriodID] IS NULL) OR ([ProductPeriodID] = @p38)) AND ((@p39 = 1 AND [ProductCreated] IS NULL) OR ([ProductCreated] = @p40)) AND ((@p41 = 1 AND [ProductUpdated] IS NULL) OR ([ProductUpdated] = @p42)) AND ((@p43 = 1 AND [ProductType] IS NULL) OR ([ProductType] = @p44)) AND ((@p45 = 1 AND [ProductPriceType] IS NULL) OR ([ProductPriceType] = @p46)) AND ((@p47 = 1 AND [ProductPriceCounter] IS NULL) OR ([ProductPriceCounter] = @p48)) AND ((@p49 = 1 AND [ProductVariantCounter] IS NULL) OR ([ProductVariantCounter] = @p50)) AND ((@p51 = 1 AND [ProductVariantProdCounter] IS NULL) OR ([ProductVariantProdCounter] = @p52)) AND ((@p53 = 1 AND [ProductVariantGroupCounter] IS NULL) OR ([ProductVariantGroupCounter] = @p54)) AND ((@p55 = 1 AND [ProductRelatedCounter] IS NULL) OR ([ProductRelatedCounter] = @p56)) AND ((@p57 = 1 AND [ProductUnitCounter] IS NULL) OR ([ProductUnitCounter] = @p58)) AND ((@p59 = 1 AND [ProductDefaultUnitID] IS NULL) OR ([ProductDefaultUnitID] = @p60)) AND ((@p61 = 1 AND [ProductDefaultVariantComboID] IS NULL) OR ([ProductDefaultVariantComboID] = @p62)) AND ((@p63 = 1 AND [ProductPriceMatrixUnit] IS NULL) OR ([ProductPriceMatrixUnit] = @p64)) AND ((@p65 = 1 AND [ProductPriceMatrixVariant] IS NULL) OR ([ProductPriceMatrixVariant] = @p66)) AND ((@p67 = 1 AND [ProductPriceMatrixPeriod] IS NULL) OR ([ProductPriceMatrixPeriod] = @p68)) AND ((@p69 = 1 AND [ProductPriceMatrixMultiplePrices] IS NULL) OR ([ProductPriceMatrixMultiplePrices] = @p70)) AND ((@p71 = 1 AND [ProductPriceMatrixQuantitySpecification] IS NULL) OR ([ProductPriceMatrixQuantitySpecification] = @p72)) AND ((@p73 = 1 AND [producent] IS NULL) OR ([producent] = @p74)) AND ((@p75 = 1 AND [ProductMetaTitle] IS NULL) OR ([ProductMetaTitle] = @p76)) AND ((@p77 = 1 AND [ProductOptimizedFor] IS NULL) OR ([ProductOptimizedFor] = @p78)) AND ((@p79 = 1 AND [ProductCommentcount] IS NULL) OR ([ProductCommentcount] = @p80)) AND ((@p81 = 1 AND [ProductRating] IS NULL) OR ([ProductRating] = @p82)) AND ((@p83 = 1 AND [ProductCost] IS NULL) OR ([ProductCost] = @p84)) AND ([ProductAutoID] = @p85) AND ((@p86 = 1 AND [ProductMetaCanonical] IS NULL) OR ([ProductMetaCanonical] = @p87)) AND ([ProductExcludeFromIndex] = @p88) AND ([ProductExcludeFromCustomizedUrls] = @p89) AND ([ProductExcludeFromAllProducts] = @p90) AND ((@p91 = 1 AND [ProductPoints] IS NULL) OR ([ProductPoints] = @p92)) AND ([bestseller] = @p93) AND ([new] = @p94) AND ([offer] = @p95) AND ([top10] = @p96) AND ((@p97 = 1 AND [top10date] IS NULL) OR ([top10date] = @p98)) AND ((@p99 = 1 AND [newdate] IS NULL) OR ([newdate] = @p100)) AND ((@p101 = 1 AND [offerdate] IS NULL) OR ([offerdate] = @p102)) AND ((@p103 = 1 AND [bestsellerdate] IS NULL) OR ([bestsellerdate] = @p104)) AND ((@p105 = 1 AND [Ean] IS NULL) OR ([Ean] = @p106)) AND ((@p107 = 1 AND [pricepurchase] IS NULL) OR ([pricepurchase] = @p108)) AND ((@p109 = 1 AND [pricerrp] IS NULL) OR ([pricerrp] = @p110)) AND ((@p111 = 1 AND [stocktype] IS NULL) OR ([stocktype] = @p112)) AND ((@p113 = 1 AND [stockminimum] IS NULL) OR ([stockminimum] = @p114)) AND ((@p115 = 1 AND [supplierno] IS NULL) OR ([supplierno] = @p116)) AND ((@p117 = 1 AND [suppliername] IS NULL) OR ([suppliername] = @p118)) AND ((@p119 = 1 AND [suppliersku] IS NULL) OR ([suppliersku] = @p120)) AND ((@p121 = 1 AND [suppliertitle] IS NULL) OR ([suppliertitle] = @p122)))',N'@p1 nvarchar(4),@p2 nvarchar(8),@p3 nvarchar(5),@p4 nvarchar(4000),@p5 int,@p6 nvarchar(5),@p7 int,@p8 nvarchar(10),@p9 int,@p10 nvarchar(27),@p11 int,@p12 nvarchar(4000),@p13 int,@p14 nvarchar(4000),@p15 int,@p16 nvarchar(4000),@p17 int,@p18 nvarchar(4000),@p19 int,@p20 nvarchar(4000),@p21 int,@p22 float,@p23 int,@p24 float,@p25 int,@p26 nvarchar(9),@p27 int,@p28 float,@p29 int,@p30 float,@p31 int,@p32 nvarchar(4000),@p33 int,@p34 nvarchar(6),@p35 int,@p36 bit,@p37 int,@p38 nvarchar(4000),@p39 int,@p40 datetime,@p41 int,@p42 datetime,@p43 int,@p44 int,@p45 int,@p46 int,@p47 int,@p48 int,@p49 int,@p50 int,@p51 int,@p52 int,@p53 int,@p54 int,@p55 int,@p56 int,@p57 int,@p58 int,@p59 int,@p60 nvarchar(4000),@p61 int,@p62 nvarchar(4000),@p63 int,@p64 int,@p65 int,@p66 int,@p67 int,@p68 int,@p69 int,@p70 int,@p71 int,@p72 nvarchar(4000),@p73 int,@p74 nvarchar(4000),@p75 int,@p76 nvarchar(4000),@p77 int,@p78 nvarchar(4000),@p79 int,@p80 int,@p81 int,@p82 float,@p83 int,@p84 float,@p85 bigint,@p86 int,@p87 nvarchar(4000),@p88 bit,@p89 bit,@p90 bit,@p91 int,@p92 float,@p93 bit,@p94 bit,@p95 bit,@p96 bit,@p97 int,@p98 datetime,@p99 int,@p100 datetime,@p101 int,@p102 datetime,@p103 int,@p104 datetime,@p105 int,@p106 nvarchar(4000),@p107 int,@p108 float,@p109 int,@p110 float,@p111 int,@p112 nvarchar(1),@p113 int,@p114 int,@p115 int,@p116 nvarchar(4),@p117 int,@p118 nvarchar(14),@p119 int,@p120 nvarchar(9),@p121 int,@p122 nvarchar(27)',@p1=N'1111',@p2=N'PROD1301',@p3=N'LANG1',@p4=N'',@p5=0,@p6=N'SHOP1',@p7=0,@p8=N'1001593000',@p9=0,@p10=N'Sort-One Size - Capri - Sæt',@p11=0,@p12=N'',@p13=0,@p14=N'',@p15=0,@p16=N'',@p17=0,@p18=N'',@p19=0,@p20=N'',@p21=0,@p22=175,19999999999999,@p23=0,@p24=2,@p25=0,@p26=N'STOCKGRP1',@p27=0,@p28=0,@p29=0,@p30=0,@p31=0,@p32=N'',@p33=0,@p34=N'MANU39',@p35=0,@p36=1,@p37=0,@p38=N'',@p39=0,@p40='2017-03-23 10:53:40',@p41=0,@p42='2017-03-23 10:53:40',@p43=0,@p44=0,@p45=0,@p46=1,@p47=0,@p48=0,@p49=0,@p50=1,@p51=0,@p52=0,@p53=0,@p54=0,@p55=0,@p56=0,@p57=0,@p58=0,@p59=0,@p60=N'',@p61=0,@p62=N'',@p63=0,@p64=0,@p65=0,@p66=0,@p67=0,@p68=0,@p69=0,@p70=0,@p71=0,@p72=N'',@p73=1,@p74=NULL,@p75=0,@p76=N'',@p77=0,@p78=N'',@p79=0,@p80=0,@p81=0,@p82=0,@p83=0,@p84=0,@p85=14392,@p86=0,@p87=N'',@p88=0,@p89=0,@p90=0,@p91=0,@p92=0,@p93=0,@p94=0,@p95=0,@p96=0,@p97=0,@p98='2017-03-23 00:00:00',@p99=0,@p100='2017-03-23 00:00:00',@p101=0,@p102='2017-03-23 00:00:00',@p103=0,@p104='2017-03-23 00:00:00',@p105=0,@p106=N'',@p107=0,@p108=89,599999999999994,@p109=0,@p110=0,@p111=0,@p112=N'1',@p113=0,@p114=1,@p115=0,@p116=N'1020',@p117=0,@p118=N'Masters Desire',@p119=0,@p120=N'1010102_1',@p121=0,@p122=N'Sort-One Size - Capri - Sæt'

 
Nicolai Pedersen
Reply

Hi Davor

@p1=N'1111',@p2=N'PROD1301',@p3=N'LANG1'

And if you query the database for all records where the product id=PROD1301 - does any of them have the 1111 value? And how many records do you have with that productid?

 
Davor Zlotrg
Reply

I have 1 record in the dabase

Pasted_image_at_2017_03_23_12_40_PM.png
 
Nicolai Pedersen
Reply

And it has the value of 1111 in product number - as you specified when saving. So what is not working?

 

You must be logged in to post in the forum