AEMexporterajaxExport

The Woocommerce CSV Import AEM exporter ajaxExport class.

Defined (1)

The class is defined in the following location(s).

/export/include/ajaxExport.php  
  1. class ajaxExport implements exportInterface 
  2. public $current_run; 
  3.  
  4. public $file; 
  5.  
  6. public $writer; 
  7.  
  8. public function __construct (writerInterface $writer) 
  9. $this->current_run = get_option( 'woocsv_export_current' ); 
  10. $this->writer = $writer; 
  11.  
  12. public function start () 
  13. global $wpdb; 
  14.  
  15. $this->newRun(); 
  16.  
  17. $this->current_run[ 'status' ] = 'running'; 
  18. $current_id = $this->current_run[ 'current_id' ]; 
  19.  
  20. $posts = $wpdb->get_col( $wpdb->prepare( "select ID from $wpdb->posts where post_type=%s and ID > %d order by ID limit %d",  
  21. 'product', $current_id, 10 ) ); 
  22.  
  23. if (!$posts) { 
  24. delete_option( 'woocsv_export_current' ); 
  25. wp_die( 0 ); 
  26.  
  27. foreach ($posts as $post) { 
  28. $this->exportProduct( $post ); 
  29.  
  30. update_option( 'woocsv_export_current', $this->current_run ); 
  31.  
  32. wp_die( $this->current_run[ 'current_row' ] ); 
  33.  
  34. public function exportProduct ($post) 
  35.  
  36. $product = wc_get_product( $post ); 
  37. $className = "AEM\\exporter\\".$product->product_type; 
  38.  
  39. if (class_exists( $className )) { 
  40. $export_product = new $className ( $post, $this->current_run[ 'header' ], $this->writer ); 
  41. $export_product->save(); 
  42.  
  43. $this->current_run[ 'current_id' ] = $post; 
  44. $this->current_run[ 'current_row' ]++; 
  45.  
  46.  
  47. public function newRun () 
  48. if ($this->current_run) { 
  49. return; 
  50.  
  51. $upload_dir = wp_upload_dir(); 
  52. $filename = $upload_dir[ 'basedir' ] . '/woocsv_export_' . time() . '.csv'; 
  53.  
  54. $header = $this->getHeader(); 
  55.  
  56. $strippedHeader = $this->stripHeader(); 
  57.  
  58. $this->current_run = array ( 
  59. 'header' => $header,  
  60. 'filename' => $filename,  
  61. 'status' => 'new',  
  62. 'current_id' => 0,  
  63. 'current_row' => 0,  
  64. ); 
  65.  
  66. update_option( 'woocsv_export_current', $this->current_run ); 
  67.  
  68. $this->writer->write($strippedHeader); 
  69.  
  70.  
  71.  
  72. public function getHeader () 
  73. return woocsv_export()->product->allFields(); 
  74.  
  75. /** 
  76. * @return array 
  77. */ 
  78. public function stripHeader () 
  79. $header = $this->getHeader(); 
  80. $stripped_header = array (); 
  81. foreach ($header as $h) { 
  82. $stripped_header[] = ltrim( $h, '_' ); 
  83.  
  84. return $stripped_header; 
  85.