Skip to content

Instantly share code, notes, and snippets.

@untwal
Last active May 17, 2020 14:21
Show Gist options
  • Save untwal/cb35449a4b15b32ae12f76c68f417ca6 to your computer and use it in GitHub Desktop.
Save untwal/cb35449a4b15b32ae12f76c68f417ca6 to your computer and use it in GitHub Desktop.
brand_and_catalog_numbers = {
'Bella + Canvas' => ['BST323', 'BST323C'],
'Bayside' => ['1900J1'],
'LAT' => ['J0041', 'J0042'],
'Rabbit Skins' => ['J0051', 'J0052'],
'US Blanks' => ['USFM47'],
'Next Level' => ['NLM100', 'NLM101']
}
brand_and_catalog_numbers.each do |brand_name, catalog_numbers|
brand = Spree::Brand.find_by_name(brand_name)
new_brand_name = "#{brand.name} FC"
ActiveRecord::Base.transaction do
new_brand = Spree::Brand.where(name: new_brand_name).first_or_create do |new_brand|
new_brand.logo = brand.logo
new_brand.map_discount_percent = brand.map_discount_percent
new_brand.active = brand.active
new_brand.exclusive = brand.exclusive
new_brand.brand_family_id = new_brand.brand_family_id
new_brand.category = brand.category
end
products = Spree::Product.where(catalog_number: catalog_numbers)
products.update_all(brand_id: new_brand.id)
products.ids.each { |product_id| RefreshProductCacheWorker.perform_async(product_id) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment