PrestaSharp icon indicating copy to clipboard operation
PrestaSharp copied to clipboard

Add Product - error Property Product->link_rewrite is empty

Open flauteps opened this issue 8 years ago • 3 comments

Hi when I try to add a product we have the error: Property Product->link_rewrite is empty

flauteps avatar Jun 16 '17 14:06 flauteps

You can insert link_rewrite doing this:

product prod = new product(); string name = "Name of product" Bukimedia.PrestaSharp.Entities.AuxEntities.language auxLang = new Bukimedia.PrestaSharp.Entities.AuxEntities.language(); auxLang.Value = name.ToLower().Replace(" ", "-"); auxLang.id = 1; prod.link_rewrite.Add(auxLang);

luiskar009 avatar Jun 17 '17 11:06 luiskar009

Unfortunately, it does not work Below I attach the XML and the error

0 0 0 0 0 9788871921501 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 prod-1 1 Prod 1 1 Prod 1 0

application/json, application/xml, text/json, text/x-json, text/javascript, text/xml, text/html

link_rewrite is empty"]]>

HttpStatusCode: BadRequest

flauteps avatar Jun 19 '17 10:06 flauteps

You have probably forgotten to change the namespace in Bukimedia.PrestaSharpSerializer.cs

I moved the the location of Bukimedia.PrestaSharp.Entities.AuxEntities.language -> shop.api.prestashop.Entities.AuxEntities.language and the auto-apply-rename updated alle references except from the "Bukimedia.PrestaSharp.Entities.AuxEntities.language", since they were in a string.

Everything worked after that, and the " link_rewrite is empty"]]>" was gone.

Example from code: (- = before, and + = after)

private void Map(XElement root, object obj)
        {
     var name = prop.Name;
                 var rawValue = prop.GetValue(obj, null);
 
-                //Hack to serialize Bukimedia.PrestaSharp.Entities.AuxEntities.language
-                if (obj.GetType().FullName.Equals("**Bukimedia.PrestaSharp.Entities.AuxEntities.language**") && root.Name.LocalName.Equals("language") && name.Equals("id"))
+                //Hack to serialize shop.api.prestashop.Entities.AuxEntities.language
+                if (obj.GetType().FullName.Equals("**shop.api.prestashop.Entities.AuxEntities.language**") && root.Name.LocalName.Equals("language") && name.Equals("id"))
                 {
-
                     root.Add(new XAttribute(XName.Get("id"), rawValue));
                     continue;
                 }
-                else if (obj.GetType().FullName.Equals("**Bukimedia.PrestaSharp.Entities.AuxEntities.language**") && root.Name.LocalName.Equals("language") && name.Equals("Value"))
+                else if (obj.GetType().FullName.Equals("**shop.api.prestashop.Entities.AuxEntities.language**") && root.Name.LocalName.Equals("language") && name.Equals("Value"))
                 {
                     XText xtext = new XText(rawValue == null ? "" : rawValue.ToString());
                     root.Add(xtext);
        }

thomasthesbjerg avatar Sep 05 '17 14:09 thomasthesbjerg