CSharp .Net client library for the PrestaShop API via web service
A simple .Net REST client written in C# for the Prestashop API. PrestaSharp uses the RestSharp library to consume the Prestashop services.
PrestaSharp is available on NuGet. Use the package manager console to install it:
Install-Package PrestaSharp
string baseUrl = "http://www.myweb.com/api";
string account = "ASDLKJOIQWEPROQWUPRPOQPPRQOW";
string password = "";
ManufacturerFactory manufacturerFactory = new ManufacturerFactory(baseUrl, account, password);
Bukimedia.PrestaSharp.Entities.manufacturer manufacturer = manufacturerFactory.Get(6);
manufacturer.name = "Iron Maiden";
manufacturer.active = 1;
manufacturerFactory.Add(manufacturer);
manufacturerFactory.Update(manufacturer);
manufacturerFactory.Delete(manufacturer);
Bukimedia.PrestaSharp.Entities.product myProduct = new Bukimedia.PrestaSharp.Entities.product();
ProductFactory productFactory = new ProductFactory(baseUrl, account, password);
myProduct = productFactory.Add(myProduct);
ImageFactory imageFactory = new ImageFactory(baseUrl, account, password);
imageFactory.AddProductImage((long)myProduct.id, "C:\\MyImage.jpg");
StockAvailableFactory stockAvailableFactory = new StockAvailableFactory(baseUrl, account, password);
long stockAvailableId = myProduct.associations.stock_availables[0].id;
Bukimedia.PrestaSharp.Entities.stock_available myStockAvailable = stockAvailableFactory.Get(stockAvailableId);
myStockAvailable.quantity = 99; // Number of available products
myStockAvailable.out_of_stock = 1; // Must enable orders
stockAvailableFactory.Update(myStockAvailable);
List<manufacturer> manufacturers = ManufacturerFactory.GetAll();
List<long> ids = ManufacturerFactory.GetIds();
Dictionary<string, string> dtn = new Dictionary<string, string>();
dtn.Add("name", "Metallica");
List<manufacturer> manufacturers = ManufacturerFactory.GetByFilter(dtn, null, null);
Dictionary<string, string> dtn = new Dictionary<string, string>();
dtn.Add("name", "[Metall]%");
List<manufacturer> manufacturers = ManufacturerFactory.GetByFilter(dtn, null, null);
Dictionary<string, string> dtn = new Dictionary<string, string>();
dtn.Add("name", "Metallica");
List<long> ids = ManufacturerFactory.GetIdsByFilter(dtn, null, null);
Dictionary<string, string> dtn = new Dictionary<string, string>();
dtn.Add("name", "[Metall]%");
List<long> ids = ManufacturerFactory.GetIdsByFilter(dtn, null, null);
Dictionary<string, string> dtn = new Dictionary<string, string>();
dtn.Add("name", "[Metall]%");
List<manufacturer> manufacturers = ManufacturerFactory.GetByFilter(dtn, "name_ASC", "5");
Dictionary<string, string> dtn = new Dictionary<string, string>();
dtn.Add("name", "[Metall]%");
List<manufacturer> manufacturers = ManufacturerFactory.GetByFilter(dtn, "name_ASC", "9,5");
Dictionary<string, string> dtn = new Dictionary<string, string>();
dtn.Add("name", "[Metallica|Nirvana|Pantera]");
List<long> ids = ManufacturerFactory.GetIdsByFilter(dtn, null, null);
DateTime startDate = new DateTime (2016, 1, 1);
DateTime endDate = new DateTime (2016, 1, 31);
Dictionary<string, string> filter = new Dictionary<string, string>();
string dFrom = string.Format("{0:yyyy-MM-dd HH:mm:ss}", startDate);
string dTo = string.Format("{0:yyyy-MM-dd HH:mm:ss}", endDate);
filter.Add("date_add", "[" + dFrom + "," + dTo + "]");
List<long> prestaSharpOrderIds = this.OrderFactory.GetIdsByFilter(filter, "id_DESC", null);
Enabling debugging in PrestaShop would make PrestaSharp exceptions more verbose, to enable that, edit /config/defines.inc.php
file in your PrestaShop website and edit this code block:
define('_PS_MODE_DEV_', false);
to:
define('_PS_MODE_DEV_', true);
More information in the development section of PrestaShop's documentation.
PrestaSharp is GNU General Public License (GPL)
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantabilty or fitness for a particular purpose. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Bukimedia reserves the right to mention of companies or individuals who use this software.
Copyright (C) 2019 Bukimedia