h1. Magja
"Magja":http://code.google.com/p/magja/ is a Java Connector for Magento's API
The goal its build a java interface to access the Magento API and exchange data.
h2. Getting Started
h2. RSS Feed
Stay up to date with "Magja RSS Feed":http://code.google.com/feeds/p/magja/updates/basic
h2. Create the Magento Connection Properties File
Create the file @/src/main/resources/magento-api.properties@ (or in your default classpath) with your proper data to magento installation, for example:
bc.. # connection to magento parameters magento-api-username=yourMagentoApiUser magento-api-password=youtMagentoApiPassword magento-api-url=http://localhost/magento/index.php/api/soap/
default-attribute-set-id=4
default-root-category-id=2
h2. Magja Console
Make sure you have created @magento-api.properties@ file as described above.
Usage:
bc.. ./magja-console
import collection.JavaConversions. import com.google.code.magja.soap. import com.google.code.magja.model.customer. import com.google.code.magja.service. import com.google.code.magja.service.customer._
h3. Category
Get only the basic information of a Category, without its dependencies:
bc. val category = RemoteServiceFactory.getCategoryRemoteService.getByIdClean(2) println(category)
Get category with its children:
bc. val category = RemoteServiceFactory.getCategoryRemoteService.getByIdWithChildren(2) category.getChildren.foreach(c => println(c.getId + " " + c.getName))
Get category with its parent:
bc. val category = RemoteServiceFactory.getCategoryRemoteService.getByIdWithParent(2) println(category.getParent)
Get category with its parent and children:
bc. val category = RemoteServiceFactory.getCategoryRemoteService.getByIdWithParentAndChildren(2)
h3. Product
bc. import com.google.code.magja.model.product._
h4. Listing Products
List all products with dependencies (slower)
bc. val products = RemoteServiceFactory.getProductRemoteService.listAll
List all products without dependencies (faster)
bc. val products = RemoteServiceFactory.getProductRemoteService.listAllNoDep
h4. Create Product
bc.. import com.google.code.magja.model.product. import com.google.code.magja.model.category.
val product = new Product product.setSku("DUMMYPRD") product.setName("Lovely Umbrella") product.setShortDescription("This is a short description") product.setDescription("This is a description for Product") product.setPrice(250.99) product.setCost(100.22) product.setEnabled(true) product.setWeight(0.500) product.setType(ProductTypeEnum.SIMPLE.getProductType) product.setAttributeSet(new ProductAttributeSet(4, "Default")) product.setMetaDescription("one two tree") product.setGoogleCheckout(true)
// category product.setCategories(List(new Category(2)))
// websites - set the website for product product.setWebsites(Array(1))
// inventory - set the inventory for product product.setQty(20) product.setInStock(true)
// Optional: you can set the properties not mapped like the following too: product.set("meta_description", "one two tree")
// then, we just instanciate the service to persist the product RemoteServiceFactory.getProductRemoteService.save(product)
h3. Customer
bc. val customerRemoteService = RemoteServiceFactory.getCustomerRemoteService val customers = customerRemoteService.list customers.foreach(c => println(c.getFirstName + " " + c.getEmail))