magento2 - 产品导出时的magento 2.3“消息已添加到队列中,请等待尽快获取您的文件”
解决方案
我有点晚了,很高兴你解决了你的问题。
我不久前发现了这篇文章,并且在 magento 的导出方面遇到了其他问题,所以在这里为其他读者发布我的解决方案。我被 Magento 愚蠢的出口推倒了(如果你有 20k+ 具有 100 个属性的产品(它完全崩溃),那就更糟了)。
所以我为自己的导出创建了一个小的独立 php 脚本。欢迎任何人使用它,但必须对其进行编辑以适应他们的需要(和数据库)。但如果他们是一家大型商店,那将是一个巨大的时间(和头痛)节省者
<?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);
}
?>
推荐阅读
- r - 一次将 dplyr 函数应用于所有变量
- jenkins - 在 Jenkins 模板引擎中使用实用程序脚本
- zeromq - ZMQ PUB/SUB 套接字低负载下的高延迟
- javascript - 在按钮上设置 Cookie
- javascript - 出现错误:未捕获的 ReferenceError:gsap 未在基本 HTML/CSS/JS 页面上定义
- python - 有没有办法解决具有 n 个约束的约束优化函数(拉格朗日)?
- uml - 如何避免创建冗长而复杂的序列图?
- android - Firebase 云消息通知在设备上不可见,但 onMessageReceived 正在执行
- mysql - 将文件加载到 MySQL 的“Azure Database for MySQL”实例中
- c++ - 通过 const std::function 引用传递临时 lambda 应该会失败,但似乎可以工作