Magento -- How to batch upload products in magento

Source: Internet
Author: User

I spent a lot of time reading almost all the posts related to batch uploading products on the magento official forum, analyzed a lot of relevant magento code, and finally realized the function of batch uploading products, without the hassle of slow network speed, jumping between pages, and repeatedly inputting data, you only need to edit data in Excel to Easily upload products to magento sites in batches.

 

Common problems encountered (all done, haha ):

Upload multiple images

Magento foreground cannot view uploaded files

After uploading, the foreground cannot view the image

After uploading, the foreground can only see some images

After uploading, the foreground images are duplicated.

Custom option cannot be uploaded (option-based price, SKU, and sort order can be supported)

(Note: If you want to upload products in batches, only 60 RMB is collected for the following 1000 products. If you need them, contact us)

 

Steps:

1. Upload all product images to magento/Media/import

2. Go to the magento management backend -- import/export -- profile and select export all product.

 

After basic settings, select Run profile. You will find a file under magento/var/export.

 

3. edit the file as a template. if the site is multilingual, it is best to provide records in different languages for a product.

 

4. The path of image, small_image, and thumbnail must start /.

5. The data file can be in CSV or XML format, but the sequence must correspond to the background settings.

6. the SKU of the same product must be consistent. do not duplicate the SKU of different products. magento uses the SKU to identify a product.

7. If you want to import magento's custom option, set magento product property has options to 1.

8. The custom option should be placed in the last column of the data file.

9. upload the data file to the/var/export directory of magento (or var/import). This depends on the settings in the import profile of magento import and export.

10. Go to the magento background to edit the same profile. However, after you change the direction to import and save it, run profile in pop window.

Problems that have not yet been tested (but it should be possible ):

How to specify the label of each image when uploading an image

 

For image uploading and custom option uploading, we need to modify the magento code and patch it.

(If You Need To reprint, please indicate the source :)

 

 

[PHP]View plaincopy
  1. $ Custom_options = array ();

 

 

 

 

 

[PHP]View plaincopy
  1. /* Custom Option Code */
  2. Error_log ($ field, 3, "my-errors.log ");
  3. If (strpos ($ field ,':')! ==False & strlen ($ value )){
  4. $ Values = explode ('|', $ value );
  5. If (count ($ values)> 0 ){
  6. @ List ($ title, $ type, $ is_required, $ sort_order) = explode (':', $ field );
  7. $ Title = ucfirst (str_replace ('_', '', $ title ));
  8. $ Custom_options [] = array (
  9. 'Is _ delete' => 0,
  10. 'Title' => $ title,
  11. 'Previous _ group' => '',
  12. 'Previous _ type' => '',
  13. 'Type' => $ type,
  14. 'Is _ require '=> $ is_required,
  15. 'Sort _ order' => $ sort_order,
  16. 'Values' => array ()
  17. );
  18. Foreach ($ values as $ v ){
  19. $ Parts = explode (':', $ V );
  20. $ Title = $ parts [0];
  21. If (count ($ parts)> 1 ){
  22. $ Price_type = $ parts [1];
  23. } Else {
  24. $ Price_type = 'fixed ';
  25. }
  26. If (count ($ parts)> 2 ){
  27. $ Price = $ parts [2];
  28. } Else {
  29. $ Price = 0;
  30. }
  31. If (count ($ parts)> 3 ){
  32. $ SKU = $ parts [3];
  33. } Else {
  34. $ SKU = '';
  35. }
  36. If (count ($ parts)> 4 ){
  37. $ Sort_order = $ parts [4];
  38. } Else {
  39. $ Sort_order = 0;
  40. }
  41. Switch ($ type ){
  42. Case 'file ':
  43. /* Todo */
  44. Break;
  45. Case 'field ':
  46. Case 'region ':
  47. $ Custom_options [count ($ custom_options)-1] ['max _ characters '] = $ sort_order;
  48. /* No break */
  49. Case 'date ':
  50. Case 'date _ time ':
  51. Case 'time ':
  52. $ Custom_options [count ($ custom_options)-1] ['price _ type'] = $ price_type;
  53. $ Custom_options [count ($ custom_options)-1] ['price'] = $ price;
  54. $ Custom_options [count ($ custom_options)-1] ['sku '] = $ SKU;
  55. Break;
  56. Case 'drop _ low ':
  57. Case 'Radio ':
  58. Case 'checkbox ':
  59. Case 'Multiple ':
  60. Default:
  61. $ Custom_options [count ($ custom_options)-1] ['values'] [] = array (
  62. 'Is _ delete' => 0,
  63. 'Title' => $ title,
  64. 'Option _ type_id '=>-1,
  65. 'Price _ type' => $ price_type,
  66. 'Price' => $ price,
  67. 'Sku '=> $ SKU,
  68. 'Sort _ order' => $ sort_order,
  69. );
  70. Break;
  71. }
  72. }
  73. }
  74. }
  75. /* End custom Option Code */

 

 

 

[PHP]View plaincopy
  1. /* Remove existing custom options attached to the product */
  2. Foreach ($ product-> getoptions () as $ o ){
  3. $ O-> getvalueinstance ()-> deletevalue ($ o-> GETID ());
  4. $ O-> deleteprices ($ o-> GETID ());
  5. $ O-> deletetitles ($ o-> GETID ());
  6. $ O-> Delete ();
  7. }
  8. /* Add the custom options specified in the CSV import file */
  9. If (count ($ custom_options )){
  10. Foreach ($ custom_options as $ option ){
  11. Try {
  12. $ Opt = Mage: GetModel ('catalog/product_option ');
  13. $ Opt-> setproduct ($ product );
  14. $ Opt-> addoption ($ option );
  15. $ Opt-> saveoptions ();
  16. }
  17. Catch (exception $ e ){}
  18. }
  19. }

 

 

Supplement: there are too many people asking related questions.

 

1. Note that the Linux server is usually used, so the file name is case sensitive.

2. fieldset and store fields also encounter case sensitivity issues.

3. Currently, this patch does not process leading or trailing spaces for values in the field. Therefore, make sure there are no spaces in the entered values. Otherwise, an error occurs.

4. Make patches before uploading custom optoin. The format must be correct.

5. the following fields are required. If one of them fails, it seems that none of them can be blank (there is time to perform one-to-one verification at the end)

 

Attribute_set Category_ids Description Image Is_in_stock Name Price Qty Short_description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.