bug fix in import from ps files
This commit is contained in:
parent
b90d401155
commit
95b5732512
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# encoding: UTF-8
|
|
||||||
|
|
||||||
ENV["RAILS_ENV"] ||= "development"
|
ENV["RAILS_ENV"] ||= "development"
|
||||||
require File.dirname(__FILE__) + "/../config/environment"
|
require File.dirname(__FILE__) + "/../config/environment"
|
||||||
|
|
@ -7,13 +6,13 @@ require File.dirname(__FILE__) + "/../config/environment"
|
||||||
# import categories data from old presta shop
|
# import categories data from old presta shop
|
||||||
|
|
||||||
class PsCategory < ApplicationRecord
|
class PsCategory < ApplicationRecord
|
||||||
self.table_name = 'ps_category'
|
self.table_name = 'ps_category'
|
||||||
establish_connection :prestashop_old
|
establish_connection :prestashop_old
|
||||||
end
|
end
|
||||||
|
|
||||||
class PsCategoryLang < ApplicationRecord
|
class PsCategoryLang < ApplicationRecord
|
||||||
self.table_name = 'ps_category_lang'
|
self.table_name = 'ps_category_lang'
|
||||||
establish_connection :prestashop_old
|
establish_connection :prestashop_old
|
||||||
end
|
end
|
||||||
|
|
||||||
pcls = PsCategoryLang.where('id_lang = 3')
|
pcls = PsCategoryLang.where('id_lang = 3')
|
||||||
|
|
@ -22,7 +21,7 @@ for pcl in pcls
|
||||||
if category.blank?
|
if category.blank?
|
||||||
pc = PsCategory.where('id_category = ?',pcl.id_category).first
|
pc = PsCategory.where('id_category = ?',pcl.id_category).first
|
||||||
if !pc.blank?
|
if !pc.blank?
|
||||||
cat = Category.new(parent_id: pc.id_parent, level_depth: pc.level_depth, active: pc.active, name: pcl.name, created_by: current_admin.id, updated_by: current_admin.id)
|
cat = Category.new(parent_id: pc.id_parent, level_depth: pc.level_depth, active: pc.active, name: pcl.name, created_by: 1, updated_by: 1)
|
||||||
cat.id = pc.id_category
|
cat.id = pc.id_category
|
||||||
cat.save
|
cat.save
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,27 +8,27 @@ require File.dirname(__FILE__) + "/../config/environment"
|
||||||
# images needs to be stored in public/tmp/original
|
# images needs to be stored in public/tmp/original
|
||||||
|
|
||||||
class PsImage < ApplicationRecord
|
class PsImage < ApplicationRecord
|
||||||
self.table_name = 'ps_image'
|
self.table_name = 'ps_image'
|
||||||
establish_connection :prestashop_old
|
establish_connection :prestashop_old
|
||||||
end
|
end
|
||||||
|
|
||||||
ps_images = PsImage.order('id_image')
|
ps_images = PsImage.order('id_image')
|
||||||
path = "#{Rails.root}/public/tmp/original/"
|
path = "#{Rails.root}/public/tmp/original/"
|
||||||
for pi in ps_images
|
ps_images.each do |pi|
|
||||||
file = "#{path}#{pi.id_product}-#{pi.id_image}.jpg"
|
file = "#{path}#{pi.id_product}-#{pi.id_image}.jpg"
|
||||||
puts "#{file} - #{File.exist?(file)}"
|
puts "#{file} - #{File.exist?(file)}"
|
||||||
if File.exist?(file)
|
if File.exist?(file)
|
||||||
image = Image.new
|
image = Image.new
|
||||||
f = File.open(file)
|
f = File.open(file)
|
||||||
image.image = f
|
image.image = f
|
||||||
f.close
|
f.close
|
||||||
image.imageable_type = "Product"
|
image.imageable_type = "Product"
|
||||||
image.imageable_id = pi.id_product
|
image.imageable_id = pi.id_product
|
||||||
image.position = pi.position
|
image.position = pi.position
|
||||||
image.cover = pi.cover
|
image.cover = pi.cover
|
||||||
image.updated_by = 1
|
image.updated_by = 1
|
||||||
image.active = true
|
image.active = true
|
||||||
image.save
|
image.save
|
||||||
puts "saved: #{image.id}"
|
puts "saved: #{image.id}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ pcls.each do |pcl|
|
||||||
product = Product.where(id: pcl.id_product).first
|
product = Product.where(id: pcl.id_product).first
|
||||||
if product.blank?
|
if product.blank?
|
||||||
pc = PsProduct.where('id_product = ?', pcl.id_product).first
|
pc = PsProduct.where('id_product = ?', pcl.id_product).first
|
||||||
if !pc.blank?
|
unless pc.blank?
|
||||||
prod = Product.new(description: pcl.description, description_short: ActionController::Base.helpers.strip_tags(pcl.description_short), default_category_id: pc.id_category_default,
|
prod = Product.new(description: pcl.description, description_short: ActionController::Base.helpers.strip_tags(pcl.description_short), default_category_id: pc.id_category_default,
|
||||||
price: pc.price, quantity: pc.quantity, active: pc.active, name: pcl.name, created_by: current_admin.id, updated_by: current_admin.id)
|
price: pc.price, quantity: pc.quantity, active: pc.active, name: pcl.name, created_by: 1, updated_by: 1)
|
||||||
prod.id = pc.id_product
|
prod.id = pc.id_product
|
||||||
prod.save
|
prod.save
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ Rails.application.configure do
|
||||||
# require 'syslog/logger'
|
# require 'syslog/logger'
|
||||||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
||||||
|
|
||||||
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
if ENV['RAILS_LOG_TO_STDOUT'].present?
|
||||||
logger = ActiveSupport::Logger.new(STDOUT)
|
logger = ActiveSupport::Logger.new(STDOUT)
|
||||||
logger.formatter = config.log_formatter
|
logger.formatter = config.log_formatter
|
||||||
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
||||||
|
|
@ -106,10 +106,10 @@ Rails.application.configure do
|
||||||
full_path = Rails.application.assets.resolve(path).to_path
|
full_path = Rails.application.assets.resolve(path).to_path
|
||||||
app_assets_path = Rails.root.join('app', 'assets').to_path
|
app_assets_path = Rails.root.join('app', 'assets').to_path
|
||||||
if full_path.starts_with? app_assets_path
|
if full_path.starts_with? app_assets_path
|
||||||
puts "including asset: " + full_path
|
puts 'including asset: ' + full_path
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
puts "excluding asset: " + full_path
|
puts 'excluding asset: ' + full_path
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue