Create orders using SAP Commerce Cloud Restful API
Recently Jerry is working on an integration project about creating orders in Wechat platform by consuming SAP Commerce Cloud Restful API.
Consultants who didn't touch SAP Commerce before(such as Jerry ) might get confused once they saw the search result by key word "commerce" in :
Several products with similar name are listed in search result.
- SAP Commerce:SAP commerce solution based on On-Premises deployment approach
- SAP Commerce Cloud on SAP Infrastructure & SAP Commerce Cloud on Public Cloud: as their names give a very clear hint: both are SAP Commerce solution based on cloud, and differentiated by the underlying cloud infrastructure the solution are running. SAP Commerce Cloud on SAP Infrastructure are sometimes called Commerce Cloud Version One and CCV1 for short, while the latter called CCV2.
There is a nice blog Two clouds in practice: a comparison of SAP Commerce Cloud v1 and v2in medium comparing both.
Back to my task, it's helpful if we play around in Commerce Cloud storefront UI to create a order manually to get ourselves familar with the process.
Log in to storefront and browse the site:
And identify a favourite product and add it to cart by pressing button "ADD TO CART":
Press CHECK OUT to proceed:
Now we get a cart ID:
Maintain shipping address:
Maintain payment details:
Once Place Order button is clicked, the order is successfully created with an automatically populated order ID:
In summary, the process of order manual creation in SAP Commerce Cloud consists of five steps:
(1) create a Shopping Cart
(2) add products into the cart
(3) maintain shipping address to the cart
(4) maintain payment details to the cart
(5) execution place order action on the cart to get order created
Now we should figure out for each step, what exactly APIs should be called.
Go to , search by keyword "Commerce Cloud", and it's easy to find the supported API list there.
Jerry has written a simple nodejs application to demonstrate how to consume such APIs to create orders in SAP Commerce Cloud. The whole source code is uploaded to my github.
Execute the application, and we can observe the successflly created order with its ID in callback function in line 20:
Search the ID in Commerce Cloud backoffice UI to check the details of created order.
As introduced before, it's necessary to go through five steps to have an order generated. And in Jerry's project there are totally seven "step.js" implementation files, why?
For the additional two step.js, one is for access token retrieve and the other for cart delivery mode set operation. Access token will be appended to the header fields of all the subsequent API calls for authorization purpose. And the cart delivery mode will be set implicitly if performed in storefront UI via browser whereas an explicit API call is necessary in our case. As a result totally seven HTTP roundtrip is needed in API consumption case.
The access token fetch is implemented by following OAuth protocol: send the OAuth Client ID and secret to SAP Commerce Cloud OAuth endpoint to get the issued access token.
First we have to create a new OAuth Client in SAP Commerce Cloud backoffice:
Then in file "step1_get_token.js", send a HTTP POST to Commerce Cloud Authentication endpoint to request access token:
For privacy reason I didn't upload urlconfig.js to github which contains the dedicated url of my own Commerce Cloud API endpoint. Instead I upload the template file: urlconfigTemplate.js. Just replace the place holder marked with "<>" with your actual value there, rename the template file back to urlconfig.js. After that you can create orders in your own Commerce Cloud tenant.
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2661539/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何通過Restful API的方式讀取SAP Commerce Cloud的Product ReferenceRESTAPICloud
- 如何通過Restful API的方式讀取SAP Commerce Cloud的Product圖片RESTAPICloud
- SAP Commerce Cloud OCC API UnknownResourceError 錯誤CloudAPIError
- SAP Marketing Cloud Restful API SDK 使用案例分享CloudRESTAPI
- SAP Commerce Cloud 裡的 Site API 呼叫方式講解CloudAPI
- SAP Commerce Cloud 架構概述Cloud架構
- SAP Commerce Cloud 的 Security 策略概述Cloud
- 使用 Recipe 安裝 SAP Commerce CloudCloud
- SAP Commerce Cloud SmartEdit 的安裝Cloud
- 如何使用API的方式消費SAP Commerce Cloud的訂單服務APICloud
- 如何使用 API 的方式消費 SAP Commerce Cloud 的訂單服務APICloud
- SAP Commerce Cloud Build Manifest ComponentsCloudUI
- SAP Commerce Cloud 專案 Spartacus 入門Cloud
- SAP Commerce Cloud OAuth 實現介紹CloudOAuth
- 給 SAP Commerce Cloud Storefront 設定 endpointCloud
- SAP Commerce Cloud SmartEdit 學習筆記Cloud筆記
- 如何用 SAP Commerce Cloud CMS API 批次返回多個 CMS Component 資料CloudAPI
- 如何在 SAP Commerce Cloud Portal 構建和部署 SAP Spartacus StorefrontCloud
- SAP Commerce Cloud Github 倉庫管理規範CloudGithub
- 如何構建和部署 SAP Commerce Cloud 專案Cloud
- SAP Commerce Cloud Product Review 的新增邏輯CloudView
- SAP Commerce Cloud 裡的 Media 概念簡述Cloud
- 什麼是 SAP Commerce Cloud 的 catalogCloud
- SAP Commerce Cloud Spartacus UI 修改 primary color 的方法CloudUI
- SAP Commerce Cloud ASM 模組的登入過程CloudASM
- SAP Commerce Cloud 裡的 Solr 架構簡介CloudSolr架構
- SAP Commerce Cloud 的 Product Carousel Component 介紹Cloud
- 關於 SAP Commerce Cloud 的 Sample Setup Github 倉庫CloudGithub
- SAP Commerce Cloud 構建環境型別介紹Cloud型別
- SAP Commerce Cloud 如何為 Storefront 配置新的應用Cloud
- SAP Commerce Cloud (電商雲) UI 的懶載入功能CloudUI
- SAP Commerce Cloud Spartacus UI 的購物車 Cart 功能CloudUI
- SAP Commerce Cloud Spartacus UI 的高階 reducer 設計CloudUI
- SAP Commerce Cloud UI 的使用者會話管理CloudUI會話
- SAP Commerce Cloud Storefront 框架選型:Accelerator 還是 Spartacus?Cloud框架
- SAP Commerce Cloud B2B Organization 功能簡介Cloud
- SAP Commerce Cloud 的構建過程學習筆記Cloud筆記
- 關於 Hybris (SAP Commerce Cloud)產品的客戶群Cloud