• Resolved growersbox

    (@growersbox)


    Hey,

    Love the plugin so far it’s great! Just wanted to see if it possible to sort the export by product instead of order ID so that the same products on the table are next to eachother?

    Also would it be possible to add a total amount of all products listed in the export so you can quickly see your total orders for each product without going through and counting each order.

    Appreciate any assistance!

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

    (@algolplus)

    Hi

    Will we sort by product title or SKU?
    How many orders will you export ?
    thanks, alex

    Thread Starter growersbox

    (@growersbox)

    Thanks for the quick response!

    By product title would be amazing.

    That changes with each export, what I mean is if 5 orders have the product “cd player” then somewhere on the export the total shows up so in this case it would of course be 5.

    Here’s a rough example Order Total Example

    Plugin Author algol.plus

    (@algolplus)

    ok, I’ll try to provide code later today

    Thread Starter growersbox

    (@growersbox)

    Thank you! Really appreciate it ??

    Plugin Author algol.plus

    (@algolplus)

    hi

    I’m sorry for long function, it’s for CSV.

    Sorting by any field + product summary for any formats will be added in next major (2.0) version only

    // Sort by Product Title + Summary, see requirements below! 
    // Format - CSV
    // Checked - Output column titles as first line
    // Checked - Populate other columns if products exported as rows
    // Button - Export w/o Progressbar 
    class Woe_Product_Summary {
    	function __construct() {
    		$this->header = false;
    		$this->lines = array();
    		
    		add_action("woe_order_export_started",array($this,"start_new_order"),10,1);
    		add_filter("woe_get_order_product_item",array($this,"record_product_qty"),10,1);
    		add_filter("woe_get_order_product",array($this,"record_product_title"),10,1);
    		
    		
    		add_filter("woe_csv_custom_output_func",array($this,"remember_lines"),10,6);
    		add_action("woe_csv_print_footer",array($this,"print_ordered_list_and_summary"),10,1);
    	}
    	
    	// 3 tricky functions, as we don't have product fields in v1.3.0
    	function start_new_order($order_id) {
    		$this->product_name = array();
    		$this->product_qty = array();
    		$this->product_pos = 0;
    	}
    	function record_product_qty($item) {
    		$this->item_qty = $item['qty'];
    	}	
    	function record_product_title($product) {
    		$this->product_name[] = $product->post->post_title; 
    		$this->product_qty[] = $this->item_qty; 
    		return $product;
    	}
    	function remember_lines($continue,$handle, $data, $delimiter, $linebreak, $enclosure) {
    		if(! $this->header )
    			$this->header = $data;
    		else {	
    			$name = $this->product_name[$this->product_pos];
    			$qty = $this->product_qty[$this->product_pos++];
    			if($name)
    				$this->lines[] = array('name'=>$name, 'qty'=>$qty, 'data'=>$data);
    		}	
    		return true; // don't output!
    	}
    
    	function print_ordered_list_and_summary($handle) {
    		//sort lines
    		usort($this->lines, function ($a, $b) {
    			return strcmp($a["name"], $b["name"]);
    		});
    		
    		// output sorted 
    		fputcsv($handle,$this->header);
    		foreach($this->lines as $line) {
    			fputcsv($handle,$line['data']);
    			@$counters[$line['name']]+=$line['qty'];
    		}	
    		
    		//empty space 
    		fwrite($handle,"\n\n\n");
    		
    		// print summary		
    		fputcsv($handle,array("Product Name","Total") );
    		foreach($counters  as $name=>$cnt) {
    			fputcsv($handle,array($name,$cnt));
    		}	
    	}
    }
    new Woe_Product_Summary();
    • This reply was modified 7 years, 6 months ago by algol.plus.
    Thread Starter growersbox

    (@growersbox)

    Thanks for putting this together so quickly! Really, appreciate it. Sorry for the late response I had this on hold for awhile.

    It works almost perfectly except it doesn’t take into account when there is more than one item in the totals for each order.

    For exampleFor Example

    Thanks again for your help so far, defiantly one of the best plugins I’ve ever used for Woocommerce.

    Plugin Author algol.plus

    (@algolplus)

    Could you try these steps?

    open section “Setup fields”
    scroll down to “Products”
    select (*) “as rows”

    Plugin Author algol.plus

    (@algolplus)

    Or you can try another (more stable) code

    sample “//Summary by Products , see conditions below!”
    at page https://algolplus.com/plugins/code-samples/

    Thread Starter growersbox

    (@growersbox)

    Your steps work great for making sure the totals are counted correctly but in this case we’re actually sending the exported csv to a routing plugin for delivery as well so the product(s) need to be on the same row as the order and not duplicated otherwise people who order multiple items will show up multiple times in the address routing software.

    Thanks for that link! Defiantly more clean although it would be great if it would take into account fields selected in “setup fields” like the original code did. Right now it only exports the order totals and ignores anything selected in setup fields.

    Thanks for all the time you spent on this! We’ve actually got it working exactly how we’d like it right now I just thought I’d let you know the issues we run into.

    Also out of curiosity do you have any plans on implementing multiple exports being sent within one email (insead of each export being sent in one email) on your roadmap?

    Thanks again!

    Plugin Author algol.plus

    (@algolplus)

    hi

    You can remove
    add_filter("woe_csv_custom_output_func", array($this,'skip_order_line') );
    and will get orders above total section.

    Could you describe “use case” for last question (multiple exports in one email) ?

    Thanks, Alex

    • This reply was modified 7 years, 6 months ago by algol.plus.
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Possible to sort rows by product?’ is closed to new replies.