Bukimedia / PrestaSharp

CSharp .Net client library for the PrestaShop API via web service
GNU General Public License v3.0
154 stars 152 forks source link

"Nullable object must have a value" when adding a new Feature Value #438

Closed gleoussis closed 2 years ago

gleoussis commented 2 years ago

Hello, I am trying to add a feature value (gender) in prestashop using PrestaSharp.

PrestaShop has the correct GenderProdFeature.id (id = 8) At first I retrieve all All Product Feature Values in a list When the product item's gender is not found in AllProductFeatureValues , I create it and then refresh the AllProductFeatureValues list.
Upon creating it, I get "System.InvalidOperationException: Nullable object must have a value." Can anyone spot the problem?

Thanks in advance :)

` [Bukimedia.PrestaSharp.PrestaSharpException: application/xml:

8 0 WOMAN DONNA ] ` HttpStatusCode: 0 ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host Here is a piece of the actual code: ` var productFeatureFactory = new ProductFeatureFactory(Globals.baseUrl, Globals.account, Globals.password); var productFeatureValueFactory = new ProductFeatureValueFactory(Globals.baseUrl, Globals.account, Globals.password); List AllProductFeatureValues = productFeatureValueFactory.GetAll(); var GenderProdFeature = productFeatureFactory.Get(Globals.GenderId); // value = 8, exists in PrestaShop var GenderFeatureValue = AllProductFeatureValues.Where(pfv => pfv.value[0].Value == "WOMAN").FirstOrDefault(); if (GenderFeatureValue == null) { //not found, create it GenderFeatureValue = new product_feature_value { id_feature = GenderProdFeature.id, value = new List { new Bukimedia.PrestaSharp.Entities.AuxEntities.language((long)LangEN.id, "WOMAN"), new Bukimedia.PrestaSharp.Entities.AuxEntities.language((long)LangIT.id, "DONNA") } }; GenderFeatureValue = productFeatureValueFactory.Add(GenderFeatureValue); // => EXCEPTION AllProductFeatureValues = productFeatureValueFactory.GetAll(); //refresh AllProductFeatureValues after the new addition } //then associate feature with item psItem.associations.product_features.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.product_feature { id = GenderProdFeature.id.Value, id_feature_value = GenderFeatureValue.id.Value }); `
gleoussis commented 2 years ago

It appears the base URL given was wrong, I changed it and now works fine. Thanks anyway