Friday, January 25, 2008

Ofbiz - Opentaps cheatsheet


1. Download Ofbiz

2. Setup database (http://www.opentaps.org/index.php?option=com_content&task=view&id=37&Itemid=62)

3. run ant run-install (to install both demo and seed data). In the production env do not install demo data. Just seed data should be fine

Writing your first entity def and service def

IMPORTANT!! All the services property declared are loaded and available to run by all the means service can be run. In other words services are globally accessible. The way to run them is described below. Also all the available services can be seen from webtools->services tab in opentaps.

1. Look at the documentation on ofbiz wiki about Entity Engine guide and Service Engine guide, also see tutorials from Si Chen

2. Once you have ofbiz component either existing or newly created - make sure entitydef and servicedef directories have related files (entity_group.xml and entitymodel_*.xml in entitydef directory and *services.xml in servicedef directory. Also make sure the entries for these 3 files exist in ofbiz_component.xml otherwise they wont be picked up automatically.

3. Once you define your service and entity defs, you can see them listed under webtools. If the entity names in your entitymodel_*.xml conflicts with the existing ones (duplicate names) whichever component is loaded last will overwrite the entity definition. You can check the definition from webtools.

4. To run the service

a. From webtools - click Service Reference link - find your service and on the top left click run service. It will ask you for input params corresponding to the ones declared in services.xml file in servicedef directory and upon successful execution will show the return arguments.

b. From beanshell - easiest way would be to use http interface of the beanshell if the port is not blocked by the firewall - the default port is 9989 - URL is http://localhost:9989/remote/jconsole.html. Download and run bshcontainer.bsh (http://www.opensourcestrategies.com/ofbiz/hello_world3.php) script so you have access to delegator, dispatcher and other ofbiz specific classes. Then call delegator.runSync("service_name", params)

c. From telnet session to beanshell - same as described in b except step b uses http interface

d. From any of the existing bsh scripts.

Shipping configuration

Modify shipment.properties file under product/config - add all the carrier specific information

Make sure you link your Product Store with the facility. Also make sure Facility has Postal Address which is tagged as atleast ship from address. Note: it is strange but the product doesnt have to be linked to the facility for this product store, even though there is facility tab for product!!

To configure UPS rate service to get the shipping charges, in your product store you need to add a shipping method (carrier method) with the service name field on the page set to upsRateEstimate. You can also add various ShippingEstimate values, the final shipping charge will be calculated based on the shipping rate using the UPS rate service and the formula displayed on the shipping estimate tab of product store.

Payment setup:

1. For CC and Paypal payments modify applications/accounting/config/payment.properties file with correct settings

2. From the catalog manager, Setup paypal payment as external service and setup authorize.net capture and authorize services with the service names specified in the production setup guide

Data Import:

1. Take a look at DemoProduct.xml file for product, category, facility, product store and website creation data.

2. Since the Id fields for PK are varchar - to avoid potential conflict with existing data, try using alpha numeric ids in the seed data or use delegator.getNextSeqId() with the sequence name. Create new or use existing sequence from SEQUENCE_VALUE_ITEM table. Word about sequence ids... For each sequence name, a bank of 10 sequence ids are created, once those are exhausted another set of 10 are created. Server restart will cause these "banked" ids to be lost and next set of bank will be created. To override default sequence id creation - take a look at SequenceUtil.java, GenericDelegator.java and other related classes.

3. If the products to be imported has SKU, ISBN, Mfg Ids use GoodIdentificationTypeIds - look at GoodIdentification and GoodIdentificationType tables.

Tax payment setup:

For CA tax

Generic Delegator Important notes

1. Generic Delegators are defined and created from the entityengine.xml file. There is a default delegator defined out of the box.

2. delegator.makeValue() is used when you absolutely know that all the fields passed belong to the entity vs. makeValidValue() is forgiving and will only take the values corresponding to the fields of the entity and ignore the rest