How to import a large number of products in Magento 2?

Nhận xét sản phẩm này

Tình trạng: Còn hàng

0,00 US$
Hoặc

Xem nhanh


It has been some time since the new version-Magento 2 was released. However, there’s still quite many issues that have not yet optimized at the moment. Typically, importing products is one of these problems. 

How to import a large number of products in Magento 2?

How to import a large number of products in Magento 2?

It has been some time since the new version-Magento 2 was released. However, there’s still quite many issues that have not yet optimized at the moment. Typically, importing products is one of these problems.

To make an example, we will proceed importing a CSV file with the following format (m2-import.csv):

 - Fill in all required fields on CSV file

- Make sure all SKU is unique

- Format the image file path correctly

To import a large number of products at the same time, URL KEY field needs to be filled

+ To have the URL KEY format compatible with Magento, we need to write script in order to reformat the product name, following is a reference script:

Upload file m2-import.csv to root file in magento 

Create urlkey.php file, then paste the following script:


$urlArray = array();
if (($handle = fopen("m2-import.csv", "r")) !== FALSE) { 
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) { 
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $data[8]); // 8 vị trí cột của trường “name”
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", '-', $clean);
$i = 0;
if(in_array($clean, $urlArray)){
$clean = $clean . '-1';
$urlArray[] = $clean;
}else{
$urlArray[] = $clean;
}

fclose($handle);
}
foreach ($urlEnd2 as $value) {
echo $value . '
';
}
print_r(array_count_values($urlEnd2));
?>


Run this url: 
http://domain.com/urlkey.php to show the database result on screen. Then copy the whole shown database to URL KEY column.

Once all needed information is completely filled in CSV file-> proceed importing

Admin->System->Import

 After completing import, remember to reindex data and upgrade website database.

Reindex: php bin/magento indexer:reindex

Upgrade: php bin/magento setup:upgrade

When things are done, reload the site and check the result.

Thông tin kỹ thuật

Author Nguyen Minh Toan
(0)

Questions and Answers

add your question

There are no entries.