Skip to content
Browse files

after_variant_saved hook

  • Loading branch information...
1 parent ad6c61c commit 801289c9127b93c71217fe6133cda288ca56613c @jzw committed Aug 15, 2011
Showing with 13 additions and 4 deletions.
  1. +13 −4 app/models/product_import.rb
View
17 app/models/product_import.rb
@@ -65,13 +65,18 @@ def import_data!
if p = Product.find(:first, :conditions => ["#{field} = ?", row[col[field.to_sym]]])
p.update_attribute(:deleted_at, nil) if p.deleted_at #Un-delete product if it is there
p.variants.each { |variant| variant.update_attribute(:deleted_at, nil) }
- create_variant_for(p, :with => product_information)
+ v = create_variant_for(p, :with => product_information)
else
- next unless create_product_using(product_information)
+ next unless p = create_product_using(product_information)
+ v = p.master
end
else
- next unless create_product_using(product_information)
+ next unless p = create_product_using(product_information)
+ v = p.master
end
+
+ after_variant_saved(v, product_information)
+
end
if IMPORT_PRODUCT_SETTINGS[:destroy_original_products]
@@ -138,6 +143,7 @@ def create_variant_for(product, options = {:with => {}})
#Log a success message
log("Variant of SKU #{variant.sku} successfully imported.\n")
+ return variant
else
log("A variant could not be imported - here is the information we have:\n" +
"#{pp options[:with]}, :error")
@@ -210,7 +216,7 @@ def create_product_using(params_hash)
#Log a success message
log("#{product.name} successfully imported.\n")
end
- return true
+ return product
end
# get_column_mappings
@@ -337,5 +343,8 @@ def associate_product_with_taxon(product, taxonomy, taxon_hierarchy)
# end
def after_product_built(product, params_hash)
end
+
+ def after_variant_saved(variant, params_hash)
+ end
end

0 comments on commit 801289c

Please sign in to comment.
Something went wrong with that request. Please try again.