-
Notifications
You must be signed in to change notification settings - Fork 2
Magento Rest Client
The Imixs-Magento-Adapter is a connector module providing a set of classes to connect to the Ecommerce Softwareplattform Magento. The module connects Imixs-Workflow with the Magento Rest API. For authentication Magento uses the OAuth 1.0.a protocol. See the Magento API documentation for further information.
The Imixs-Magento-Adapter provides Java Beans to connect with the Magento Rest API. The MagentoService EJB provides a set of methods to be used by any business application based on the Imixs Marty project. To integrate a business process with Magento the MagentoPlugin can be added into a Imixs Workflow Model.
The Imixs-Magento-Adapter can be configured by the imixs.property file or the imixs PropertyService . The following example shows a typical configuration of the imixs.properties including the OAuht access keys:
##############################
# Magento REST Service Configuration
##############################
# magento host
magento.uri-basis=http://localhost/magento/index.php/
magento.uri-api=http://localhost/magento/api/rest
# OAuth consumer token
magento.token.consumer-key=7ec2d5c3ef2ad29d.......
magento.token.consumer-secret=19002a261f4b4........
# OAuth access token...
magento.token.access-key=m0scpjq3wsje9......
magento.token.access-secret=e05b4m4p8b9n....
# optional
magento.debug=true
To access the Magento Rest API it is necessary to configure the OAuth based access module from Magento. First you need to create a consumer token in Magento Admin Interface to be used by your Workflow application. With the consumer token you can generate an access token. Both tokens (consumer and access) are necessary to authenticate a third party application like Imixs-Workflow.
The Imixs-Magento-Adapter project provides a set of methods to generate a valid access token. For easy usage the junit Test class 'org.imixs.workflow.magento.test.TestMagentoPlugin' can be used to generate a valid access token by calling the test method 'testRequestNewToken()'. If you run this test the MagentoService EJB requests a new access token in an interactive way. Before you start the test method make sure hat the properties 'magento.uri-basis', 'magento.token.consumer-key' and 'magento.token.consumer-secret' are configured by the imixs.properties file!.
Running the test will print a request URL to call from a web Browser. Then you can login into Magento and gain the access. The verifier need to be entered into the live console. After that a new access token (key and secret) will be generated. See the following example of a test run:
Open Browser Window and authorize the Imixs MagentoPlugin here:
http://localhost/magento/index.php/admin/oauth_authorize?oauth_token=261a3514776fbaeef56xxxxxxxx
And paste the verifier here
>>949775df82a747d09b72exxxxxxxxxx
Got the Access Token!
key=7ec2d5c3ef2ad29d5519773dd0537a44
secret=19002a261f4b42a0d4b86388757fa2b4
To run further tests the key and secret generated by the JUnit test need to be entered into the properties 'magento.token.access-key' and 'magento.token.access-secrete' of imixs.porperties file.
The EJB org.imixs.workflow.magento.MagentoService provides several methods to access the Magento Rest API. The service EJB is also used by the MagentoPlugin class. The service initialize the OAuth Data to access the Magento Web Service Rest API. There for the EJB uses the Scribe library. The configuration can be stored in a config Entity 'ConfigMagento' or in the imixs.properties file. The configuration is read during the @PostConstruct call back method. The method getService() returns a OAuthService object which can be used to interact in a flexible way with the OAuth Service.
If a workitem is based on the import of a magento order the order id is stored in the property 'txtName' in the following format:
magento:order:ID
All properties of the magento order are stored in properties with the prafix 'm_'.
The class org.imixs.workflow.magento.MagentoPlugin synchronizes the Order Data of a worktiem and creates the following workitem attributes:
-
txtMagentoCustomer=combined magento customer name (First- and Lastname)
-
txtMagentoCustomerEmail = E-Mail address of customer
-
txtMagentoOrderID = Order id of magento order
-
txtMagentoBillingFirstname = Firstname of Billing address
-
txtMagentoBillingLastname = Lastname of Billing address
-
txtMagentoBillingTelephone = telephone of Billing address
-
txtMagentoBillingCompany = company of Billing address
-
txtMagentoBillingstreet = String of Billing address
-
txtMagentoBillingPostcode = Postcode of Billing address
-
txtMagentoBillingCity = City of Billing address
-
txtMagentoShippingFirstname = Firstname of Shipping address
-
txtMagentoShippingLastname = Lastname of Shipping address
-
txtMagentoShippingTelephone = telephone of Shipping address
-
txtMagentoShippingCompany = company of Shipping address
-
txtMagentoShippingstreet = String of Shipping address
-
txtMagentoShippingPostcode = Postcode of Shipping address
-
txtMagentoShippingCity = City of Shipping address
The MagentoSchedulerService implements a Timer EJB to import order items from Magento. The EJB can be configured through the config entity 'Type=ConfigMagento'. The JSF page /pages/admin/magento.xthml and the MagentoController provides a way to easy configure the timer in the web frontend of Imixs-Office-Workflow.
When a new order is imported or updated the scheduler calls the activityID 800. This activity should be definend in every status the order should be updated.
The EJB MagentoCache provides a caching mechanism to cache products and customer entities. This EJB is used by the MagentoService. The config property 'magento.cache.refresh' defines the maximal time in seconds a magento object is cached. If an object is older then the refresh time the object will be refetched by the MagentoService.
magento.cache.refresh=600
The method flush() provides a way to force the flush of older items. This method is called automatically by the MagentoScheduelerService. To clear the cache the method clear() can be called.