Sales report CSV template
Home / Topic / Theme and Plugin Support / Sales report CSV template
Theme and Plugin Support
Sales report CSV template Resolved
- This topic has 10 replies, 4 voices, and was last updated 2 months, 1 week ago by
WCMp Support Ninja.
-
AuthorPosts
-
-
August 23, 2020 at 12:53 PM #103885
victorjpr8
ParticipantRegards
When exporting the sales made, I notice that the .csv format is little understandable or difficult to read, for a programmer it is easier to understand, but for a common user or with reading difficulties it is very difficult to read.
I think the solution would be to enable columns and rows in the template, I understand that it may lead to a code modification but could you help me how to do it or where to start? please and thank you very much.
Attachments:
-
August 24, 2020 at 7:40 AM #103934
abhirup
ModeratorHi @victorjpr8,
After hearing from you we have doubled check this on our end, as you can see all the details can be understood by any user. (check the attachment)
Can you please check again.
Here is the CSV scrrenshot : https://prnt.sc/u4y6xr
Make sure, to keep enable “,” as separator : https://prnt.sc/u4y76k
Can you please check again.Thank You.
-
August 24, 2020 at 4:51 PM #103975
victorjpr8
ParticipantHi @abhirup
Thanks for taking your time to reply,
I just saw the images you shared and I can see that in the second image you have a kind of configuration panel open to export something that is not shown to me, how can I see this?
Attachments:
-
August 24, 2020 at 9:25 PM #103983
victorjpr8
ParticipantI was able to solve the problem, with hours of research I could find the solution!
I will leave the code to help others, now I would like how I could add it in functions.php so that in future updates of the plugin I do not lose the changes.
public function generate_csv($customer_orders, $vendor, $args = array()) { global $WCMp; $order_datas = array(); $index = 0; $date = date('Y-m-d'); $default = array( 'filename' => 'SalesReport-' . $date . '.csv', 'iostream' => 'php://output', 'buffer' => 'w', 'action' => 'download', ); $args = wp_parse_args($args, $default); $filename = $args['filename']; if ($args['action'] == 'download') { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: text/plain"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Disposition: attachment;filename={$filename}"); header("Content-Transfer-Encoding: binary"); header("Content-Type: charset=UTF-8"); } $headers = apply_filters('wcmp_vendor_order_generate_csv_headers', array( 'order' => __('# Pedido', 'dc-woocommerce-multi-vendor'), ";", 'date_of_purchase' => __('Fecha de la compra', 'dc-woocommerce-multi-vendor'), ";", 'product' => __('Producto', 'dc-woocommerce-multi-vendor'), ";", 'qty' => __('Cantidad', 'dc-woocommerce-multi-vendor') , ";", 'order_total' => __('Total del la compra ($)' , 'dc-woocommerce-multi-vendor'), ";", 'buyer_name' => __('Nombre del cliente', 'dc-woocommerce-multi-vendor') . ";", 'buyer_email' => __('Correo del cliente', 'dc-woocommerce-multi-vendor') , ";", 'buyer_contact' => __('Número de teléfono', 'dc-woocommerce-multi-vendor') . ";", 'shipping_address' => __('Detálles de envío', 'dc-woocommerce-multi-vendor') , ";", 'order_status' => __('Order Status', 'dc-woocommerce-multi-vendor'), ";", )); if (!apply_filters('show_customer_details_in_export_orders', true, $vendor->id)) { unset($headers['buyer_name']); unset($headers['buyer_email']); unset($headers['buyer_contact']); } if (!apply_filters('show_customer_billing_address_in_export_orders', true, $vendor->id)) { unset($headers['billing_address']); } if (!apply_filters('show_customer_shipping_address_in_export_orders', true, $vendor->id)) { unset($headers['shipping_address']); } if ($vendor) { if (!empty($customer_orders)) { foreach ($customer_orders as $commission_id => $customer_order) { $order = wc_get_order($customer_order); $vendor_items = $vendor->get_vendor_items_from_order($customer_order, $vendor->term_id); $item_names = $item_qty = array(); if (sizeof($vendor_items) > 0) { foreach ($vendor_items as $item) { $item_names[] = $item['name']; $item_qty[] = $item['quantity']; } //coupons count $coupon_used = ''; $coupons = $order->get_items('coupon'); foreach ($coupons as $coupon_item_id => $item) { $coupon = new WC_Coupon(trim($item['name'])); $coupon_post = get_post($coupon->get_id()); $author_id = $coupon_post->post_author; if ($vendor->id == $author_id) { $coupon_used .= $item['name'] . ', '; } } // Formatted Addresses $formatted_billing_address = apply_filters('woocommerce_order_formatted_billing_address', array( 'address_1' => $order->get_billing_address_1(), 'address_2' => $order->get_billing_address_2(), 'city' => $order->get_billing_city(), 'state' => $order->get_billing_state(), 'postcode' => $order->get_billing_postcode(), 'country' => $order->get_billing_country() ), $order); $formatted_billing_address = WC()->countries->get_formatted_address($formatted_billing_address); $formatted_shipping_address = apply_filters('woocommerce_order_formatted_shipping_address', array( 'address_1' => $order->get_shipping_address_1(), 'address_2' => $order->get_shipping_address_2(), 'city' => $order->get_shipping_city(), 'state' => $order->get_shipping_state(), 'postcode' => $order->get_shipping_postcode(), 'country' => $order->get_shipping_country() ), $order); $formatted_shipping_address = WC()->countries->get_formatted_address($formatted_shipping_address); $customer_name = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(); $customer_email = $order->get_billing_email(); $customer_phone = $order->get_billing_phone(); $order_datas[$index] = apply_filters('wcmp_vendor_order_generate_csv_data', array( 'order' => '#' . $customer_order , ";", 'date_of_purchase' => date_i18n('Y-m-d', strtotime($order->get_date_created())) , ";", 'product' => implode($item_names) , ";", 'qty' => implode($item_qty) , ";", 'order_total' => '$' . $order->get_total() , ";", 'buyer_name' => $customer_name , ";", 'buyer_email' => $customer_email , ";", 'buyer_contact' => $customer_phone , ";", 'shipping_address' => str_replace('<br/>', ', ', $formatted_shipping_address) ,";", 'order_status' => $order->get_status(), ), $customer_order, $vendor); if (!apply_filters('show_customer_details_in_export_orders', true, $vendor->id)) { unset($order_datas[$index]['buyer_name']); unset($order_datas[$index]['buyer_email']); unset($order_datas[$index]['buyer_contact']); } if (!apply_filters('show_customer_billing_address_in_export_orders', true, $vendor->id)) { unset($order_datas[$index]['billing_address']); } if (!apply_filters('show_customer_shipping_address_in_export_orders', true, $vendor->id)) { unset($order_datas[$index]['shipping_address']); } $index++; } } } } // Initiate output buffer and open file ob_start(); if ($args['action'] == 'download' && $args['iostream'] == 'php://output') { $file = fopen($args['iostream'], $args['buffer']); } elseif ($args['action'] == 'temp' && $args['filename']) { $filename = sys_get_temp_dir() . '/' . $args['filename']; $file = fopen($filename, $args['buffer']); } // Add headers to file // fputcsv($file, $headers, ',',' '); fprintf($file, chr(0xEF).chr(0xBB).chr(0xBF)); fputcsv($file, $headers, ' ',' '); // Add data to file foreach ($order_datas as $order_data) { if (!$WCMp->vendor_caps->vendor_capabilities_settings('is_order_show_email') || apply_filters('is_not_show_email_field', true)) { unset($order_data['buyer']); } fprintf($file, chr(0xEF).chr(0xBB).chr(0xBF)); fputcsv($file, $order_data, ' ',' '); } // Close file and get data from output buffer fclose($file); $csv = ob_get_clean(); if ($args['action'] == 'temp') { return $filename; } else { // Send CSV to browser for download echo $csv; die(); } }
Copy -
August 24, 2020 at 9:27 PM #103984
victorjpr8
ParticipantI had forgotten to leave a screenshot of the result …..
Attachments:
-
August 25, 2020 at 9:25 AM #104042
abhirup
ModeratorHi,
sorry but this is a function you can not hook it, so use hook and filter for your modification. -
August 25, 2020 at 1:02 PM #104052
victorjpr8
ParticipantHi!
Well how could I do that? or where can I start? I would greatly appreciate the possible help.
-
August 26, 2020 at 8:02 PM #104131
WCMp Support
KeymasterHi,
As the above issue is specifically at your website, please share admin and vendor access of your staging website together with FTP. Don’t forget to mark the thread private while sharing the info of your stagng website.
-
August 27, 2020 at 4:24 PM #104233
victorjpr8
ParticipantHi @WCMpSupport
as I mentioned in my previous post, I was able to solve the problem under my investigation, now, there is a requirement that if it is possible to receive your help, it is how I can get product stock value so that a seller when downloading the sales report can know the Inventory.
How can I start doing this? I would appreciate the possible help.
-
August 28, 2020 at 8:28 AM #104272
abhirup
ModeratorHi,
For your requirement >> how I can get product stock value so that a seller when downloading the sales report can know the Inventory.
use this filter for csv headerwcmp_vendor_order_generate_csv_headers
Copyand for row use this filter
apply_filters('wcmp_vendor_order_generate_csv_data', $data, $customer_order, $vendor);
Copy -
November 18, 2020 at 5:30 PM #110069
WCMp Support Ninja
ModeratorWe have not received any update from you for a long. Hope this ticket is already been resolved.
We are now closing this ticket. Kindly create a new one if you need any further help.
-
-
AuthorPosts
The topic ‘Sales report CSV template’ is closed to new replies.