0% found this document useful (0 votes)
106 views

Prestashop - APIs

The document contains 5 sections that provide API responses from a Prestashop site: 1) Provides product names from a specific category 2) Lists product IDs 3) Provides product details for a specific product 4) Provides order details for a specific order 5) Details a POST request to the Prestashop admin site

Uploaded by

perlmohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

Prestashop - APIs

The document contains 5 sections that provide API responses from a Prestashop site: 1) Provides product names from a specific category 2) Lists product IDs 3) Provides product details for a specific product 4) Provides order details for a specific order 5) Details a POST request to the Prestashop admin site

Uploaded by

perlmohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

1.

)
http://127.0.0.1/prestashop/api/products/?display=[name]&output_format=JSON&filter[id_category_d
efault]=9

"products": [

"name": "The best is yet to come' Framed poster"

},

"name": "The adventure begins Framed poster"

},

"name": "Today is a good day Framed poster"

},

"name": "Mountain fox - Vector graphics"

},

"name": "Brown bear - Vector graphics"

},

"name": "Hummingbird - Vector graphics"

2.) http://127.0.0.1/prestashop/api/products/?output_format=JSON

// 20200414131347
// http://127.0.0.1/prestashop/api/products/?output_format=JSON

"products": [

"id": 1

},

"id": 2

},

"id": 16

},

"id": 17

},

"id": 18

},

"id": 6

},

"id": 7

},

"id": 8

},

{
"id": 9

},

"id": 10

},

"id": 11

},

"id": 15

},

"id": 19

},

"id": 3

},

"id": 4

},

"id": 5

},

"id": 12

},

"id": 13

},
{

"id": 14

3.) http://127.0.0.1/prestashop/api/products/1?output_format=JSON

"product": {

"id": 1,

"id_manufacturer": "1",

"id_supplier": "0",

"id_category_default": "4",

"new": null,

"cache_default_attribute": "1",

"id_default_image": "1",

"id_default_combination": "1",

"id_tax_rules_group": "1",

"position_in_category": "1",

"manufacturer_name": "Studio Design",

"quantity": "0",

"type": "simple",

"id_shop_default": "1",

"reference": "demo_1",

"supplier_reference": "",

"location": "",

"width": "0.000000",

"height": "0.000000",
"depth": "0.000000",

"weight": "0.000000",

"quantity_discount": "0",

"ean13": "",

"isbn": "",

"upc": "",

"cache_is_pack": "0",

"cache_has_attachments": "0",

"is_virtual": "0",

"state": "1",

"additional_delivery_times": "1",

"delivery_in_stock": "",

"delivery_out_stock": "",

"on_sale": "0",

"online_only": "0",

"ecotax": "0.000000",

"minimal_quantity": "1",

"low_stock_threshold": null,

"low_stock_alert": "0",

"price": "23.900000",

"wholesale_price": "0.000000",

"unity": "",

"unit_price_ratio": "0.000000",

"additional_shipping_cost": "0.00",

"customizable": "0",

"text_fields": "0",

"uploadable_files": "0",

"active": "1",

"redirect_type": "301-category",
"id_type_redirected": "0",

"available_for_order": "1",

"available_date": "0000-00-00",

"show_condition": "0",

"condition": "new",

"show_price": "1",

"indexed": "1",

"visibility": "both",

"advanced_stock_management": "0",

"date_add": "2020-03-20 07:42:58",

"date_upd": "2020-03-20 07:42:58",

"pack_stock_type": "3",

"meta_description": "",

"meta_keywords": "",

"meta_title": "",

"link_rewrite": "hummingbird-printed-t-shirt",

"name": "Hummingbird printed t-shirt",

"description": "<p><span style=\"font-size:10pt;font-style:normal;\"><span style=\"font-


size:10pt;font-style:normal;\">Symbol of lightness and delicacy, the hummingbird evokes curiosity and
joy.</span><span style=\"font-size:10pt;font-style:normal;\"> Studio Design' PolyFaune collection
features classic products with colorful patterns, inspired by the traditional japanese origamis. To wear
with a chino or jeans. The sublimation textile printing process provides an exceptional color rendering
and a color, guaranteed overtime.</span></span></p>",

"description_short": "<p><span style=\"font-size:10pt;font-style:normal;\">Regular fit, round


neckline, short sleeves. Made of extra long staple pima cotton. </span></p>\r\n<p></p>",

"available_now": "",

"available_later": "",

"associations": {

"categories": [

"id": "2"
},

"id": "3"

},

"id": "4"

],

"images": [

"id": "1"

},

"id": "2"

],

"combinations": [

"id": "1"

},

"id": "2"

},

"id": "3"

},

"id": "4"

},
{

"id": "5"

},

"id": "6"

},

"id": "7"

},

"id": "8"

],

"product_option_values": [

"id": "1"

},

"id": "11"

},

"id": "2"

},

"id": "8"

},

"id": "3"

},
{

"id": "4"

],

"product_features": [

"id": "1",

"id_feature_value": "4"

},

"id": "2",

"id_feature_value": "8"

],

"stock_availables": [

"id": "1",

"id_product_attribute": "0"

},

"id": "20",

"id_product_attribute": "1"

},

"id": "21",

"id_product_attribute": "2"

},

"id": "22",
"id_product_attribute": "3"

},

"id": "23",

"id_product_attribute": "4"

},

"id": "24",

"id_product_attribute": "5"

},

"id": "25",

"id_product_attribute": "6"

},

"id": "26",

"id_product_attribute": "7"

},

"id": "27",

"id_product_attribute": "8"

}
4.) http://127.0.0.1/prestashop/api/orders/1?output_format=JSON

"order": {

"id": 1,

"id_address_delivery": "5",

"id_address_invoice": "5",

"id_cart": "1",

"id_currency": "1",

"id_lang": "1",

"id_customer": "2",

"id_carrier": "2",

"current_state": "6",

"module": "ps_checkpayment",

"invoice_number": "0",

"invoice_date": "0000-00-00 00:00:00",

"delivery_number": "0",

"delivery_date": "0000-00-00 00:00:00",

"valid": "0",

"date_add": "2020-03-20 07:42:58",

"date_upd": "2020-03-20 07:42:58",

"shipping_number": "",

"id_shop_group": "1",

"id_shop": "1",

"secure_key": "b44a6d9efd7a0076a0fbce6b15eaf3b1",

"payment": "Payment by check",

"recyclable": "0",

"gift": "0",
"gift_message": "",

"mobile_theme": "0",

"total_discounts": "0.000000",

"total_discounts_tax_incl": "0.000000",

"total_discounts_tax_excl": "0.000000",

"total_paid": "61.800000",

"total_paid_tax_incl": "61.800000",

"total_paid_tax_excl": "61.800000",

"total_paid_real": "0.000000",

"total_products": "59.800000",

"total_products_wt": "59.800000",

"total_shipping": "2.000000",

"total_shipping_tax_incl": "2.000000",

"total_shipping_tax_excl": "2.000000",

"carrier_tax_rate": "0.000",

"total_wrapping": "0.000000",

"total_wrapping_tax_incl": "0.000000",

"total_wrapping_tax_excl": "0.000000",

"round_mode": "0",

"round_type": "0",

"conversion_rate": "1.000000",

"reference": "XKBKNABJK",

"associations": {

"order_rows": [

"id": "1",

"product_id": "1",

"product_attribute_id": "1",

"product_quantity": "1",
"product_name": "Hummingbird printed t-shirt - Color : White, Size : S",

"product_reference": "demo_2",

"product_ean13": "",

"product_isbn": "",

"product_upc": "",

"product_price": "23.900000",

"id_customization": "0",

"unit_price_tax_incl": "23.900000",

"unit_price_tax_excl": "23.900000"

},

"id": "2",

"product_id": "2",

"product_attribute_id": "9",

"product_quantity": "1",

"product_name": "Hummingbird printed sweater - Color : White, Size : S",

"product_reference": "demo_3",

"product_ean13": "",

"product_isbn": "",

"product_upc": "",

"product_price": "35.900000",

"id_customization": "0",

"unit_price_tax_incl": "35.900000",

"unit_price_tax_excl": "35.900000"

}
5.) curl --location --request POST
'http://127.0.0.1/prestashop/admin602gqubdt/index.php?controller=AdminOrders&token=4fc250576d
6d6f0ff9ed89abe02a315e' \

--header 'Connection: keep-alive' \

--header 'Accept: application/json, text/javascript, */*; q=0.01' \

--header 'Sec-Fetch-Dest: empty' \

--header 'X-Requested-With: XMLHttpRequest' \

--header 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/80.0.3987.149 Safari/537.36' \

--header 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \

--header 'Origin: http://127.0.0.1' \

--header 'Sec-Fetch-Site: same-origin' \

--header 'Sec-Fetch-Mode: cors' \

--header 'Referer:
http://127.0.0.1/prestashop/admin602gqubdt/index.php?controller=AdminOrders&vieworder=&id_ord
er=5&token=4fc250576d6d6f0ff9ed89abe02a315e' \

--header 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \

--header 'Cookie: PrestaShop-


0b9c3f304c6c2d08e8f8247b88b2790b=def502006cdfb20ab4c9b64ed42f4d9579ba2b95a95847860f6d5
022e5278a0567127e97db999b637c49f69bd7c4fedcd5164f9bc18889dd4c9517b5c6d9d79b505fb272c47
0b51fd1d3d69963b33d84e871538128c92b674df362eafdd7aa78a06ec60f823a00277b0cd27d3b5f2d737
8d824a8600ba6e4f09dd0748ff376e106d5eed4f7a3f2326da5117042cd62e561dd05969b348606867ca8e
a16add5f09b420e7310bda91b5d073fc210dc7bd5801ad530427d9495424ca621fb6634dfbcb1a6381755
7da09901264cc1a9593c62427fe7714240b5a64b9f1ef649eabcfd39a476b6ad236aa6f2b94f3922dcc1492
8e719aa2aafa92727808fbebda768fef6a5aa8c052df9428b6e3da6eebae610a5fe1fda69a0409f3d5b983e
56f1d3482e5fa15eae2e3657429d9f00d67fd1ac65ae067c7b6c98e9f85f329b25cf4b934c5ea36f38ab700c
27b760bf406a4fd78c7344c97341224a2b2b9354728a8c02808c2bf4911d599e487e0adcfecca8fee94644b
5630c243e82bc7c7d59053b2d21e3f358c409b587f545726c31ed15f5; PrestaShop-
adea1e3af1920604564688b926a158c5=def5020075d5e9bdeb63e056ea35b139c81624600c375e8b54ee
3550a5f3449a0d6223bcc367961f0f0ab224fdc5a662fb94eecf2a45da5804a59103c9165b8fdbe60eee008
9ef8f8a6ad524bd21875f5bcd80624c8ca5ca547d0c0b1a44133d5b99c52ef71ff06af3c4ee4f1b9a84ca302
fc2c5a13102c33bba343ff7411621cca1de67fcc22b74b68eb421c5784cc1ab74c3667b14f7bf25b97920cb6
258820013f9e5b831a4dd0b9ed28eb5401818ca4dce1cd8611d5942c879df1a0292ec1217e09ec42a5bbe
19a2eb501f190dfef4ea14535320ef94237144fbc1301d5a95cd4511e3e696c61d92e076b8914729a1851b
a2297a7b3c387e5d3da712ea87dd8c0f15b4e6749807f392559a4ffb0d15bf67cf12a6182f9bfc798bdb0ea
0612d7421c7b6f486c11df3bc34cb461261a54fb9f8749fec7d3e1d85f87bde4346557fac21b36160d78d5d
c7247a53e435c09e733ac9f6c151c73da06ac01b66c1; PHPSESSID=a9oehu596jnu5mjun9mgt9m52s' \

--data-raw
'ajax=1&token=4fc250576d6d6f0ff9ed89abe02a315e&action=editProductOnOrder&id_order=5&produc
t_id_order_detail=7&product_price_tax_excl=18.9&product_price_tax_incl=18.9&product_quantity=26'

File - /var/www/html/prestashop/controllers/admin/AdminOrdersController.php

public function ajaxProcessEditProductOnOrder()

// Return value

$res = true;

$order = new Order((int) Tools::getValue('id_order'));

$order_detail = new OrderDetail((int) Tools::getValue('product_id_order_detail'));

if (Tools::isSubmit('product_invoice')) {

$order_invoice = new OrderInvoice((int) Tools::getValue('product_invoice'));

// Check fields validity

$this->doEditProductValidation($order_detail, $order, isset($order_invoice) ? $order_invoice :


null);

// If multiple product_quantity, the order details concern a product customized

$product_quantity = 0;

if (is_array(Tools::getValue('product_quantity'))) {

foreach (Tools::getValue('product_quantity') as $id_customization => $qty) {

// Update quantity of each customization

Db::getInstance()->update('customization', array('quantity' => (int) $qty), 'id_customization = ' .


(int) $id_customization);

// Calculate the real quantity of the product


$product_quantity += $qty;

} else {

$product_quantity = Tools::getValue('product_quantity');

$product_price_tax_incl = Tools::ps_round(Tools::getValue('product_price_tax_incl'), 2);

$product_price_tax_excl = Tools::ps_round(Tools::getValue('product_price_tax_excl'), 2);

$total_products_tax_incl = $product_price_tax_incl * $product_quantity;

$total_products_tax_excl = $product_price_tax_excl * $product_quantity;

// Calculate differences of price (Before / After)

$diff_price_tax_incl = $total_products_tax_incl - $order_detail->total_price_tax_incl;

$diff_price_tax_excl = $total_products_tax_excl - $order_detail->total_price_tax_excl;

// Apply change on OrderInvoice

if (isset($order_invoice)) {

// If OrderInvoice to use is different, we update the old invoice and new invoice

if ($order_detail->id_order_invoice != $order_invoice->id) {

$old_order_invoice = new OrderInvoice($order_detail->id_order_invoice);

// We remove cost of products

$old_order_invoice->total_products -= $order_detail->total_price_tax_excl;

$old_order_invoice->total_products_wt -= $order_detail->total_price_tax_incl;

$old_order_invoice->total_paid_tax_excl -= $order_detail->total_price_tax_excl;

$old_order_invoice->total_paid_tax_incl -= $order_detail->total_price_tax_incl;

$res &= $old_order_invoice->update();


$order_invoice->total_products += $order_detail->total_price_tax_excl;

$order_invoice->total_products_wt += $order_detail->total_price_tax_incl;

$order_invoice->total_paid_tax_excl += $order_detail->total_price_tax_excl;

$order_invoice->total_paid_tax_incl += $order_detail->total_price_tax_incl;

$order_detail->id_order_invoice = $order_invoice->id;

if ($diff_price_tax_incl != 0 && $diff_price_tax_excl != 0) {

$order_detail->unit_price_tax_excl = $product_price_tax_excl;

$order_detail->unit_price_tax_incl = $product_price_tax_incl;

$order_detail->total_price_tax_incl += $diff_price_tax_incl;

$order_detail->total_price_tax_excl += $diff_price_tax_excl;

if (isset($order_invoice)) {

// Apply changes on OrderInvoice

$order_invoice->total_products += $diff_price_tax_excl;

$order_invoice->total_products_wt += $diff_price_tax_incl;

$order_invoice->total_paid_tax_excl += $diff_price_tax_excl;

$order_invoice->total_paid_tax_incl += $diff_price_tax_incl;

// Apply changes on Order

$order = new Order($order_detail->id_order);

$order->total_products += $diff_price_tax_excl;
$order->total_products_wt += $diff_price_tax_incl;

$order->total_paid += $diff_price_tax_incl;

$order->total_paid_tax_excl += $diff_price_tax_excl;

$order->total_paid_tax_incl += $diff_price_tax_incl;

$res &= $order->update();

$old_quantity = $order_detail->product_quantity;

$order_detail->product_quantity = $product_quantity;

$order_detail->reduction_percent = 0;

// update taxes

$res &= $order_detail->updateTaxAmount($order);

// Save order detail

$res &= $order_detail->update();

// Update weight SUM

$order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier());

if (Validate::isLoadedObject($order_carrier)) {

$order_carrier->weight = (float) $order->getTotalWeight();

$res &= $order_carrier->update();

if ($res) {

$order->weight = sprintf('%.3f ' . Configuration::get('PS_WEIGHT_UNIT'), $order_carrier-


>weight);

}
}

// Save order invoice

if (isset($order_invoice)) {

$res &= $order_invoice->update();

// Update product available quantity

StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id,
($old_quantity - $order_detail->product_quantity), $order->id_shop);

$products = $this->getProducts($order);

// Get the last product

$product = $products[$order_detail->id];

$resume = OrderSlip::getProductSlipResume($order_detail->id);

$product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity'];

$product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl'];

$product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl']);

$product['refund_history'] = OrderSlip::getProductSlipDetail($order_detail->id);

if ($product['id_warehouse'] != 0) {

$warehouse = new Warehouse((int) $product['id_warehouse']);

$product['warehouse_name'] = $warehouse->name;

$warehouse_location = WarehouseProductLocation::getProductLocation($product['product_id'],
$product['product_attribute_id'], $product['id_warehouse']);

if (!empty($warehouse_location)) {

$product['warehouse_location'] = $warehouse_location;

} else {

$product['warehouse_location'] = false;

}
} else {

$product['warehouse_name'] = '--';

$product['warehouse_location'] = false;

// Get invoices collection

$invoice_collection = $order->getInvoicesCollection();

$invoice_array = array();

foreach ($invoice_collection as $invoice) {

/* @var OrderInvoice $invoice */

$invoice->name = $invoice->getInvoiceNumberFormatted(Context::getContext()->language->id,
(int) $order->id_shop);

$invoice_array[] = $invoice;

$order = $order->refreshShippingCost();

$stockLocationIsAvailable = false;

foreach ($products as $currentProduct) {

if (!empty($currentProduct['location'])) {

$stockLocationIsAvailable = true;

break;

// Assign to smarty informations in order to show the new product line

$this->context->smarty->assign(array(
'product' => $product,

'order' => $order,

'currency' => new Currency($order->id_currency),

'can_edit' => $this->access('edit'),

'invoices_collection' => $invoice_collection,

'current_id_lang' => Context::getContext()->language->id,

'link' => Context::getContext()->link,

'current_index' => self::$currentIndex,

'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'),

'stock_location_is_available' => $stockLocationIsAvailable,

));

if (!$res) {

die(json_encode(array(

'result' => $res,

'error' => $this->trans('An error occurred while editing the product line.', array(),
'Admin.Orderscustomers.Notification'),

)));

if (is_array(Tools::getValue('product_quantity'))) {

$view = $this->createTemplate('_customized_data.tpl')->fetch();

} else {

$view = $this->createTemplate('_product_line.tpl')->fetch();

$this->sendChangedNotification($order);

die(json_encode(array(
'result' => $res,

'view' => $view,

'can_edit' => $this->access('add'),

'invoices_collection' => $invoice_collection,

'order' => $order,

'invoices' => $invoice_array,

'documents_html' => $this->createTemplate('_documents.tpl')->fetch(),

'shipping_html' => $this->createTemplate('_shipping.tpl')->fetch(),

'customized_product' => is_array(Tools::getValue('product_quantity')),

)));

6.) http://127.0.0.1/prestashop/api/stock_availables/19?output_format=JSON

7.)http://127.0.0.1/prestashop/api/products/?output_format=JSON&filter[id_category_default]=9

8.) http://127.0.0.1/prestashop/api/products/19?output_format=JSON

9.) http://127.0.0.1/prestashop/api/orders/1?output_format=JSON

You might also like