Nandos Posted May 25, 2016 Share Posted May 25, 2016 (edited) Hello everyone, i'm new here We're checking PS features to decide if this will be part of our new ecommerce, and so far it looks very nice and complete, but we need an important functionality we didn't find in the back office . Let me explain better. Periodically, we send the details of our orders to a research institute for data mining. They analyze those info and we receive a service from them in terms of market and business decisions and so on... Anyway, we need to send them weekly only the quantities of orders (how many orders we do in a week) and the associated products codes into the orders. So far we only find an export for numbers of orders, not complete. Is there a way to make a customizable exporting of orders? Some coding involved? If i have to install a module for that, link it to me please, since i didn't find what i need. Thanks in advance Edited June 17, 2016 by Nandos (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted May 25, 2016 Share Posted May 25, 2016 I think you can write specific SQL statement to run on your store to get what ever results you want. Link to comment Share on other sites More sharing options...
Nandos Posted May 26, 2016 Author Share Posted May 26, 2016 (edited) I think you can write specific SQL statement to run on your store to get what ever results you want. Can you help me with that? Since i'm new with PS, i still don't know where it stores these kind of data, in which fields and in which tables etc... This "hypothetical" query should generate results for how many orders we had in a week and the associated products codes (description and EAN) in each order. For example, a table with these fields: columns line product order data | product code | EAN | product name | quantity | price no vat for single product | price no vat for multiple of that product if more are present *| total order price with vat 26/05/2016 xxxxx xxx item xxx yyy zz,zz€ zz,zz€ zz,zz€ 26/05/2016 xxxxx xxx item xxx yyy zz,zz€ zz,zz€ zz,zz€ ... *if 1, show the same price as single product Then i want to export it in a csv file. It would be great an help Thanks in advance! Edited May 26, 2016 by Nandos (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted May 27, 2016 Share Posted May 27, 2016 I am sorry, this is not easy to explain and write the SQL in a few minutes. detailed requirements of the CSV export needs to be discusses. I guess you you will need to hire someone to help with that if you are not able to coding by yourself. Link to comment Share on other sites More sharing options...
Nandos Posted June 14, 2016 Author Share Posted June 14, 2016 I wrote a kind of solution, using the integrated sql manager into the back office: http://pastebin.com/NFNgMP2G (the date window is just an example) Link to comment Share on other sites More sharing options...
shokinro Posted June 14, 2016 Share Posted June 14, 2016 it looks like a very good solution.congratulations! for the date, you can use CURDATE() and DATEDIFF() to calculate. 1 Link to comment Share on other sites More sharing options...
Nandos Posted June 14, 2016 Author Share Posted June 14, 2016 it looks like a very good solution.congratulations! for the date, you can use CURDATE() and DATEDIFF() to calculate. Thanks Ah ok, i will look at them. In the meanwhile, can you explain me how do they work exactly? Just an example if you can Link to comment Share on other sites More sharing options...
shokinro Posted June 14, 2016 Share Posted June 14, 2016 CURDATE() will get current date time. you can find more info here http://www.w3schools.com/sql/func_curdate.asp You can use DATE_ADD() to get future data of past data of specified data. http://www.w3schools.com/sql/func_date_add.asp 1 Link to comment Share on other sites More sharing options...
Nandos Posted June 14, 2016 Author Share Posted June 14, 2016 CURDATE() will get current date time. you can find more info here http://www.w3schools.com/sql/func_curdate.asp You can use DATE_ADD() to get future data of past data of specified data. http://www.w3schools.com/sql/func_date_add.asp Thank you, very appreciated Link to comment Share on other sites More sharing options...
shokinro Posted June 14, 2016 Share Posted June 14, 2016 you are welcome, hope that helped Link to comment Share on other sites More sharing options...
danplant Posted February 25, 2017 Share Posted February 25, 2017 Hi guys, i'm very interested this functionality ! How integrate this in the BO ? P.S. 1.6.1.7 Link to comment Share on other sites More sharing options...
Nandos Posted February 25, 2017 Author Share Posted February 25, 2017 (edited) Hi guys, i'm very interested this functionality ! How integrate this in the BO ? P.S. 1.6.1.7 Ok, so login into your BO, go to the Advanced Parameters menu, and from there click on "SQL Manager". Into SQL Manager, add a new SQL Query with the button on the top, give it a title and paste there the code i linked before in this thread. Then save it and in the list you will have a new voice (if no queries, you will have just one ID=1), click on it and you will get the result directly into the BO. If you want to export the results, from the list click on the "Export" button and the browser will download a .csv file with the data. Hope it helps. Cya o/ Edited April 21, 2017 by Nandos (see edit history) 1 Link to comment Share on other sites More sharing options...
danplant Posted February 25, 2017 Share Posted February 25, 2017 Sounds good !!!! Very thanks, very helpful ! Regards 1 Link to comment Share on other sites More sharing options...
Surffari Posted January 11, 2021 Share Posted January 11, 2021 Thanks @Nandos Just the droids ... I mean the SQL I was looking for! Few modifications to get what I need (works with 1.7) Link to comment Share on other sites More sharing options...
anth55 Posted February 27, 2021 Share Posted February 27, 2021 On 1/11/2021 at 6:52 PM, Surffari said: Thanks @Nandos Just the droids ... I mean the SQL I was looking for! Few modifications to get what I need (works with 1.7) Hi, would you please let me know how did you modified the SQL statement so it works in prestashop 1.7 ? Best regards! Link to comment Share on other sites More sharing options...
GoPure Kratom Posted February 28, 2021 Share Posted February 28, 2021 On 2/27/2021 at 7:30 PM, anth55 said: Hi, would you please let me know how did you modified the SQL statement so it works in prestashop 1.7 ? Best regards! Here's SQL script I made to export in a format I needed for a particular purpose. You can modify the WHERE clause and the output fields according to your needs. SELECT o.id_order AS WebshopOrderId, ad.firstname "ShippingFirstName", "" AS "ShippingMiddleName", ad.LastName "ShippingLastName", ad.address1 AS "ShippingStreet", ad.address2 AS "ShippinghouseNo", "" AS "ShippingHouseNoAddition", ad.postcode "ShippingPostalCode", ad.city "ShippingCity", "" AS "ShippingState", cn.iso_code AS "ShippingCountry", g.email AS "ShippingEmail", ad.phone AS "ShippingPhone", "" AS "ShippingComment", "0" AS "B2B", d.product_reference AS "ArticleSKU", d.product_quantity AS "OrderedQty", o.reference AS "Reference", "" AS "Comment", "" AS "ShipmentDate", "" AS "ShipperCode", "" AS "ShipperRef", "0" AS "IsQuarantaineOrder", "" AS "InvoiceCompany", "" AS "InvoiceFirstName", "" AS "InvoiceMiddleName", "" AS "InvoiceLastName", "" AS "InvoiceStreet", "" AS "InvoicehouseNo", "" AS "InvoiceHouseNoAddition", "" AS "InvoicePostalCode", "" AS "InvoiceCity", "" AS "InvoiceState", "" AS "InvoiceCountry", "" AS "InvoiceEmail", "" AS "InvoicePhone", "" AS "InvoiceDebtorNumber", "" AS "InvoiceComment", "" AS "ShippingCompany" FROM pscw_order_detail d LEFT JOIN pscw_orders o ON (d.id_order = o.id_order) LEFT JOIN pscw_address ad ON (o.id_address_delivery = ad.id_address) LEFT JOIN pscw_address ai ON (o.id_address_invoice = ai.id_address) LEFT JOIN pscw_country cn ON (ad.id_country = cn.id_country) LEFT JOIN pscw_stock_available s ON (d.product_id = s.id_product) LEFT JOIN pscw_customer g ON (o.id_customer = g.id_customer) LEFT JOIN pscw_group_lang gl ON (g.id_default_group = gl.id_group) LEFT JOIN pscw_order_state_lang os ON (o.current_state = os.id_order_state) WHERE 1 GROUP BY o.reference, d.product_reference ORDER BY d.id_order DESC 1 Link to comment Share on other sites More sharing options...
DoGGoD Posted April 14, 2021 Share Posted April 14, 2021 (edited) Hi, The original code kind of works. I have this issue that it does not give me the orders, where the customer has not made the payment yet. How can I modify the code so it gives me those orders as well, where the payment (invoice) is not yet made? Thanks! Edit: I removed the d.delivery_date, c.date_add and INNER JOIN ps_order_invoice AS c ON c.id_order = b.id_order so it gives me all the sold products, even when there is no payment involved. SELECT a.id_order, a.date_add, c.delivery_date, c.date_add, b.product_reference, b.product_name, b.product_quantity, b.product_price, a.total_products_wt, a.total_paid FROM ps_orders AS a INNER JOIN ps_order_detail AS b ON b.id_order = a.id_order INNER JOIN ps_order_invoice AS c ON c.id_order = b.id_order WHERE a.date_add BETWEEN "2016-05-31 08:30:00" AND "2016-06-11 18:30:00" Edited April 14, 2021 by DoGGoD (see edit history) Link to comment Share on other sites More sharing options...
GoPure Kratom Posted April 14, 2021 Share Posted April 14, 2021 17 minutes ago, DoGGoD said: Hi, The original code kind of works. I have this issue that it does not give me the orders, where the customer has not made the payment yet. How can I modify the code so it gives me those orders as well, where the payment (invoice) is not yet made? Thanks! Edit: I removed the d.delivery_date, c.date_add and INNER JOIN ps_order_invoice AS c ON c.id_order = b.id_order so it gives me all the sold products, even when there is no payment involved. SELECT a.id_order, a.date_add, c.delivery_date, c.date_add, b.product_reference, b.product_name, b.product_quantity, b.product_price, a.total_products_wt, a.total_paid FROM ps_orders AS a INNER JOIN ps_order_detail AS b ON b.id_order = a.id_order INNER JOIN ps_order_invoice AS c ON c.id_order = b.id_order WHERE a.date_add BETWEEN "2016-05-31 08:30:00" AND "2016-06-11 18:30:00" It's been a while since I did some SQL, but I think when you include hte ps_order_invoice, the not paid orders are not included since they don't have an invoice yet. Maybe check LEFT JOIN to join the tables in an order that includes also the ones without an invoice Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now