skip to Main Content

I got error when export product

enter image description here

2

Answers


  1. maybe its because your crons not run then you need to run: bin/magento cron:run

    If not work with that line then try manually with bin/magento queue:consumers:start exportProcessor

    Good luck

    Login or Signup to reply.
  2. Im a bit late, and glad you got your issue sorted.

    I Found this post a while back and had other problems wit magento’s export, so posting my solution here for other readers. I got thrustrated with Magento’s silly export (its worse if you have 20k+ products with 100’s of attributes (it completely breaks)).

    So I created a small standalone php script for my own exports. Anyone is welcome to use it, but will have to edit it to fit their need’s (and db). But will be a massive time (and headache) saver if they a massive store

        <?php
    header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    
    $connect = mysqli_connect("your","db","details","here") OR die ('Could not connect to MySQL');
    $brandlist = "SELECT `value` FROM `eav_attribute_option_value` LEFT JOIN `eav_attribute_option` ON `eav_attribute_option`.`option_id` = `eav_attribute_option_value` . `option_id` WHERE `eav_attribute_option_value`.`store_id` = 0 AND `eav_attribute_option`.`attribute_id` = 165 ORDER BY `value` ASC";
    
    if ($_SERVER["REQUEST_METHOD"] != "POST") {
    ?>
    
    <form method="post" action="<?php /* @escapeNotVerified */ ?>" enctype="multipart/form-data">
      Brand: <select name="brand" id="brand">
      <?php
      foreach (($connect->query($brandlist)) as $row){
    echo '<option value="'  . $row['value'] . '">' . $row['value'] . '</option>';
    }
    ?>
    </select>
    <input class="button" type="submit" name="submit" value="Submit"> 
    </form>
    
    <?php
    }
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $brand = $_POST["brand"];
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    $result = mysqli_query($connect, "SELECT
           e.sku,
           v1.value AS 'name',
           v3.value AS 'product_online',
           d1.value AS 'price',
           v7.value AS 'url_key',
           v10.value AS 'special_price',
           v8.`value` AS 'special_to',
           v9.value AS 'special_from'
    FROM catalog_product_entity e
    LEFT JOIN catalog_product_entity_varchar v1 ON e.entity_id = v1.entity_id
    AND v1.store_id = 0
    AND v1.attribute_id =
      (SELECT attribute_id
       FROM eav_attribute
       WHERE attribute_code = 'name'
         AND entity_type_id =
           (SELECT entity_type_id
            FROM eav_entity_type
            WHERE entity_type_code = 'catalog_product'))
    LEFT JOIN catalog_product_entity_decimal d1 ON e.entity_id = d1.entity_id
    AND d1.store_id = 0
    AND d1.attribute_id =
      (SELECT attribute_id
       FROM eav_attribute
       WHERE attribute_code = 'price'
         AND entity_type_id =
           (SELECT entity_type_id
            FROM eav_entity_type
            WHERE entity_type_code = 'catalog_product'))
            LEFT JOIN catalog_product_entity_int v3 ON e.entity_id = v3.entity_id
    AND v3.store_id = 0
    AND v3.attribute_id =
      (SELECT attribute_id
       FROM eav_attribute
       WHERE attribute_code = 'status'
         AND entity_type_id =
           (SELECT entity_type_id
            FROM eav_entity_type
            WHERE entity_type_code = 'catalog_product'))
                    LEFT JOIN catalog_product_entity_int v4 ON e.entity_id = v4.entity_id
    AND v4.store_id = 0
    AND v4.attribute_id =
      (SELECT attribute_id
       FROM eav_attribute
       WHERE attribute_code = 'manufacturer'
         AND entity_type_id =
           (SELECT entity_type_id
            FROM eav_entity_type
            WHERE entity_type_code = 'catalog_product'))
                            LEFT JOIN eav_attribute_option_value v5 ON v4.value = v5.option_id
    AND v5.store_id = 0
    AND v5.option_id = v4.value
    LEFT JOIN catalog_product_entity v6 ON e.entity_id = v6.entity_id
    LEFT JOIN catalog_product_entity_varchar v7 ON e.entity_id = v7.entity_id AND v7.store_id = 0 AND v7.attribute_id =
      (SELECT attribute_id
       FROM eav_attribute
       WHERE attribute_code = 'url_key'
         AND entity_type_id =
           (SELECT entity_type_id
            FROM eav_entity_type
            WHERE entity_type_code = 'catalog_product'))
    LEFT JOIN
      (SELECT product_id,
              GROUP_CONCAT(c.category_id SEPARATOR ',') AS category_ids,
              GROUP_CONCAT(cv.value SEPARATOR ',') AS category_names
       FROM catalog_category_product c
       INNER JOIN catalog_category_entity_varchar cv ON c.category_id = cv.entity_id
       AND cv.store_id = 0
       AND cv.attribute_id =
         (SELECT attribute_id
          FROM eav_attribute
          WHERE attribute_code = 'name'
            AND entity_type_id =
              (SELECT entity_type_id
               FROM eav_entity_type
               WHERE entity_type_code = 'catalog_category'))
       GROUP BY product_id) cids ON e.entity_id = cids.product_id
          LEFT JOIN catalog_product_entity_datetime v8 ON e.entity_id = v8.entity_id AND v8.attribute_id = 159 AND (DATE_FORMAT(v8.`value`, '%Y-%m-%d') >= CURDATE())
            LEFT JOIN catalog_product_entity_datetime v9 ON e.entity_id = v9.entity_id AND v9.attribute_id = 157 AND (DATE_FORMAT(v9.`value`, '%Y-%m-%d') <= CURDATE()) AND (DATE_FORMAT(v8.`value`, '%Y-%m-%d') >= CURDATE())
                LEFT JOIN catalog_product_entity_decimal v10 ON e.entity_id = v10.entity_id AND v10.attribute_id = 155 AND v9.attribute_id = 157 AND (DATE_FORMAT(v9.`value`, '%Y-%m-%d') <= CURDATE()) AND (DATE_FORMAT(v8.`value`, '%Y-%m-%d') >= CURDATE())
       WHERE v3.value = 1
       AND v5.value = '$brand'
       AND NOT v6.attribute_set_id = 39
       AND NOT v1.value LIKE '%(EOL)%' AND NOT v1.value LIKE '%Discontinued%' AND NOT v1.value LIKE 'Product Not For Sale' AND NOT d1.value = 0 AND NOT v6.attribute_set_id = 37;");
       if ($connect->query($result) === TRUE) {
      echo "db connect pass";}
          else {
        echo $connect->error;
    }
    
       function setExcelContentType() {
        if(headers_sent())
            return false;
    
        header('Content-type: application/vnd.ms-excel');
        return true;
    }
    
    function setDownloadAsHeader($filename) {
        if(headers_sent())
            return false;
    
        header('Content-disposition: attachment; filename=' . $filename);
        return true;
    }
    
    function csvFromResult($stream, $result, $showColumnHeaders = true) {
        if($showColumnHeaders) {
            $columnHeaders = array();
            $nfields = mysqli_num_fields($result);
            for($i = 0; $i < $nfields; $i++) {
                $field = mysqli_fetch_field($result);
                $columnHeaders[] = $field->name;
            }
            fputcsv($stream, $columnHeaders);
        }
    
        $nrows = 0;
        while($row = mysqli_fetch_row($result)) {
            fputcsv($stream, $row);
            $nrows++;
        }
    
        return $nrows;
    }
    
    function csvFileFromResult($filename, $result, $showColumnHeaders = true) {
        $fp = fopen($filename, 'w');
        $rc = csvFromResult($fp, $result, $showColumnHeaders);
        fclose($fp);
        return $rc;
    }
    
    function csvToExcelDownloadFromResult($result, $showColumnHeaders = true, $asFilename = 'product-export.csv') {
        $asFilename = 'product-export-' . date('m-d-Y-His') . '.csv';
        setExcelContentType();
        setDownloadAsHeader($asFilename);
        return csvFileFromResult('php://output', $result, $showColumnHeaders);
    }
    csvToExcelDownloadFromResult($result);
    }
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search