也提 供API檔案。
整合架構包含具有API的整合層。 這可讓您建立適用於電子商務功能的AEM元件(不受您的特定電子商務引擎影響)。 它也可讓您使用內部CRX資料庫,或插入電子商務系統,並將產品資料提取至AEM。
提供許多現成可用的AEM元件,以使用整合層。 目前有:
針對搜尋,提供整合掛接,可讓您使用AEM搜尋、協力廠商搜尋(例如Search&Promote)或其組合。
電子商務架構可與任何電子商務解決方案搭配使用,所使用的引擎需由AEM識別——即使使用AEM一般引擎:
電子商務引擎是支援CommerceService
介面的OSGi服務
commerceProvider
服務屬性區分AEM支援CommerceService
和Product
的Resource.adaptTo()
adaptTo
實作會在資源的階層中尋找cq:commerceProvider
屬性:
使用cq:Commerce
mixin,將cq:commerceProvider
新增至強型資源。
cq:commerceProvider
屬性也用於參考適當的商務工廠定義。
cq:commerceProvider
屬性的值geometrixx將關聯至Day CQ Commerce Factory for Geometrixx-Outdoors(com.adobe.cq.commerce.hybris.impl.GeoCommerceServiceFactory
)的OSGi組態——其中,參數commerceProvider
也包含值geometrixx
。在標準AEM安裝中,需要特定實作,例如:
cq:commerceProvider = geometrixx |
geometrixx範例;這包括一般API的最低擴充功能 |
/etc/commerce/products/geometrixx-outdoors
+ cq:commerceProvider = geometrixx
+ adobe-logo-shirt
+ cq:commerceType = product
+ price = 12.50
+ adobe-logo-shirt_S
+ cq:commerceType = variant
+ size = S
+ adobe-logo-shirt_XL
+ cq:commerceType = variant
+ size = XL
+ price = 14.50
使用CRXDE Lite,您就可以在AEM一般實作的產品元件中看到如何處理這些問題:
/apps/geometrixx-outdoors/components/product
儲存客戶購物車相關資訊的作業。
CommerceSession:
擁有購物車
執行添加/刪除/等
對購物車執行各種計算;
commerceSession.getProductPriceInfo(Product product, Predicate filter)
擁有order資料的持久性:
CommerceSession.getUserContext()
可使用updateOrder(Map<String, Object> delta)
擷取/更新傳送詳細資訊
也擁有payment處理連線
也擁有fulfillment連線
單一產品可以有多種變化;例如,可能因顏色和/或大小而異。 產品必須定義哪些屬性驅動變化;我們將這些變型軸稱為。
但是,並非所有屬性都是變型軸。 變化也會影響其他屬性;例如,價格可能取決於規模。 購物者無法選取這些屬性,因此不視為變型軸。
每個產品和/或變體都由資源表示,因此將1:1映射到儲存庫節點。 由此推論,特定產品和/或變體可以通過其路徑唯一標識。
任何產品資源都可以用Product API
表示。 產品API中的大部分呼叫都是特定變數(雖然變數可能繼承祖先的共用值),但也有列出變數集(getVariantAxes()
、getVariants()
等)的呼叫。
實際上,變型軸由Product.getVariantAxes()
返回的值確定:
cq:productVariantAxes
)雖然產品(一般而言)可以有許多變型軸,但現成的產品元件只能處理兩個:
size
此附加變型是透過產品參考的variationAxis
屬性選取的(通常color
for Geometrixx Outdoors)。
一般而言:
PIM資料位於/etc
下
/content
下的產品參考。
產品變化與產品資料節點之間必須有1:1的對應。
產品參考也必須為每個呈現的變化提供一個節點——但不需要顯示所有的變化。 例如,如果產品有S、M、L變數,則產品資料可能是:
etc
commerce
products
shirt
shirt-s
shirt-m
shirt-l
雖然「高大」目錄可能只有:
content
big-and-tall
shirt
shirt-l
最後,不需要使用產品資料。 您可以將所有產品資料放在目錄的參考之下;但是,若不複製所有產品資料,就無法真正擁有多個型錄。
API
public interface Product extends Adaptable {
public String getPath(); // path to specific variation
public String getPagePath(); // path to presentation page for all variations
public String getSKU(); // unique ID of specific variation
public String getTitle(); // shortcut to getProperty(TITLE)
public String getDescription(); // shortcut to getProperty(DESCRIPTION)
public String getImageUrl(); // shortcut to getProperty(IMAGE_URL)
public String getThumbnailUrl(); // shortcut to getProperty(THUMBNAIL_URL)
public <T> T getProperty(String name, Class<T> type);
public Iterator<String> getVariantAxes();
public boolean axisIsVariant(String axis);
public Iterator<Product> getVariants(VariantFilter filter) throws CommerceException;
}
/**
* Interface for filtering variants and AxisFilter provided as common implementation
*
* The <code>VariantFilter</code> is used to filter variants,
* e.g. when using {@link Product#getVariants(VariantFilter filter)}.
*/
public interface VariantFilter {
public boolean includes(Product product);
}
/**
* A {@link VariantFilter} for filtering variants by the given
* axis and value. The following example returns a list of
* variant products that have a value of <i>blue</i> on the
* <i>color</i> axis.
*
* <p>
* <code>product.getVariants(new AxisFilter("color", "blue"));</code>
*/
public class AxisFilter implements VariantFilter {
private String axis;
private String value;
public AxisFilter(String axis, String value) {
this.axis = axis;
this.value = value;
}
/**
* {@inheritDoc}
*/
public boolean includes(Product product) {
ValueMap values = product.adaptTo(ValueMap.class);
if(values != null) {
String v = values.get(axis, String.class);
return v != null && v == value;
}
return false;
}
}
通用儲存機制
產品節點為nt:unstructured。
產品節點可以是:
參考,其中產品資料儲存在其他位置:
productData
屬性,其指向產品資料(通常位於/etc/commerce/products
下)。產品本身:
productData
屬性。AEM-generic產品結構
+ banyan_shirt
- cq:commerceType = product
- cq:productAttributes = [jcr:title, jcr:description, size, price, color]
- cq:productVariantAxes = [color, size]
- jcr:title = Banyan Shirt
- jcr:description = Flowery, all-cotton shirt.
- price = 14.00
+ banyan_shirt_s
- cq:commerceType = variant
- size = S
+ banyan_shirt_s_red
- cq:commerceType = variant
- color = red
+ banyan_shirt_s_blue
- cq:commerceType = variant
- color = blue
+ banyan_shirt_m
- cq:commerceType = variant
- size = M
+ banyan_shirt_m_red
- cq:commerceType = variant
- color = red
+ banyan_shirt_m_blue
- cq:commerceType = variant
- color = blue
+ banyan_shirt_l
- cq:commerceType = variant
- size = L
+ banyan_shirt_l_red
- cq:commerceType = variant
- color = red
+ banyan_shirt_l_blue
- cq:commerceType = variant
- color = blue
+ banyan_shirt_xl
- cq:commerceType = variant
- size = XL
- price = 18.00
元件
購物車歸CommerceSession:
所有
CommerceSession
執行添加、刪除等操作。CommerceSession
也會在購物車上執行各種計算。CommerceSession
也會套用已引發購物車的憑單和促銷。雖然不直接與購物車相關,CommerceSession
也必須提供目錄定價資訊(因為它擁有定價)
定價可能有數種修飾詞:
這些修飾元是完全開放的,具有下列介面:
int CommerceSession.getQuantityBreakpoints(Product product)
String CommerceSession.getProductPrice(Product product)
儲存
儲存
個性化
個人化應一律透過ClientContext來驅動。
所有情況下都會建立購物車的ClientContext /version/
:
CommerceSession.addCartEntry()
方法來新增產品。以下說明ClientContext購物車中購物車資訊的範例:
購物車和訂購資料
CommerceSession
擁有以下三個元素:
購物車內容
購物車內容結構由API修正:
public void addCartEntry(Product product, int quantity);
public void modifyCartEntry(int entryNumber, int quantity);
public void deleteCartEntry(int entryNumber);
定價
API也會修正定價結構:
public String getCartPreTaxPrice();
public String getCartTax();
public String getCartTotalPrice();
public String getOrderShipping();
public String getOrderTotalTax();
public String getOrderTotalPrice();
訂單詳細資料
但是,訂單詳細資訊由API修正:**
public void updateOrderDetails(Map<String, String> orderDetails);
public Map<String, String> getOrderDetails();
public void submitOrder();
發運計算
訂單通常需要提供多種運送選項(和價格)。
價格可能根據訂單的項目和詳細資訊,例如重量和/或交貨地址。
CommerceSession
可存取所有相依性,因此可以以類似產品定價的方式處理:
CommerceSession
擁有運費。updateOrder(Map<String, Object> delta)
來擷取/更新傳送詳細資訊。遵循標準服務API模型,電子商務專案提供一組可由個別商務引擎實施的搜尋相關API。
目前,只有hybris引擎會立即建置搜尋API。
不過,搜尋API是通用的,可由每個CommerceService個別實作。
因此,雖然提供的通用實作現成不實作此API,但您可以擴充它並新增搜尋功能。
電子商務專案包含預設搜尋元件,位於:
/libs/commerce/components/search
如此可使用搜尋API來查詢選取的商務引擎(請參閱電子商務引擎選擇):
核心專案提供數個通用/輔助類別:
CommerceQuery
用於描述搜索查詢(包含有關查詢文本、當前頁、頁面大小、排序和選定刻面的資訊)。 所有實作搜尋API的電子商務服務都會收到此類的例項,以執行其搜尋。 CommerceQuery
可從請求物件(HttpServletRequest
)實例化。
FacetParamHelper
是一種實用程式類,它提供一種靜態方法- toParams
-,用於從刻面清單和一個切換值生成GET
參數字串。 這在UI端很有用,您需要針對每個Facet的每個值顯示超連結,如此當使用者按一下超連結時,就會切換個別值(例如,如果選取該值,則會從查詢中移除,否則會新增)。 這會處理處理多/單值刻面、覆寫值等所有邏輯。
搜尋API的入口點是傳回CommerceResult
物件的CommerceService#search
方法。 如需此主題的詳細資訊,請參閱API檔案。
憑單:
優惠券是以頁面為基礎的元件,可透過網站主控台建立/編輯,並儲存於:
/content/campaigns
憑單供應:
憑單沒有自己的開/關日期/時間,但使用其父促銷活動。
外部商務引擎也可以提供憑證;這些要求至少:
isValid()
方法優惠券元件(/libs/commerce/components/voucher
)提供:
促銷活動:
促銷是以頁面為基礎的元件,使用網站主控台建立/編輯,並儲存在:
/content/campaigns
促銷提供:
您可以將促銷活動連結至促銷活動,以定義其開/關日期/時間。
您可以將促銷活動與體驗連結,以定義其細分。
與體驗無關的促銷活動不會自行引發,但仍可以透過優惠券引發。
升級元件(/libs/commerce/components/promotion
)包含:
兩個升級處理常式會從方塊中提供:
DiscountPromotionHandler
,這套用整個購物車的絕對或百分比折扣PerfectPartnerPromotionHandler
,如果合作夥伴產品也在購物車中,則套用產品絕對或百分比折扣ClientContext SegmentMgr
可解析區段,而ClientContext CartMgr
可解析促銷。 每個至少受限於一個已解決群體的促銷活動都會引發。
從購物車新增/移除優惠券是透過CommerceSession
API完成:
/**
* Apply a voucher to this session's cart.
*
* @param code the voucher's code
* @throws CommerceException
*/
public void addVoucher(String code) throws CommerceException;
/**
* Remove a voucher that was previously added with {@link #addVoucher(String)}.
*
* @param code the voucher's code
* @throws CommerceException
*/
public void removeVoucher(String code) throws CommerceException;
/**
* Get a list of vouchers that were added to this cart via {@link #addVoucher(String)}.
*
* @throws CommerceException
*/
public List<Voucher> getVouchers() throws CommerceException;
這樣,CommerceSession
負責檢查憑單是否存在以及是否可以套用。 這可能是針對只有在符合特定條件時才能使用的憑證;例如,當購物車總價格大於$100時)。 如果憑單因故無法套用,addVoucher
方法將擲回例外。 此外,CommerceSession
負責在新增/移除優惠券後更新購物車的價格。
Voucher
是類似Bean的類,包含以下欄位:
提供的AbstractJcrCommerceSession
可以申請憑證。 getVouchers()
類返回的憑單是包含jcr:content節點的cq:Page
實例,其中包含以下屬性:
sling:resourceType
(字串)-這必須是 commerce/components/voucher
jcr:title
(字串)-用於優惠券的說明
code
(字串)-使用者必須輸入的代碼,才能套用此憑單
promotion
(字串)-要套用的促銷;例如, /content/campaigns/geometrixx-outdoors/article/10-bucks-off
促銷處理常式是可修改購物車的OSGi服務。 購物車將支援在PromotionHandler
介面中定義的數個勾點。
/**
* Apply promotion to a cart line item. The method returns a discount
* <code>PriceInfo</code> instance or <code>null</code> if no discount
* was applied.
* @param commerceSession The commerce session
* @param promotion The configured promotion
* @param cartEntry The cart line item
* @return A discounted <code>PriceInfo</code> or <code>null</code>
*/
public PriceInfo applyCartEntryPromotion(CommerceSession commerceSession,
Promotion promotion, CartEntry cartEntry)
throws CommerceException;
/**
* Apply promotion to an order. The method returns a discount
* <code>PriceInfo</code> instance or <code>null</code> if no discount
* was applied.
* @param commerceSession The commerce session
* @param promotion The configured promotion
* @return A discounted <code>PriceInfo</code> or <code>null</code>
*/
public PriceInfo applyOrderPromotion(CommerceSession commerceSession, Promotion promotion)
throws CommerceException;
public PriceInfo applyShippingPromotion(CommerceSession commerceSession, Promotion promotion)
throws CommerceException;
/**
* Allows a promotion handler to define a custom, author-oriented message for a promotion.
* The {@link com.adobe.cq.commerce.common.promotion.PerfectPartnerPromotionHandler}, for instance,
* uses this to list the qualifying pairs of products in the current cart.
* @param commerceSession
* @param promotion
* @return A message to display
* @throws CommerceException
*/
public String getMessage(SlingHttpServletRequest request, CommerceSession commerceSession, Promotion promotion) throws CommerceException;
/**
* Informs the promotion handler that something under the promotions root has been edited, and the handler
* should invalidate any caches it might be keeping.
*/
public void invalidateCaches();
3個升級處理常式現成可用:
DiscountPromotionHandler
套用購物車的絕對或百分比折扣PerfectPartnerPromotionHandler
如果產品合作夥伴也在購物車中,則套用產品絕對或百分比折扣FreeShippingPromotionHandler
套用免運費