Sales report CSV template

Theme and Plugin Support

Sales report CSV template Resolved

Viewing 10 reply threads
  • Author
    Posts
    • #103885
      victorjpr8
      Participant

      Regards

      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:
    • #103934
      abhirup
      Moderator

      Hi @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.

    • #103975
      victorjpr8
      Participant

      Hi @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:
    • #103983
      victorjpr8
      Participant

      I 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
    • #103984
      victorjpr8
      Participant

      I had forgotten to leave a screenshot of the result …..

      Attachments:
    • #104042
      abhirup
      Moderator

      Hi,
      sorry but this is a function you can not hook it, so use hook and filter for your modification.

    • #104052
      victorjpr8
      Participant

      Hi!

      Well how could I do that? or where can I start? I would greatly appreciate the possible help.

    • #104131
      WCMp Support
      Keymaster

      Hi,

      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.

    • #104233
      victorjpr8
      Participant

      Hi @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.

    • #104272
      abhirup
      Moderator

      Hi,
      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 header

      wcmp_vendor_order_generate_csv_headers
      Copy

      and for row use this filter

      apply_filters('wcmp_vendor_order_generate_csv_data', $data, $customer_order, $vendor);
      Copy
    • #110069

      We 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.

Viewing 10 reply threads

The topic ‘Sales report CSV template’ is closed to new replies.

Buy all Marketplace addons together, check out our Bundle

Buy at Slashed Price