Last active
August 4, 2016 18:04
-
-
Save candidosales/6a9c84e4b50458fcf5bbb61934d7e886 to your computer and use it in GitHub Desktop.
[Rake task] Atualizar adicionando uma descrição nos produtos do Spree - Incluir o arquivo na pasta lib/tasks do seu projeto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :update_products do | |
desc "update_products" | |
task :description => :environment do | |
skus = ["ABR112803","ABR112903","ABR112703","ABR101703","ABR101903","ABR102303","ABR109203","ABR113403","ABR112806","ABR100803","ABR10103","ABR112906","ABR113003","ABR113103","ABR100903","ABR101303","ABR101403","ABR101503","ABR102103","ABR109003","ABR112503","ABR113203","ABR89603","ABR84703","ABR102506","ABR112706","ABR101706","ABR101906","ABR102306","ABR109206","ABR113406","ABR112812","ABR100806","ABR112912","ABR113006","ABR113106","ABR100906","ABR101006","ABR101306","ABR101406","ABR101506","ABR102106","ABR10906","ABR112506","ABR113206","ABR89606","ABR84706","ABR89303","ABR102512","ABR10003","ABR112712","ABR101912","ABR102312","ABR105503","ABR109212","ABR113412","ABR100812","ABR113012","ABR113112","ABR101012","ABR101312","ABR101512","ABR102112","ABR109012","ABR112512","ABR113212","ABR101712","ABR88303","ABR100912","ABR89612","ABR101412","ABR84712","ABR89306","ABR100006","ABR105506","ABR88306","ABR89312","ABR100012","ABR105512","ABR88312"] | |
skus_success = [] | |
skus_fail = [] | |
description_new = "<b>O link para acessar a sua assinatura digital será enviado para o seu e-mail.</b>" | |
skus.each{ |sku| | |
spree_variant = Spree::Variant.find_by(sku: sku) | |
if !spree_variant.blank? | |
spree_variant.product.description = "#{spree_variant.product.description} #{description_new}" | |
if spree_variant.product.save | |
skus_success << sku | |
end | |
else | |
skus_fail << sku | |
end | |
} | |
if skus_success.count > 0 | |
puts "SUCESSO (#{skus_success.count}): #{skus_success.join(', ')}" | |
puts "---------------------------------------------------------" | |
end | |
if skus_fail.count > 0 | |
puts "FALHA (#{skus_fail.count}): #{skus_fail.join(', ')}" | |
puts "---------------------------------------------------------" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment