• Resolved domjespo

    (@domjespo)


    Hi, I would like to have an export that summarizes customer details and then pivots on the products that the users ordered by quantity. For example the below is a row with 2 products bacon and carrots as an example.

    First Name Last Name Email Bacon Carrots
    John Doe [email protected] 4 2
    Joe Doe [email protected] 3 4

    I’ve tried to use the “group by product” checkbox to get this result but it leaves the column name as “Quantity 1” “Quantity 2”, etc.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi

    Could you try this code https://algolplus.com/plugins/code-samples/#complex_reports_products_columns ?

    See notes at top of the page (how to use code).
    thanks, Alex

    Thread Starter domjespo

    (@domjespo)

    Thanks! What fields should I use for exported fields with this?

    Plugin Author algol.plus

    (@algolplus)

    use Qty

    Thread Starter domjespo

    (@domjespo)

    Hey @algolplus sorry I’m still having trouble with this. The columns are exporting as Qty#1, Qty #2 instead of the product names. Here’s some debugging:

    1) I have the code added in misc under Custom PHP code to modify output.
    2) I’m exporting the following fields : First Name, Last Name, Address, Adress, City, State, Postcode, Country Code, Country Name, Quantity

    Plugin Author algol.plus

    (@algolplus)

    hi

    Could you submit new ticket and upload settings as .txt file ?
    use tab “Tools” to get them.
    thanks, Alex

    Thread Starter domjespo

    (@domjespo)

    {
    “version”: “2.0”,
    “mode”: “cron”,
    “title”: “Route LIst”,
    “skip_empty_file”: “on”,
    “log_results”: “”,
    “from_status”: [],
    “to_status”: [],
    “change_order_status_to”: “”,
    “statuses”: [
    “wc-processing”
    ],
    “from_date”: “”,
    “to_date”: “”,
    “shipping_locations”: [],
    “shipping_methods”: [],
    “item_names”: [],
    “item_metadata”: [],
    “user_roles”: [],
    “user_names”: [],
    “user_custom_fields”: [],
    “billing_locations”: [],
    “payment_methods”: [],
    “any_coupon_used”: “0”,
    “coupons”: [],
    “order_custom_fields”: [],
    “product_categories”: [],
    “product_vendors”: [],
    “products”: [],
    “product_taxonomies”: [],
    “product_custom_fields”: [],
    “product_attributes”: [],
    “product_itemmeta”: [],
    “format”: “CSV”,
    “format_xls_use_xls_format”: “0”,
    “format_xls_sheet_name”: “Orders”,
    “format_xls_display_column_names”: “1”,
    “format_xls_auto_width”: “1”,
    “format_xls_direction_rtl”: “0”,
    “format_csv_enclosure”: “\””,
    “format_csv_delimiter”: “,”,
    “format_csv_linebreak”: “\\r\\n”,
    “format_csv_display_column_names”: “1”,
    “format_csv_add_utf8_bom”: “0”,
    “format_csv_item_rows_start_from_new_line”: “0”,
    “format_csv_encoding”: “UTF-8”,
    “format_csv_delete_linebreaks”: “0”,
    “format_tsv_linebreak”: “\\r\\n”,
    “format_tsv_display_column_names”: “1”,
    “format_tsv_add_utf8_bom”: “0”,
    “format_tsv_encoding”: “UTF-8”,
    “format_xml_root_tag”: “Orders”,
    “format_xml_order_tag”: “Order”,
    “format_xml_product_tag”: “Product”,
    “format_xml_coupon_tag”: “Coupon”,
    “format_xml_prepend_raw_xml”: “”,
    “format_xml_append_raw_xml”: “”,
    “format_xml_self_closing_tags”: “1”,
    “all_products_from_order”: “1”,
    “skip_refunded_items”: “1”,
    “skip_suborders”: “1”,
    “export_refunds”: “0”,
    “date_format”: “Y-m-d”,
    “time_format”: “H:i”,
    “sort_direction”: “DESC”,
    “sort”: “order_id”,
    “format_number_fields”: “0”,
    “export_all_comments”: “0”,
    “export_refund_notes”: “0”,
    “strip_tags_product_fields”: “0”,
    “cleanup_phone”: “0”,
    “enable_debug”: “1”,
    “format_json_start_tag”: “[“,
    “format_json_end_tag”: “]”,
    “custom_php”: “1”,
    “custom_php_code”: “\/\/ Export Products as columns\r\n\/\/ Format – XLS\r\n\/\/ Checked – Output column titles as first line\r\n\/\/ Button – Export w\/o Progressbar\r\nclass Woe_Product_Columns {\r\n function __construct() {\r\n \/\/add settings, , skip products \r\n add_action(\”woe_settings_above_buttons\”, array($this,\”draw_options\”) );\r\n add_filter(\”woe_settings_validate_defaults\”,array($this,\”skip_products\”),10,1);\r\n }\r\n\r\n \/\/ 1\r\n function draw_options($settings){\r\n $selected = !empty($settings[ \u0027products_as_columns\u0027 ]) ? \u0027checked\u0027: \u0027\u0027;\r\n echo \u0027<br><br>\r\n <input type=hidden name=\”settings[products_as_columns]\” value=\”0\”>\r\n <input type=checkbox name=\”settings[products_as_columns]\” value=\”1\” \u0027. $selected .\u0027>\r\n <span class=\”wc-oe-header\”>Export products as columns, print <select name=\”settings[products_as_columns_output_field]\” style=\”width: 100px\”>\r\n\t\t\t<option value=\”qty\”>Qty<\/option>\r\n\t\t\t<option value=\”line_total\”>Amount<\/option>\r\n <\/select>\r\n in cell<\/span><br>\r\n Format <b>XLS<\/b>, button <b>Export w\/o progressbar<\/b>\r\n <br><br>\u0027;\r\n }\r\n\r\n function skip_products($current_job_settings) {\r\n if( !empty($current_job_settings[\u0027products_as_columns\u0027]) ) {\r\n $current_job_settings[\”order_fields\”][\”products\”][\”checked\”] = 0;\/\/ just skip standard products\r\n $this->output_field = $current_job_settings[\u0027products_as_columns_output_field\u0027];\r\n \/\/ read orders\r\n add_action(\”woe_order_export_started\”,array($this,\”start_new_order\”),10,1);\r\n\r\n \/\/stop default output for rows\r\n add_action(\”woe_xls_header_filter\”,array($this,\”prepare_xls_vars\”),10,2);\r\n add_action(\”woe_xls_output_filter\”,array($this,\”record_xls_rows\”),10,2);\r\n add_action(\”woe_xls_print_footer\”,array($this,\”analyze_products_add_columns\”),10,2);\r\n }\r\n return $current_job_settings;\r\n } \r\n\r\n \/\/ 2\r\n function prepare_xls_vars($data) {\r\n\t$this->headers_added = count($data);\r\n $this->product_columns = array();\r\n return $data;\r\n }\r\n\r\n \/\/3\r\n function start_new_order($order_id) {\r\n $this->order_id = $order_id;\r\n return $order_id;\r\n }\r\n function record_xls_rows($data,$obj) {\r\n $order = new WC_Order($this->order_id);\r\n $extra_cells = array_fill(0, count($this->product_columns), \”\”);\r\n \/\/ work with products\r\n foreach($order->get_items(\u0027line_item\u0027) as $item_id=>$item) {\r\n $product_name = $item[\u0027name\u0027]; \r\n $pos = array_search($product_name,$this->product_columns);\r\n if( $pos === false) { \/\/ new product detected\r\n $extra_cells[] = $item[ $this->output_field ]; \r\n $this->product_columns[] = $product_name;\r\n } else {\r\n $extra_cells[$pos] = $item[ $this->output_field ]; \r\n }\r\n }\r\n foreach($extra_cells as $pc)\r\n $data[] = $pc;\r\n return $data;\r\n }\r\n\r\n \/\/4 \r\n function analyze_products_add_columns($phpExcel,$formatter) {\r\n \/\/ add products as titles\r\n foreach($this->product_columns as $pos=>$text)\r\n $formatter->objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( $pos+$this->headers_added, 1, $text );\r\n \/\/make first bold\r\n $last_column = $formatter->objPHPExcel->getActiveSheet()->getHighestDataColumn();\r\n $formatter->objPHPExcel->getActiveSheet()->getStyle( \”A1:\” . $last_column . \”1\” )->getFont()->setBold( true );\r\n }\r\n}\r\nnew Woe_Product_Columns();”,
    “mark_exported_orders”: “0”,
    “export_unmarked_orders”: “0”,
    “summary_report_by_products”: “0”,
    “duplicated_fields_settings”: {
    “products”: {
    “repeat”: “columns”,
    “populate_other_columns”: “1”,
    “max_cols”: “50”,
    “group_by”: “as_independent_columns”,
    “line_delimiter”: “\\n”
    },
    “coupons”: {
    “repeat”: “rows”,
    “max_cols”: “10”,
    “group_by”: “product”,
    “line_delimiter”: “\\n”
    }
    },
    “format_xls_populate_other_columns_product_rows”: “1”,
    “format_csv_populate_other_columns_product_rows”: “1”,
    “format_tsv_populate_other_columns_product_rows”: “1”,
    “export_rule_field”: “date”,
    “order_fields”: [
    {
    “segment”: “coupon”,
    “key”: “coupons”,
    “colname”: “Coupons”,
    “label”: “Coupons”,
    “format”: “string”
    },
    {
    “segment”: “shipping”,
    “key”: “shipping_first_name”,
    “label”: “First Name (Shipping)”,
    “format”: “string”,
    “colname”: “First Name (Shipping)”
    },
    {
    “segment”: “shipping”,
    “key”: “shipping_last_name”,
    “label”: “Last Name (Shipping)”,
    “format”: “string”,
    “colname”: “Last Name (Shipping)”
    },
    {
    “segment”: “shipping”,
    “key”: “shipping_address_1”,
    “label”: “Address 1 (Shipping)”,
    “format”: “string”,
    “colname”: “Address 1 (Shipping)”
    },
    {
    “segment”: “shipping”,
    “key”: “shipping_address_2”,
    “label”: “Address 2 (Shipping)”,
    “format”: “string”,
    “colname”: “Address 2 (Shipping)”
    },
    {
    “segment”: “shipping”,
    “key”: “shipping_city”,
    “label”: “City (Shipping)”,
    “format”: “string”,
    “colname”: “City (Shipping)”
    },
    {
    “segment”: “shipping”,
    “key”: “shipping_state”,
    “label”: “State Code (Shipping)”,
    “format”: “string”,
    “colname”: “State Code (Shipping)”
    },
    {
    “segment”: “shipping”,
    “key”: “shipping_postcode”,
    “label”: “Postcode (Shipping)”,
    “format”: “string”,
    “colname”: “Postcode (Shipping)”
    },
    {
    “segment”: “shipping”,
    “key”: “shipping_country”,
    “label”: “Country Code (Shipping)”,
    “format”: “string”,
    “colname”: “Country Code (Shipping)”
    },
    {
    “segment”: “shipping”,
    “key”: “shipping_country_full”,
    “label”: “Country Name (Shipping)”,
    “format”: “string”,
    “colname”: “Country Name (Shipping)”
    },
    {
    “segment”: “product”,
    “key”: “products”,
    “colname”: “Products”,
    “label”: “Products”,
    “format”: “string”
    },
    {
    “segment”: “products”,
    “key”: “plain_products_qty”,
    “label”: “Quantity”,
    “format”: “number”,
    “colname”: “Qty”
    }
    ],
    “order_product_fields”: [],
    “order_coupon_fields”: [],
    “id”: “2”,
    “schedule”: {
    “type”: “schedule-1”,
    “weekday”: {
    “Sun”: “on”
    },
    “run_at”: “18:00”,
    “times”: “”,
    “date_times”: “”,
    “last_run”: 1549822394,
    “next_run”: 1550426400
    },
    “export_rule”: “custom”,
    “export_rule_custom”: “5”,
    “export_filename”: “orders-%y-%m-%d-%h-%i-%s.csv”,
    “destination”: {
    “email_from”: “”,
    “email_from_name”: “”,
    “email_subject”: “”,
    “email_body”: “”,
    “email_recipients”: “”,
    “email_recipients_cc”: “”,
    “email_recipients_bcc”: “”,
    “ftp_server”: “”,
    “ftp_port”: “”,
    “ftp_user”: “”,
    “ftp_pass”: “”,
    “ftp_path”: “”,
    “ftp_conn_timeout”: “”,
    “ftp_max_retries”: “”,
    “sftp_server”: “”,
    “sftp_port”: “”,
    “sftp_user”: “”,
    “sftp_pass”: “”,
    “sftp_path”: “”,
    “sftp_conn_timeout”: “”,
    “sftp_max_retries”: “”,
    “http_post_url”: “”,
    “http_post_conn_timeout”: “”,
    “http_post_max_retries”: “”,
    “path”: “\/var\/www\/html\/”,
    “zapier_export_order_product_columns”: “10”,
    “zapier_export_order_coupon_columns”: “10”
    }
    }

    Plugin Author algol.plus

    (@algolplus)

    hi

    Please, remove code from “Misc Settings” and add to functions.php in child theme ( or use plugin https://ww.wp.xz.cn/plugins/code-snippets/) .

    if you do it correct – you should see following line at bottom.
    “Export products as columns, print [Qty] in cell”

    thanks, Alex

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Group Export by Product (columns)’ is closed to new replies.