workarea-magento_migrator 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.ruby-gemset +1 -0
  4. data/Gemfile +16 -0
  5. data/LICENSE +52 -0
  6. data/README.md +56 -0
  7. data/Rakefile +57 -0
  8. data/app/assets/images/workarea/admin/magento_data_migration/.keep +0 -0
  9. data/app/assets/images/workarea/storefront/magento_data_migration/.keep +0 -0
  10. data/app/assets/javascripts/workarea/admin/magento_data_migration/.keep +0 -0
  11. data/app/assets/javascripts/workarea/storefront/magento_data_migration/.keep +0 -0
  12. data/app/assets/stylesheets/workarea/admin/magento_data_migration/.keep +0 -0
  13. data/app/assets/stylesheets/workarea/storefront/magento_data_migration/.keep +0 -0
  14. data/app/controllers/.keep +0 -0
  15. data/app/helpers/.keep +0 -0
  16. data/app/mailers/.keep +0 -0
  17. data/app/models/.keep +0 -0
  18. data/app/models/workarea/magento_customer.rb +10 -0
  19. data/app/models/workarea/user.decorator +20 -0
  20. data/app/views/.keep +0 -0
  21. data/bin/magento_migrator +21 -0
  22. data/bin/rails +25 -0
  23. data/config/data/catalog_category.yml +55 -0
  24. data/config/data/catalog_product.yml +51 -0
  25. data/config/initializers/workarea.rb +3 -0
  26. data/config/routes.rb +2 -0
  27. data/data/categories.json +28460 -0
  28. data/data/content_pages.json +7566 -0
  29. data/data/taxons.json +1336 -0
  30. data/dump.rdb +0 -0
  31. data/fields_for_magento_modules.md +30 -0
  32. data/lib/field-mapping/fields_for_magento_customer_module.md +30 -0
  33. data/lib/field-mapping/fields_for_workarea_customer_module.md +23 -0
  34. data/lib/sql/magento_customer.sql +26 -0
  35. data/lib/sql/magento_products.sql +147 -0
  36. data/lib/tasks/catalog_catagories.rake +21 -0
  37. data/lib/tasks/customers.rake +9 -0
  38. data/lib/tasks/products.rake +8 -0
  39. data/lib/tasks/workarea/import_magento_content.rake +14 -0
  40. data/lib/workarea/magento_migrator/catalog_category.rb +238 -0
  41. data/lib/workarea/magento_migrator/catalog_product.rb +38 -0
  42. data/lib/workarea/magento_migrator/engine.rb +10 -0
  43. data/lib/workarea/magento_migrator/magento_base.rb +119 -0
  44. data/lib/workarea/magento_migrator/sql_connection.rb +76 -0
  45. data/lib/workarea/magento_migrator/version.rb +5 -0
  46. data/lib/workarea/magento_migrator.rb +19 -0
  47. data/test/dummy/.ruby-version +1 -0
  48. data/test/dummy/Rakefile +6 -0
  49. data/test/dummy/app/assets/config/manifest.js +3 -0
  50. data/test/dummy/app/assets/images/.keep +0 -0
  51. data/test/dummy/app/assets/javascripts/application.js +14 -0
  52. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  53. data/test/dummy/app/controllers/application_controller.rb +2 -0
  54. data/test/dummy/app/controllers/concerns/.keep +0 -0
  55. data/test/dummy/app/helpers/application_helper.rb +2 -0
  56. data/test/dummy/app/jobs/application_job.rb +2 -0
  57. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  58. data/test/dummy/app/models/concerns/.keep +0 -0
  59. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  60. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  61. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  62. data/test/dummy/bin/bundle +3 -0
  63. data/test/dummy/bin/rails +4 -0
  64. data/test/dummy/bin/rake +4 -0
  65. data/test/dummy/bin/setup +25 -0
  66. data/test/dummy/bin/update +25 -0
  67. data/test/dummy/config/application.rb +34 -0
  68. data/test/dummy/config/boot.rb +5 -0
  69. data/test/dummy/config/environment.rb +5 -0
  70. data/test/dummy/config/environments/development.rb +52 -0
  71. data/test/dummy/config/environments/production.rb +83 -0
  72. data/test/dummy/config/environments/test.rb +45 -0
  73. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  74. data/test/dummy/config/initializers/assets.rb +12 -0
  75. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  76. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  77. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  78. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  79. data/test/dummy/config/initializers/inflections.rb +16 -0
  80. data/test/dummy/config/initializers/mime_types.rb +4 -0
  81. data/test/dummy/config/initializers/workarea.rb +5 -0
  82. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  83. data/test/dummy/config/locales/en.yml +33 -0
  84. data/test/dummy/config/puma.rb +34 -0
  85. data/test/dummy/config/routes.rb +5 -0
  86. data/test/dummy/config/spring.rb +6 -0
  87. data/test/dummy/config.ru +5 -0
  88. data/test/dummy/db/seeds.rb +2 -0
  89. data/test/dummy/lib/assets/.keep +0 -0
  90. data/test/dummy/log/.keep +0 -0
  91. data/test/teaspoon_env.rb +6 -0
  92. data/test/test_helper.rb +10 -0
  93. data/test/workarea/magento_migrator/catalog_product_test.rb +13 -0
  94. data/workarea-magento_migrator.gemspec +23 -0
  95. metadata +178 -0
data/dump.rdb ADDED
Binary file
@@ -0,0 +1,30 @@
1
+ ```
2
+ fields through eav_attributes
3
+
4
+ created_in
5
+ default_billing
6
+ default_shipping
7
+ dob
8
+ firstname
9
+ gender
10
+ lastname
11
+ middlename
12
+ password_hash
13
+ prefix
14
+ reward_update_notification
15
+ reward_warning_notification
16
+ suffix
17
+ taxvat
18
+
19
+ fields directly belongs to 'customer_entity' table
20
+
21
+ entity_id
22
+ entity_type_id
23
+ website_id
24
+ email
25
+ store_id
26
+ created_at
27
+ updated_at
28
+ is_active
29
+
30
+ ```
@@ -0,0 +1,30 @@
1
+ ```
2
+ fields through eav_attributes
3
+
4
+ created_in
5
+ default_billing
6
+ default_shipping
7
+ dob
8
+ firstname
9
+ gender
10
+ lastname
11
+ middlename
12
+ password_hash
13
+ prefix
14
+ reward_update_notification
15
+ reward_warning_notification
16
+ suffix
17
+ taxvat
18
+
19
+ fields directly belongs to 'customer_entity' table
20
+
21
+ entity_id
22
+ entity_type_id
23
+ website_id
24
+ email
25
+ store_id
26
+ created_at
27
+ updated_at
28
+ is_active
29
+
30
+ ```
@@ -0,0 +1,23 @@
1
+ User
2
+ fields
3
+ _id, type: StringId, default: -> { BSON::ObjectId.new }
4
+ email, type: String
5
+ first_name, type: String
6
+ last_name, type: String
7
+ name, type: String
8
+ created_by_id, type: String
9
+
10
+ Address
11
+ association: one to many
12
+ fields:
13
+ first_name, type: String
14
+ last_name, type: String
15
+ company, type: String
16
+ street, type: String
17
+ street_2, type: String
18
+ city, type: String
19
+ region, type: String
20
+ postal_code, type: String
21
+ country, type: Country
22
+ phone_number, type: String
23
+ phone_extension, type: String
@@ -0,0 +1,26 @@
1
+ select
2
+ c.entity_id,
3
+ c.email,
4
+ c.created_at,
5
+ c.updated_at,
6
+ c.is_active,
7
+ c.group_id,
8
+ -- fetch columns from customer_entity_varchar
9
+ (select f.value from customer_entity_varchar f where c.entity_id = f.entity_id and f.attribute_id = 3) created_in,
10
+ (select f.value from customer_entity_varchar f where c.entity_id = f.entity_id and f.attribute_id = 4) prefix,
11
+ (select f.value from customer_entity_varchar f where c.entity_id = f.entity_id and f.attribute_id = 5) fitst_name,
12
+ (select f.value from customer_entity_varchar f where c.entity_id = f.entity_id and f.attribute_id = 6) middle_name,
13
+ (select f.value from customer_entity_varchar f where c.entity_id = f.entity_id and f.attribute_id = 7) last_name,
14
+ (select f.value from customer_entity_varchar f where c.entity_id = f.entity_id and f.attribute_id = 8) suffix,
15
+ (select f.value from customer_entity_varchar f where c.entity_id = f.entity_id and f.attribute_id = 12) password_hash,
16
+ (select f.value from customer_entity_varchar f where c.entity_id = f.entity_id and f.attribute_id = 15) taxvat,
17
+ -- fetch columns from customer_entity_int
18
+ (select f.value from customer_entity_int f where c.entity_id = f.entity_id and f.attribute_id = 13) default_billing,
19
+ (select f.value from customer_entity_int f where c.entity_id = f.entity_id and f.attribute_id = 14) default_shipping,
20
+ (select f.value from customer_entity_int f where c.entity_id = f.entity_id and f.attribute_id = 18) gender,
21
+ (select f.value from customer_entity_int f where c.entity_id = f.entity_id and f.attribute_id = 149) reward_update_notification,
22
+ (select f.value from customer_entity_int f where c.entity_id = f.entity_id and f.attribute_id = 150) reward_warning_notification,
23
+ -- fetch columns from customer_entity_datetime
24
+ (select f.value from customer_entity_datetime f where c.entity_id = f.entity_id and f.attribute_id = 11) dob
25
+
26
+ from customer_entity c;
@@ -0,0 +1,147 @@
1
+ -- Product entity type ID
2
+ SET @etype = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product');
3
+ -- Product name attribute ID
4
+ SET @name = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = @etype);
5
+ -- Product name attribute ID
6
+ SET @artist_name = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'artist_name' AND entity_type_id = @etype);
7
+ SET @country_of_manufacture = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'country_of_manufacture' AND entity_type_id = @etype);
8
+ SET @cs_sort_order = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'cs_sort_order' AND entity_type_id = @etype);
9
+ SET @custom_design = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'custom_design' AND entity_type_id = @etype);
10
+ SET @feed_dimensions = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'feed_dimensions' AND entity_type_id = @etype);
11
+ SET @feed_product_image = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'feed_product_image' AND entity_type_id = @etype);
12
+ SET @height = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'height' AND entity_type_id = @etype);
13
+ SET @image = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'image' AND entity_type_id = @etype);
14
+ SET @image_label = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'image_label' AND entity_type_id = @etype);
15
+ SET @links_title = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'links_title' AND entity_type_id = @etype);
16
+ SET @meta_description = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'meta_description' AND entity_type_id = @etype);
17
+ SET @meta_title = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'meta_title' AND entity_type_id = @etype);
18
+ SET @msrp_display_actual_price_type = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'msrp_display_actual_price_type' AND entity_type_id = @etype);
19
+ SET @msrp_enabled = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'msrp_enabled' AND entity_type_id = @etype);
20
+ SET @name = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = @etype);
21
+ SET @number_of_sales = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'number_of_sales' AND entity_type_id = @etype);
22
+ SET @options_container = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'options_container' AND entity_type_id = @etype);
23
+ SET @rating = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'rating' AND entity_type_id = @etype);
24
+ SET @rf123_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'rf123_id' AND entity_type_id = @etype);
25
+ SET @rf123_url = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'rf123_url' AND entity_type_id = @etype);
26
+ SET @sale_price = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'sale_price' AND entity_type_id = @etype);
27
+ SET @samples_title = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'samples_title' AND entity_type_id = @etype);
28
+ SET @small_image = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'small_image' AND entity_type_id = @etype);
29
+ SET @small_image_label = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'small_image_label' AND entity_type_id = @etype);
30
+ SET @small_price = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'small_price' AND entity_type_id = @etype);
31
+ SET @thumbnail = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'thumbnail' AND entity_type_id = @etype);
32
+ SET @thumbnail_label = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'thumbnail_label' AND entity_type_id = @etype);
33
+ SET @url_key = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'url_key' AND entity_type_id = @etype);
34
+ SET @url_path = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'url_path' AND entity_type_id = @etype);
35
+ SET @width = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'width' AND entity_type_id = @etype);
36
+ -- Product name attribute ID
37
+ SET @description = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'description' AND entity_type_id = @etype);
38
+ -- Product price attribute ID
39
+ SET @price = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'price' AND entity_type_id = @etype);
40
+ -- Admin store ID
41
+ SET @store = 0;
42
+
43
+ -- Query
44
+ SELECT
45
+ e.entity_id AS 'id',
46
+ e.sku,
47
+ v1.value AS 'name',
48
+ v2.value AS 'artist_name',
49
+ v3.value AS 'width',
50
+ v4.value AS 'country_of_manufacture',
51
+ v5.value AS 'cs_sort_order',
52
+ v6.value AS 'custom_design',
53
+ v7.value AS 'feed_dimensions',
54
+ v8.value AS 'feed_product_image',
55
+ v9.value AS 'height',
56
+ v10.value AS 'image',
57
+ v11.value AS 'image_label',
58
+ v12.value AS 'links_title',
59
+ v13.value AS 'meta_description',
60
+ v14.value AS 'meta_title',
61
+ v15.value AS 'msrp_display_actual_price_type',
62
+ v16.value AS 'msrp_enabled',
63
+ v17.value AS 'description',
64
+ v18.value AS 'number_of_sales',
65
+ v19.value AS 'options_container',
66
+ v20.value AS 'rating',
67
+ v21.value AS 'rf123_id',
68
+ v22.value AS 'rf123_url',
69
+ v23.value AS 'sale_price',
70
+ v24.value AS 'samples_title',
71
+ v25.value AS 'small_image',
72
+ v26.value AS 'small_image_label',
73
+ v27.value AS 'small_price',
74
+ v28.value AS 'thumbnail',
75
+ v29.value AS 'thumbnail_label',
76
+ v30.value AS 'url_key',
77
+ v31.value AS 'url_path',
78
+ si.qty AS 'stock qty',
79
+ d1.value AS 'price'
80
+ FROM
81
+ catalog_product_entity e
82
+ LEFT JOIN cataloginventory_stock_item si
83
+ ON e.entity_id = si.product_id
84
+ LEFT JOIN catalog_product_entity_varchar v1
85
+ ON e.entity_id = v1.entity_id AND v1.store_id = @store AND v1.attribute_id = @name
86
+ LEFT JOIN catalog_product_entity_varchar v2
87
+ ON e.entity_id = v2.entity_id AND v2.store_id = @store AND v2.attribute_id = @artist_name
88
+ LEFT JOIN catalog_product_entity_varchar v3
89
+ ON e.entity_id = v3.entity_id AND v3.store_id = @store AND v3.attribute_id = @width
90
+ LEFT JOIN catalog_product_entity_varchar v4
91
+ ON e.entity_id = v4.entity_id AND v4.store_id = @store AND v4.attribute_id = @country_of_manufacture
92
+ LEFT JOIN catalog_product_entity_varchar v5
93
+ ON e.entity_id = v5.entity_id AND v5.store_id = @store AND v5.attribute_id = @cs_sort_order
94
+ LEFT JOIN catalog_product_entity_varchar v6
95
+ ON e.entity_id = v6.entity_id AND v6.store_id = @store AND v6.attribute_id = @custom_design
96
+ LEFT JOIN catalog_product_entity_varchar v7
97
+ ON e.entity_id = v7.entity_id AND v7.store_id = @store AND v7.attribute_id = @feed_dimensions
98
+ LEFT JOIN catalog_product_entity_varchar v8
99
+ ON e.entity_id = v8.entity_id AND v8.store_id = @store AND v8.attribute_id = @feed_product_image
100
+ LEFT JOIN catalog_product_entity_varchar v9
101
+ ON e.entity_id = v9.entity_id AND v9.store_id = @store AND v9.attribute_id = @height
102
+ LEFT JOIN catalog_product_entity_varchar v10
103
+ ON e.entity_id = v10.entity_id AND v10.store_id = @store AND v10.attribute_id = @image
104
+ LEFT JOIN catalog_product_entity_varchar v11
105
+ ON e.entity_id = v11.entity_id AND v11.store_id = @store AND v11.attribute_id = @image_label
106
+ LEFT JOIN catalog_product_entity_varchar v12
107
+ ON e.entity_id = v12.entity_id AND v12.store_id = @store AND v12.attribute_id = @links_title
108
+ LEFT JOIN catalog_product_entity_varchar v13
109
+ ON e.entity_id = v13.entity_id AND v13.store_id = @store AND v13.attribute_id = @meta_description
110
+ LEFT JOIN catalog_product_entity_varchar v14
111
+ ON e.entity_id = v14.entity_id AND v14.store_id = @store AND v14.attribute_id = @meta_title
112
+ LEFT JOIN catalog_product_entity_varchar v15
113
+ ON e.entity_id = v15.entity_id AND v15.store_id = @store AND v15.attribute_id = @msrp_display_actual_price_type
114
+ LEFT JOIN catalog_product_entity_varchar v16
115
+ ON e.entity_id = v16.entity_id AND v16.store_id = @store AND v16.attribute_id = @msrp_enabled
116
+ LEFT JOIN catalog_product_entity_varchar v17
117
+ ON e.entity_id = v17.entity_id AND v17.store_id = @store AND v17.attribute_id = @description
118
+ LEFT JOIN catalog_product_entity_varchar v18
119
+ ON e.entity_id = v18.entity_id AND v18.store_id = @store AND v18.attribute_id = @number_of_sales
120
+ LEFT JOIN catalog_product_entity_varchar v19
121
+ ON e.entity_id = v19.entity_id AND v19.store_id = @store AND v19.attribute_id = @options_container
122
+ LEFT JOIN catalog_product_entity_varchar v20
123
+ ON e.entity_id = v20.entity_id AND v20.store_id = @store AND v20.attribute_id = @rating
124
+ LEFT JOIN catalog_product_entity_varchar v21
125
+ ON e.entity_id = v21.entity_id AND v21.store_id = @store AND v21.attribute_id = @rf123_id
126
+ LEFT JOIN catalog_product_entity_varchar v22
127
+ ON e.entity_id = v22.entity_id AND v22.store_id = @store AND v22.attribute_id = @rf123_url
128
+ LEFT JOIN catalog_product_entity_varchar v23
129
+ ON e.entity_id = v23.entity_id AND v23.store_id = @store AND v23.attribute_id = @sale_price
130
+ LEFT JOIN catalog_product_entity_varchar v24
131
+ ON e.entity_id = v24.entity_id AND v24.store_id = @store AND v24.attribute_id = @samples_title
132
+ LEFT JOIN catalog_product_entity_varchar v25
133
+ ON e.entity_id = v25.entity_id AND v25.store_id = @store AND v25.attribute_id = @small_image
134
+ LEFT JOIN catalog_product_entity_varchar v26
135
+ ON e.entity_id = v26.entity_id AND v26.store_id = @store AND v26.attribute_id = @small_image_label
136
+ LEFT JOIN catalog_product_entity_varchar v27
137
+ ON e.entity_id = v27.entity_id AND v27.store_id = @store AND v27.attribute_id = @small_price
138
+ LEFT JOIN catalog_product_entity_varchar v28
139
+ ON e.entity_id = v28.entity_id AND v28.store_id = @store AND v28.attribute_id = @thumbnail
140
+ LEFT JOIN catalog_product_entity_varchar v29
141
+ ON e.entity_id = v29.entity_id AND v29.store_id = @store AND v29.attribute_id = @thumbnail_label
142
+ LEFT JOIN catalog_product_entity_varchar v30
143
+ ON e.entity_id = v30.entity_id AND v30.store_id = @store AND v30.attribute_id = @url_key
144
+ LEFT JOIN catalog_product_entity_varchar v31
145
+ ON e.entity_id = v31.entity_id AND v31.store_id = @store AND v31.attribute_id = @url_path
146
+ LEFT JOIN catalog_product_entity_decimal d1
147
+ ON e.entity_id = d1.entity_id AND d1.store_id = @store AND d1.attribute_id = @price;
@@ -0,0 +1,21 @@
1
+ namespace :magento_migrator do
2
+ desc 'Fetch customers data from magento'
3
+
4
+ task :cc_menu => :environment do
5
+ puts Workarea::MagentoMigrator::CatalogCategory.catalog_category_menu
6
+ end
7
+
8
+ task :catagories_query => :environment do
9
+ puts Workarea::MagentoMigrator::CatalogCategory.select_query
10
+ end
11
+
12
+ task :restore_from_json => :environment do
13
+ Workarea::MagentoMigrator::CatalogCategory.restore_from_json
14
+ end
15
+
16
+ task :import_catagories => :environment do
17
+ Workarea::MagentoMigrator::CatalogCategory.import_catagories
18
+ Workarea::MagentoMigrator::CatalogCategory.import_content_pages
19
+ end
20
+
21
+ end
@@ -0,0 +1,9 @@
1
+ namespace :magento_migrator do
2
+ desc "Fetch customers data from magento"
3
+
4
+ task :migrate_customers => :environment do
5
+ sql_connection = Workarea::MagentoMigrator::SqlConnection.new
6
+ sql_connection.migrate_customers
7
+ end
8
+
9
+ end
@@ -0,0 +1,8 @@
1
+ namespace :magento_migrator do
2
+ desc "Fetch products data from magento"
3
+
4
+ task :migrate_products => :environment do
5
+ Workarea::MagentoMigrator::Product.execute_query
6
+ end
7
+
8
+ end
@@ -0,0 +1,14 @@
1
+ #To read csv file
2
+ require 'csv'
3
+
4
+ namespace :workarea do
5
+ desc 'Import magento CSV file content..'
6
+
7
+ task import_magento_content: :environment do
8
+ # Instantiated the ImportMagentoContent class
9
+ @import_data = Workarea::MagentoMigrator::Product.new
10
+ @import_data.read_csv_file # Calling the read_csv_file method
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,238 @@
1
+ module Workarea
2
+ module MagentoMigrator
3
+ class CatalogCategory < MagentoBase
4
+
5
+ class << self
6
+ def ids_to_include
7
+ "SELECT distinct(category_id) FROM catalog_category_product "
8
+ end
9
+
10
+ def table_name
11
+ @@table_name ||= 'catalog_category'
12
+ end
13
+
14
+ def select_taxons_query
15
+ select_query = "SELECT #{select_columns} FROM #{table_name}_entity e #{join_clause} "
16
+ select_query += "\nwhere e.entity_id not in (#{ids_to_include}) and e.parent_id>1 and e.level >1"
17
+ end
18
+
19
+ def catalog_category_menu
20
+ client.query(select_taxons_query).to_a
21
+ end
22
+
23
+ def build_taxons
24
+ cc_menu = {}
25
+ (2..6).to_a.each do |level|
26
+ statement = client.prepare(MENU_QUERY)
27
+ res = statement.execute(level, level-1)
28
+ res.to_a.map{|ccm| ccm['name']}
29
+ end
30
+
31
+ cc_menu
32
+ end
33
+
34
+ def import_content_pages
35
+ File.open("#{MagentoMigrator::Engine.root}/data/content_pages.json", "w"){ |f|
36
+ f.write(JSON.pretty_generate(catalog_category_menu))
37
+ }
38
+ end
39
+
40
+ def import_taxons(taxons)
41
+ File.open("#{MagentoMigrator::Engine.root}/data/taxons.json", "w"){ |f|
42
+ f.write(JSON.pretty_generate(taxons))
43
+ }
44
+ end
45
+
46
+ def restore_from_json
47
+ taxon_data_file = File.open("#{MagentoMigrator::Engine.root}/data/content_pages.json").read
48
+ taxon_data = JSON.parse(taxon_data_file)
49
+
50
+ category_data_file = File.open("#{MagentoMigrator::Engine.root}/data/categories.json").read
51
+ category_data = JSON.parse(category_data_file)
52
+ taxons = (taxon_data + category_data).select{|t| t['include_in_menu'] == 1 }
53
+
54
+ menus = get_taxons_structure(taxons)
55
+ import_taxons(menus)
56
+
57
+ delete_all
58
+ create_categories(category_data)
59
+ create_content_pages(taxons)
60
+ create_navigation_taxons(menus)
61
+ end
62
+
63
+ def delete_all
64
+ Workarea::Navigation::Taxon.delete_all
65
+ Workarea::Navigation::Menu.delete_all
66
+ Workarea::Catalog::Category.delete_all
67
+ Workarea::Content::Page.delete_all
68
+ end
69
+
70
+ def create_navigation_taxons(menu)
71
+ menu.each do |top_level, sub_menu|
72
+ page = Workarea::Content::Page.find_by(name: top_level)
73
+
74
+ begin
75
+ puts "creating taxon and menu for #{top_level} content::page"
76
+ taxon = Workarea::Navigation::Taxon.root.children.create!(navigable: page)
77
+ menu = Workarea::Navigation::Menu.create!(taxon: taxon)
78
+
79
+ puts "creating content and content block for menu: #{top_level}"
80
+ content = Workarea::Content.for(menu)
81
+ content.blocks.create!(type: 'taxonomy', data: { start: taxon.id, show_starting_taxon: false } )
82
+
83
+ sub_menus = sub_menu.keys
84
+ next if sub_menus.blank?
85
+ puts 'Create submenu for :'
86
+ puts sub_menus.inspect
87
+
88
+ categories = Workarea::Catalog::Category.any_in(name: sub_menus)
89
+ content_pages = Workarea::Content::Page.any_in(name: sub_menus)
90
+ puts "Categories: #{categories.map(&:name).inspect}"
91
+ puts "content_pages: #{categories.map(&:name).inspect}"
92
+
93
+ next if categories.blank? && content_pages.blank?
94
+
95
+ categories.each do |category|
96
+ taxon.children.create!(navigable: category)
97
+ end
98
+
99
+ content_pages.each do |content_page|
100
+ begin
101
+ taxon.children.create!(navigable: content_page)
102
+ rescue Exception => e
103
+ puts e.message
104
+ puts content_page.inspect
105
+ puts taxon.inspect
106
+ end
107
+ end
108
+ rescue => e
109
+ puts e.message
110
+ puts "Error creating taxon for main: #{top_level}"
111
+ end
112
+ end
113
+ end
114
+
115
+ # create content blocks for category pages
116
+ def create_content_pages(taxons)
117
+ taxons.each do |taxon|
118
+ page = Workarea::Content::Page.where(name: taxon['name']).first
119
+ if page.blank?
120
+ page = Workarea::Content::Page.create!(page_attrs(taxon))
121
+ end
122
+ content = Workarea::Content.for(page)
123
+
124
+ next if content.blocks.presence
125
+
126
+ sub_taxons = taxons.select{|t| t['parent_id'] == taxon['entity_id']}
127
+ next if sub_taxons.blank?
128
+
129
+ begin
130
+ sub_taxons.each do |sub_taxon|
131
+ category = Workarea::Catalog::Category.where(name: sub_taxon['name']).first
132
+ if category
133
+ content.blocks.build(type: :category_summary, data: {category: category.id} )
134
+ else
135
+ Workarea::Content::Page.create!(page_attrs(sub_taxon))
136
+ end
137
+ end
138
+ rescue Exception => e
139
+ puts '*' * 100
140
+ puts e.message
141
+ end
142
+
143
+ content.save!
144
+ end
145
+ end
146
+
147
+ def create_categories(category_data)
148
+ Sidekiq::Callbacks.disable do
149
+ category_data.each do |category_attr|
150
+ next if Workarea::Catalog::Category.where(name: category_attr['name']).first.present?
151
+
152
+ Workarea::Catalog::Category.create!(
153
+ name: category_attr['name'],
154
+ product_rules: [],
155
+ default_sort: Search::CategoryBrowse.available_sorts.sample
156
+ )
157
+ end
158
+ end
159
+ end
160
+
161
+ def page_attrs(taxon)
162
+ {name: taxon['name'], display_h1: taxon['h1_tag'], tag_list: ['browsing', taxon['meta_keywords']].flatten.join(', ')}
163
+ end
164
+
165
+ def get_taxons_structure(taxons)
166
+ menus = {}
167
+
168
+ l2ms = taxons.select{|t| t['level'] == 2 }
169
+ l2ms = l2ms.flatten.compact.sort_by{|a| a['position']}
170
+
171
+ l2ms.each do |l2m|
172
+
173
+ l3ms = taxons.select{|t| t['level'] == 3 && t['parent_id'] == l2m['entity_id'] }
174
+ l3ms = l3ms.flatten.compact.sort_by{|a| a['position']}
175
+
176
+ if l3ms.blank?
177
+ menus[l2m['name']] = {}
178
+ next
179
+ else
180
+ menus[l2m['name']] = {}
181
+ l3ms.map{|l3m| menus[l2m['name']][l3m['name']] = {}}
182
+
183
+ l3ms.each do |l3m|
184
+
185
+ l4ms = taxons.select{|t| t['level'] == 4 && t['parent_id'] == l3m['entity_id']}
186
+ l4ms = l4ms.flatten.compact.sort_by{|a| a['position']}
187
+
188
+ if l4ms.blank?
189
+ menus[l2m['name']][l3m['name']] = {} if menus[l2m['name']].present?
190
+ next
191
+ else
192
+
193
+ menus[l2m['name']][l3m['name']] = {}
194
+ l4ms.each{|l4m| menus[l2m['name']][l3m['name']][l4m['name']]={}}
195
+
196
+ l4ms.each do |l4m|
197
+
198
+ l5ms = taxons.select{|t| t['level'] == 5 && t['parent_id'] == l4m['entity_id']}
199
+ l5ms = l5ms.flatten.compact.sort_by{|a| a['position']}
200
+
201
+ if l5ms.blank?
202
+ menus[l2m['name']][l3m['name']][l4m['name']] = {}
203
+ next
204
+ else
205
+ l5ms.each {|l5m| menus[l2m['name']][l3m['name']][l4m['name']][l5m['name']]={}}
206
+
207
+ l5ms.each do |l5m|
208
+ l6ms = taxons.select{|t| t['level'] == 6 && t['parent_id'] == l5m['entity_id']}
209
+ l6ms = l6ms.flatten.compact.sort_by{|a| a['position']}
210
+
211
+ if l6ms.blank?
212
+ menus[l2m['name']][l3m['name']][l4m['name']][l5m['name']] = {}
213
+ next
214
+ else
215
+ l6ms.each{|l6m| menus[l2m['name']][l3m['name']][l4m['name']][l5m['name']][l6m['name']]={}}
216
+ end
217
+ end
218
+ end
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
224
+
225
+ menus
226
+ end
227
+
228
+ def import_catagories
229
+ File.open("#{MagentoMigrator::Engine.root}/data/categories.json", "w"){ |f|
230
+ f.write(JSON.pretty_generate(all.to_a))
231
+ }
232
+ end
233
+
234
+ end # class self declaration
235
+
236
+ end # class end
237
+ end
238
+ end
@@ -0,0 +1,38 @@
1
+ module Workarea
2
+ module MagentoMigrator
3
+ class CatalogProduct
4
+
5
+ COLUMNS = [
6
+ "custom_design_from", "custom_design_to", "news_from_date", "news_to_date", "special_from_date", "special_to_date", "am_giftcard_price_percent", "am_giftcard_prices", "am_open_amount_max", "am_open_amount_min", "cost", "group_price", "licensing_fee", "minimal_price", "msrp", "price", "special_price", "tier_price", "weight", "am_allow_message", "am_allow_open_amount", "am_giftcard_code_set", "am_giftcard_lifetime", "am_giftcard_price_type", "am_giftcard_type", "commercial_quote_materials", "featured", "form_materials", "is_recurring", "links_exist", "links_purchased_separately", "manufacturer", "material", "needs_editorial_approval", "new", "old_id", "orientation", "package_type", "price_type", "price_view", "scalable_pattern", "shipment_type", "sku_type", "status", "style", "tax_class_id", "visibility", "weight_type", "category_ids", "created_at", "has_options", "required_options", "sku", "updated_at", "am_giftcard_code_image", "colors", "custom_layout_update", "description", "meta_keyword", "recurring_profile", "search_tags", "searchindex_weight", "short_description", "am_email_template", "artist_name", "country_of_manufacture", "cs_sort_order", "custom_design", "feed_dimensions", "feed_product_image", "gallery", "gift_message_available", "height", "image", "image_label", "links_title", "media_gallery", "meta_description", "meta_title", "msrp_display_actual_price_type", "msrp_enabled", "name", "number_of_sales", "options_container", "package_depth", "package_height", "package_width", "page_layout", "rating", "rf123_id", "rf123_url", "sale_price", "samples_title", "small_image", "small_image_label", "small_price", "thumbnail", "thumbnail_label", "url_key", "url_path", "width"
7
+ ]
8
+
9
+ def read_csv_file
10
+ # parsing the magento csv file
11
+ file = "lib/data/product_catalog_from_magento.csv"
12
+ csv = CSV.read(file)
13
+ # get the column
14
+ puts col = csv[0].inspect
15
+ # get the row
16
+ puts row = csv[1].inspect
17
+ puts convert_to_workarea_product(row)
18
+ end
19
+
20
+ def convert_to_workarea_product(row) # defined a method to do the mapping job
21
+ murals_product = []
22
+ murals_product << row
23
+ puts murals_product.inspect
24
+ # murals_product.to_csv(file_name: 'workarea_product_data.csv')
25
+ # Import the file to workarea
26
+ Workarea::DataFile::Import.create(file_name: 'murals_product', file_type: 'csv')
27
+ end
28
+
29
+ class << self
30
+
31
+ def table_name
32
+ @@table_name ||= 'catalog_product'
33
+ end
34
+
35
+ end # class self declaration
36
+ end # class end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ require 'workarea/magento_migrator'
2
+
3
+ module Workarea
4
+ module MagentoMigrator
5
+ class Engine < ::Rails::Engine
6
+ include Workarea::Plugin
7
+ isolate_namespace Workarea::MagentoMigrator
8
+ end
9
+ end
10
+ end