Skip to content

Fixes after restsharp update #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,6 @@ pip-log.txt
## Testing
#############

.docker/data
.docker/data
/PrestaSharp/Entities/boxnow_entry.cs
/PrestaSharp/Factories/BoxnowEntryFactory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net452</TargetFrameworks>
<TargetFrameworks>net472;</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
3 changes: 3 additions & 0 deletions PrestaSharp/Entities/order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public class order : PrestaShopEntity, IPrestaShopFactoryEntity
public decimal total_wrapping_tax_incl { get; set; }
public decimal total_wrapping_tax_excl { get; set; }
public string shipping_number { get; set; }

public int? round_mode { get; set; }
public int? round_type { get; set; }
public decimal conversion_rate { get; set; }
public string reference { get; set; }
public AuxEntities.AssociationsOrder associations { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion PrestaSharp/Factories/ProductCustomizationFieldFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Bukimedia.PrestaSharp.Factories
{
public class ProductCustomizationFieldFactory : GenericFactory<customization_field>
{
protected override string singularEntityName { get { return "customization_fields"; } }
protected override string singularEntityName { get { return "customization_field"; } }
protected override string pluralEntityName { get { return "product_customization_fields"; } }

public ProductCustomizationFieldFactory(string BaseUrl, string Account, string SecretKey)
Expand Down
13 changes: 11 additions & 2 deletions PrestaSharp/Factories/RestSharpFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
using System.Security.Policy;
using System.Threading.Tasks;
using System.Xml.Linq;
using Bukimedia.PrestaSharp.Entities;
using RestSharp;
using RestSharp.Serializers;
using RestSharp.Serializers.Xml;

namespace Bukimedia.PrestaSharp.Factories
Expand Down Expand Up @@ -35,6 +38,11 @@ private void AddBody(RestRequest request, IEnumerable<PrestaShopEntity> entities
{
request.RequestFormat = DataFormat.Xml;
var serialized = string.Empty;
Serializer.XMLSerializer xmlSerializer = new Serializer.XMLSerializer();
foreach (var entity in entities)
{
serialized += xmlSerializer.Serialize(entity);
}
serialized = "<prestashop>\n" + serialized + "\n</prestashop>";
request.AddParameter("application/xml", serialized, ParameterType.RequestBody);
}
Expand Down Expand Up @@ -74,7 +82,8 @@ RestClient GetClient()
{
var client = new RestClient(
options => { options.BaseUrl = new Uri(BaseUrl); },
configureSerialization: s => s.UseXmlSerializer()
configureSerialization: s => s.UseSerializer(() => new PrestaSharp.Serializer.RestCustomSerializer())
//configureSerialization: s => s.UseXmlSerializer(null, "prestashop", true)
);
return client;
}
Expand Down Expand Up @@ -123,7 +132,7 @@ protected bool ExecuteHead(RestRequest request)

protected byte[] ExecuteForImage(RestRequest request)
{
var client = new RestClient();
var client = GetClient();
AddWsKey(request);
var response = client.Execute(request);
CheckResponse(response, request);
Expand Down
2 changes: 1 addition & 1 deletion PrestaSharp/PrestaSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
<TargetFrameworks>net472;</TargetFrameworks>
<RootNamespace>Bukimedia.PrestaSharp</RootNamespace>
<AssemblyName>Bukimedia.PrestaSharp</AssemblyName>
<Company>Bukimedia</Company>
Expand Down
23 changes: 23 additions & 0 deletions PrestaSharp/Serializer/RestCustomSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Bukimedia.PrestaSharp.Serializer;
using RestSharp;
using RestSharp.Serializers;
using System;

namespace Bukimedia.PrestaSharp.Serializer
{
public class RestCustomSerializer : IRestSerializer
{
private XMLSerializer sharpSerializer = new XMLSerializer();
public string? Serialize(object? obj) => obj == null ? null : sharpSerializer.Serialize(obj);
public string? Serialize(Parameter bodyParameter) => Serialize(bodyParameter.Value);
private XMLDeserializer sharpDeserializer = new XMLDeserializer();
public T? Deserialize<T>(RestResponse response) => sharpDeserializer.Deserialize<T>(response);
public ContentType ContentType { get; set; } = ContentType.Xml;
public ISerializer Serializer => new XMLSerializer();
public IDeserializer Deserializer => new XMLDeserializer();
public DataFormat DataFormat => DataFormat.Xml;
public string[] AcceptedContentTypes => ContentType.XmlAccept;
public SupportsContentType SupportsContentType
=> contentType => contentType.Value.EndsWith("xml", StringComparison.InvariantCultureIgnoreCase);
}
}
Loading