The impex torture is over guys! Enjoy your hybris projects with a nice ruby api for impex generation!
Simpex will make your life easier because:
- it will remove the “csv noise” from your eyes
- let you focus on the important stuff, building relationships between your impex tables
- process any incoming format like xml, excel, csv with the power of ruby
- do basic impex validations for you before hybris does it: asserting number of attributes and values, asserting the presense of macros
- handle huge file sets and write to a file after 20000 entries in the whole tree ( set @memory_safe = true and setup the max_type_entries_in_tree all in the impex_result.rb)
- generate the right files names with right index numbers so hyris can process them in the right order
- simpex is bullet proof and was used and developed for a huge ecommerce project in cooperation with namics.com
Ready? Here it comes:
product_type = Type.new(“Product”, %w{code[unique=true] name[lang=en] name[lang=de] unit(code) $catalogVersion supercategories(code)})
product = TypeEntry.new(product_type, %w{555 myproduct555 meinproduct555 pieces SimpexProducts:Online SampleCategory})
assert_equal “555”, product.code
assert_equal “pieces”, product.unit
assert_equal “SampleCategory”, product.supercategories
Never worry about the order of rows any more just create a hash specifying the attributes:
product2 = TypeEntry.new(product_type, {"code" => “333”, “name” => "MyName"})
Just use full string attribute names for ambigious attributes like
assert_equal “myproduct555”, product.get(“name[lang=en]”)
assert_equal “meinproduct555”, product.get(“name[lang=de]”)
Now lets build some real references:
catalog_type = Type.new(“Catalog”, %w{id[unique=true] name[lang=de] name[lang=en] defaultCatalog})
#now create a catalog, by giving the type ‘catalog_type’ to the constructor, it will be registered for the future generation
catalog = TypeEntry.new(catalog_type, %w{simpex_catalog SimpexCatalog SimpexCatalog true})
catalog_version_type = Type.new(“CatalogVersion”, %w{catalog(id)[unique=true] version[unique=true] active defaultCurrency(isocode)})
catalog_version = TypeEntry.new(catalog_version_type, [catalog.id, “online”, “true”, “EUR”, “de,en”])
Now add averything to a main object managing the files creation:
result = ImpexResult.new(“your/impex/folder”)
#Each type, containts all the entries for this type, so entries are listed there for generation, now you just have to add the types to the result
result << catalog_type
result << product_type
#now lets generated the result, memory leaks will be avoiaded by not exeeding more than 2000 entries in a type
result.impexify # => will write separate files for each type
result.impexify(“basic_setup.csv”) # => will write all tables to one file in the folder your/impex/folder
Thats it!
rvm install 1.9.1
cd to directory and run bundle install
For now it only generates a dummy ImpEx file.
Run rake simpex:generate
You can find the generated file in ‘tmp/’
Run rake simpex:test to execute all tests