-
Notifications
You must be signed in to change notification settings - Fork 155
Open
Description
Prestashop version: 8.1.3 but I think it's unrelated to Prestashop version
Trying to add a manufacturer using either Add or AddAsync methods throws an exception at line 186 (using AddAsync) or at line 46 (using Add) in GenericFactory.cs:
Exception has occurred: CLR/System.InvalidOperationException
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll: 'Nullable object must have a value.'
In order to reproduce:
- Clone the GitHub repo
- Add a new console project to the solution
- Add PrestaSharp ass a reference to the project
- In Program.cs:
using Bukimedia.PrestaSharp.Entities;
using Bukimedia.PrestaSharp.Factories;
string url = "http://localhost/prestashop/api";
string account = "<api_key>";
string secretKey = "";
string manufacturerName = "TestManufacturer";
ManufacturerFactory manufacturerFactory = new ManufacturerFactory(url, account, secretKey);
// just to test that credentials are correct
List<manufacturer> manufacturers = manufacturerFactory.GetAll();
var newManufacturer = new manufacturer();
newManufacturer.name = manufacturerName;
newManufacturer.active = 1;
newManufacturer = manufacturerFactory.Add(newManufacturer);
// or
newManufacturer = await manufacturerFactory.AddAsync(newManufacturer);Reverting back before Merge pull request #469 fixes the issue:
git reset 0121cc0 --hardLooking at the AddBody method (that was change in pull request 469) in RestSharpFactory.cs I can see that entities is not used and serialized is just an empty string:
private void AddBody(RestRequest request, IEnumerable<PrestaShopEntity> entities)
{
request.RequestFormat = DataFormat.Xml;
var serialized = string.Empty;
serialized = "<prestashop>\n" + serialized + "\n</prestashop>";
request.AddParameter("application/xml", serialized, ParameterType.RequestBody);
}Metadata
Metadata
Assignees
Labels
No labels