diff --git a/bin/import_categories_from_ps.rb b/bin/import_categories_from_ps.rb index 3d8c744..cab59c7 100644 --- a/bin/import_categories_from_ps.rb +++ b/bin/import_categories_from_ps.rb @@ -1,5 +1,4 @@ #!/usr/bin/env ruby -# encoding: UTF-8 ENV["RAILS_ENV"] ||= "development" require File.dirname(__FILE__) + "/../config/environment" @@ -7,13 +6,13 @@ require File.dirname(__FILE__) + "/../config/environment" # import categories data from old presta shop class PsCategory < ApplicationRecord - self.table_name = 'ps_category' - establish_connection :prestashop_old + self.table_name = 'ps_category' + establish_connection :prestashop_old end class PsCategoryLang < ApplicationRecord - self.table_name = 'ps_category_lang' - establish_connection :prestashop_old + self.table_name = 'ps_category_lang' + establish_connection :prestashop_old end pcls = PsCategoryLang.where('id_lang = 3') @@ -22,7 +21,7 @@ for pcl in pcls if category.blank? pc = PsCategory.where('id_category = ?',pcl.id_category).first 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.save end diff --git a/bin/import_images_from_ps.rb b/bin/import_images_from_ps.rb index 96e7d4b..1ccf13d 100644 --- a/bin/import_images_from_ps.rb +++ b/bin/import_images_from_ps.rb @@ -8,27 +8,27 @@ require File.dirname(__FILE__) + "/../config/environment" # images needs to be stored in public/tmp/original class PsImage < ApplicationRecord - self.table_name = 'ps_image' - establish_connection :prestashop_old + self.table_name = 'ps_image' + establish_connection :prestashop_old end ps_images = PsImage.order('id_image') path = "#{Rails.root}/public/tmp/original/" -for pi in ps_images - file = "#{path}#{pi.id_product}-#{pi.id_image}.jpg" - puts "#{file} - #{File.exist?(file)}" - if File.exist?(file) - image = Image.new - f = File.open(file) - image.image = f - f.close - image.imageable_type = "Product" - image.imageable_id = pi.id_product - image.position = pi.position - image.cover = pi.cover - image.updated_by = 1 - image.active = true - image.save - puts "saved: #{image.id}" - end +ps_images.each do |pi| + file = "#{path}#{pi.id_product}-#{pi.id_image}.jpg" + puts "#{file} - #{File.exist?(file)}" + if File.exist?(file) + image = Image.new + f = File.open(file) + image.image = f + f.close + image.imageable_type = "Product" + image.imageable_id = pi.id_product + image.position = pi.position + image.cover = pi.cover + image.updated_by = 1 + image.active = true + image.save + puts "saved: #{image.id}" + end end diff --git a/bin/import_products_from_ps.rb b/bin/import_products_from_ps.rb index a7c97d8..90d6978 100644 --- a/bin/import_products_from_ps.rb +++ b/bin/import_products_from_ps.rb @@ -20,9 +20,9 @@ pcls.each do |pcl| product = Product.where(id: pcl.id_product).first if product.blank? 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, - 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.save end diff --git a/config/environments/production.rb b/config/environments/production.rb index 6429761..d382344 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -93,7 +93,7 @@ Rails.application.configure do # require 'syslog/logger' # 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.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) @@ -106,10 +106,10 @@ Rails.application.configure do full_path = Rails.application.assets.resolve(path).to_path app_assets_path = Rails.root.join('app', 'assets').to_path if full_path.starts_with? app_assets_path - puts "including asset: " + full_path + puts 'including asset: ' + full_path true else - puts "excluding asset: " + full_path + puts 'excluding asset: ' + full_path false end else