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

Add Product - error Property Product->link_rewrite is empty #266

Open flauteps opened 7 years ago

flauteps commented 7 years ago

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

luiskar009 commented 7 years ago

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);

flauteps commented 7 years ago

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

<?xml version="1.0" encoding="UTF-8"?>

link_rewrite is empty"]]>

HttpStatusCode: BadRequest

thomasthesbjerg commented 6 years ago

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 "<![CDATA[84]]>

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); } ```