Viewing 1 replies (of 1 total)
  • Thread Starter deejaybackloop

    (@deejaybackloop)

    Here is the code off the customised class-stock-manager-admin.php

    /**
    * Create csv array and download cvs file
    *
    * @since 1.0.0
    */
    public function stock_convert_to_csv($input_array, $output_file_name, $delimiter){

    $temp_memory = fopen(‘php://memory’, ‘w’);

    foreach ($input_array as $line) {
    fputcsv($temp_memory, $line, $delimiter);
    }
    fseek($temp_memory, 0);

    header(‘Content-Type: application/csv’);
    header(‘Content-Disposition: attachement; filename=”‘ . $output_file_name . ‘”;’);

    fpassthru($temp_memory);
    exit();
    }

    /**
    * Generate csv data
    *
    * @since 1.0.0
    */
    public function generate_csv_file(){

    if(isset($_GET[‘action’]) && $_GET[‘action’] == ‘export’){

    $stock = $this->stock();

    $array_to_csv = array();
    //First line
    $array_to_csv[] = array(‘id’,’sku’,’Name’,’maat’,’Stock status’,’Stock’,’Type’);

    $products = $stock->get_products_for_export();

    /** $name variabele toegevoegd om de naam van het product te weten**/
    foreach( $products as $item ){
    $product_meta = get_post_meta($item->ID);
    $name = get_the_title($item->ID);
    $item_product = get_product($item->ID);
    $product_type = $item_product->product_type;
    $id = $item->ID;

    if(!empty($product_meta[‘_sku’][0])){ $sku = $product_meta[‘_sku’][0]; }else{ $sku = ”; }

    if(!empty($product_meta[‘_stock_status’][0])){ $stock_status = $product_meta[‘_stock_status’][0]; }else{ $stock_status = ”; }

    if(!empty($product_meta[‘_stock’][0])){ $stock = $product_meta[‘_stock’][0]; }else{ $stock = ‘0’; }
    if($product_type == ‘variable’){ $product_type = ‘variable’; }else{ $product_type = ‘simple’; }

    $array_to_csv[] = array($id,$sku,$name,$maat,$stock_status,$stock,$product_type,”);

    if($product_type == ‘variable’){
    $args = array(
    ‘post_parent’ => $item->ID,
    ‘post_type’ => ‘product_variation’,
    ‘numberposts’ => -1,
    ‘post_status’ => ‘publish’
    );
    $variations_array = get_children( $args );
    foreach($variations_array as $vars){

    $var_meta = get_post_meta($vars->ID);

    $id = $vars->ID;
    if(!empty($var_meta[‘_sku’][0])){ $sku = $var_meta[‘_sku’][0]; }else{ $sku = ”; }

    if(!empty($var_meta[‘_stock_status’][0])){ $stock_status = $var_meta[‘_stock_status’][0]; }else{ $stock_status = ”; }

    if(!empty($var_meta[‘_stock’][0])){ $stock = $var_meta[‘_stock’][0]; }else{ $stock = ‘0’; }
    $product_type = ‘product-variant’;
    $parent_id = $item->ID;

    $array_to_csv[] = array($id,$sku,$name,$maat,$stock_status,$stock,$product_type);

    }
    }
    }

    $this->stock_convert_to_csv($array_to_csv, ‘stock-manager-export.csv’, ‘;’);

    }
    }

Viewing 1 replies (of 1 total)
  • The topic ‘place Name product Attribute Name in csv-export’ is closed to new replies.