[Prestashop] How to Debug Prestashop API?
There are severals ways to make it right. Below I described my way of testing Prestashop API using cURL as the tool that checkes all dependencies. After enabling Prestashop API in your administration panel, save the API Key.
Depends what you want to check your xml files would be different. All possibilites you can find in the Prestashop API documentation, for instance: http://doc.prestashop.com/display/PS14/Chapter+4+-+Retrieve+Data+-+Retrieving+a+Client. Most important thing here is the XML file.
In our example we will add a new product to the Prestashop API. Here is ours XML file with data.
product.xml
1 2 3 4 5 6 7 8 9 10 11 |
<prestashop> <product> <price>123.00</price> <link_rewrite> <language id="1"><![CDATA[test-123]]></language> </link_rewrite> <name> <language id="1"><![CDATA[Test 123]]></language> </name> </product> </prestashop> |
Save it and execute command below.
1 |
curl -X POST -u 'YOUR_PRESTASHOP_API_KEY:' -d @product.xml 'http://YOUR_WEBSITE_URL/api/products' -v |
Pretashop has RESTful API so it depends on the http methods that you would be able to add / edit or remove products.
[Prestashop] Adding Product Thumbnail to the Order Email
Find and open PaymentModule (directory classes).
There will be line similar to this (line 381).
1 2 3 4 |
$products_list .= '<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';"> <td style="padding: 0.6em 0.4em;width: 15%;">'.$product['reference'].'</td> <td style="padding: 0.6em 0.4em;width: 30%;"><strong>'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').' - |
We are adding the new cell to this table by getting product image from the database. Below you will the code.
1 2 3 4 5 6 |
$img = $this->context->link->getImageLink($product['link_rewrite'], $product['id_image'], 'pos_product'); $products_list .= '<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';"> <td style="padding: 0.6em 0.4em;width: 15%;"><img style="width: 100px" src="' . $img .'" /></td> <td style="padding: 0.6em 0.4em;width: 15%;">'.$product['reference'].'</td> <td style="padding: 0.6em 0.4em;width: 30%;"><strong>'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').' - |
How to Change the Original Price in Prestashop
That’s a really useful snipet for anybody who wants to change the original price to the new one.
Solution for this is very easy …
Ok .. here it is:
Product.php, line 1686
1 2 3 4 5 6 |
public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = NULL, $decimals = 6, $divisor = NULL, $only_reduc = false, $usereduc = true, $quantity = 1, $forceAssociatedTax = false, $id_customer = NULL, $id_cart = NULL, $id_address = NULL, &$specificPriceOutput = NULL, $with_ecotax = TRUE) { // .... find some space before `return` $my_new_price = Warehouse::getPriceByDay(); return $my_new_price; |
How to Add a New Custom Field in Prestashop
I’ve figured out how to add new field to database using Prestashop (1.4.3, but I think for the newer versions would be the same). This solution gives you new field in database and you will be able to edit / save data to this field in your admin panel, for my example I needed a field which was called “number of photos”. Below you can see how it works.
Read the full article »