Bukimedia / PrestaSharp

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

Extend product class #371

Closed lichesser closed 5 years ago

lichesser commented 5 years ago

Hy,

is there a guideline on how to extend Prestasharp? Means, we use Prestasharp Nuget package within our project and found out, that there are properties missing in the webservice., So, that's why we want to extend f.ex the product class by 2 additional properties (used in step 4 of product backend). I started with adding a folder to my project called 'PrestasharpExtension', where I put in an 'Entities' and 'Factories' folder, where I places a product.cs and a ProductFactory.cs.

In my product.cs I did this:

[XmlType(Namespace = "myProject/PrestasharpExtension/Entities")]

public class product : PrestaShopEntity
{
    public int additional_delivery_times { get; set; }

    public product()
    {
    }
}

and in my ProductFactory this

namespace myProject.PrestasharpExtension.Factories {

public class ProductFactory : GenericFactory<product>
{
    protected override string singularEntityName { get { return "additional_delivery_times"; } }
    protected override string pluralEntityName   { get { return "additional_delivery_times"; } }

    public ProductFactory(string BaseUrl, string Account, string SecretKey)
        : base(BaseUrl, Account, SecretKey)
    {

    }
}

}

What I'd have expected is, that I can now use this new property within my product entity like

myproduct.additional_delivery_times = 1

but this doesn't work.

What am I missing?

Gtx, L

lichesser commented 5 years ago

Hy,

a little refactoring of our code helped to make the product class extension work. What we found out is, that we had to name the extension class also 'product' and trick around a little bit with namespaces (Bukimedia.PrestaSharp.Entities.product vs our project.PrestasharpExtension.Entities). Our class was first named 'myProduct' but this didn't work, since it seems that xml deserialization magically matches the singularEntityName, so it expected a 'product' and not a 'myproduct' and didn't return any data.

Since it's solved for us, I close the ticket.

Gtx, L

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.