Welcome to the IBM Websphere Commerce Hub


Welcome to the IBM Websphere Commerce Hub

Come join me in my journey to explore the various features and capabilities of IBM Websphere Commerce and understand how retailers can benefit from its really cool out-of-box functionality.

Sunday, June 14, 2015

Attribute Dictionary - Defining Attributes

Basic Concepts :


What is Attribute Dictionary?

An attribute dictionary is a set of common attributes and attribute values that can be reused by multiple products. The attribute management tool in Management Center provides business users the ability to create, update, assign, and manage product attributes.

More detailed understanding can be found here in the Infocenter.


What are defining and descriptive attributes?

There are two types of attributes: descriptive attributes and defining attributes.
  • Descriptive attributes are not intended for SKU resolution. These attributes only provide additional information about the product. An example would be “Operating System Installed” with the values “Windows 7”, “Windows 8” etc.
  • Defining attributes are used for SKU resolution and you won’t be able to buy an item until you have given values for these defining attributes. An example would be a T-Shirt and the defining attributes “Size” and “Colour”. Once a value has been given for the two different defining attributes such as Colour: Red and Size: Medium, we will be able to determine the item/SKU that corresponds to medium, red colour shirt.


Problem Statement:


The task that we have in hand is to display all the "possible" allowed values of the defining attribtes on the PDP so that it can be used for SKU resolution when a customer makes his/her choice of the values of the defining attributes from the dropdown. The reason I say "possible" is because attribute dictionary Standardizes attributes and attribute values that are common among multiple products. For example , in the attribute dictionary , you may have a attribute called size with all allowed values of "XS" , "S" , "M" , "L" , "XL". But for a particular product - the only possible values from the list may be "S" , "M" and "L". In this scenario, I would only want to display the possible "allowed" values of "S" , "M" and "L" - rather than all the 5 allowed values 


Solution & Approach:  


I first wanted to explore if there was any OOB DSL components (get-data expressions / access profiles) which would help me accomplish my requirement.

One useful reference link in Infocenter which could help me understand this was -

From the list of access-profiles listed in the link above , I found that access-profile "IBM_Store_CatalogEntryAttributesParent" . One of the associated sql statements to this access profile in the corresponding tpl file clearly does what we require

<!-- ========================================================== 
     Adds the allowed values of attribute dictionary 
     attributes (ATTRVAL table) to the
      resultant data graph.         
     The allowed values which are not used by valid SKU of the product are filtered out                        
     ========================================================== -->
BEGIN_ASSOCIATION_SQL_STATEMENT
name=IBM_AttributeDictionaryAttributeSchemaAllowedValue

I could not , however , find a get expression associated with this accessprofile. So , I extended the corresponding \Stores\WebContent\WEB-INF\config\com.ibm.commerce.catalog-ext\get-data-config.xml (Please follow the recommended process to extend the get-data-config.xml) and added the below expression:

<expression-builder>
<name>getParentCatalogEntryAttrDictDefiningAttributesByID</name>
<data-type-name>CatalogEntry</data-type-name>
<expression-template>{_wcf.ap=$accessProfile$;_wcf.dataLanguageIds='$dataLanguageIds$'}/CatalogEntry[CatalogEntryIdentifier[(UniqueID='$catEntryId$')]]</expression-template>
<param>
<name>accessProfile</name>
<value>IBM_Store_CatalogEntryAttributesParent</value>
</param>
<param>
<name>dataLanguageIds</name>
<value></value>
</param>
</expression-builder>

And in the storefront JSP , used the following code-snippet to fetch the data using the above get expression:


<wcf:getData type = "com.ibm.commerce.catalog.facade.datatypes.CatalogEntryType" var = "catalogEntryWithAttr" expressionBuilder = "getParentCatalogEntryAttrDictDefiningAttributesByID">
<wcf:contextData name = "storeId" data = "${param.storeId}"/>
<wcf:param name = "catEntryId" value = "${product.productID}"/>
<wcf:param name = "dataLanguageIds" value = "${param.langId}"/>
</wcf:getData>

<c:forEach var="attribute" items='${catalogEntryWithAttr.catalogEntryAttributes.attributes}'> 
<c:if test="${attribute.usage== 'Defining'}" >
<p>
         <label><c:out value = "${attribute.name}"/>:</label>
<select id= "${attribute.name}" name = "${attribute.name}">
     <c:forEach var='attributeVal' items='${attribute.allowedValue}'> 
  <option value="${attributeVal.value}">${attributeVal.value}</option>
     </c:forEach>
</select>
</p>
</c:if>
</c:forEach>

Please ensure proper values are being passed (based on the JSP in which the above snippet is being introduced ) for the input parameters highlighted in red.

An another useful Infocenter link which may help us accomplish this is provided below. I havent tried it myself but providing it for reference.


No comments:

Post a Comment