|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object atg.nucleus.logging.VariableArgumentApplicationLoggingImpl atg.nucleus.GenericService atg.commerce.catalog.comparison.ComparisonList atg.commerce.catalog.comparison.ProductComparisonList
public class ProductComparisonList
ProductComparisonList extends ComparisonList and manages list elements that are specifically designed for comparing catalog-based category/product/sku tuples rather than simple Java objects.
This class includes convenience methods that take product, category, and sku id's and retrieve the corresponding objects from the product catalog, making it easier to write form handlers and droplet that manipulate the list contents. It also endows each list element with an unambiguous unique id and allows callers to remove elements by specifying their ids, which eases the task of writing form handlers that display a sorted list of product entries with "remove" buttons or checkboxes associated with entry.
The list entries of a ProductComparisonList will always contain at least the following set of properties:
id
- the unique id that identifies this list entry.
product
- the product repository item for this
list entry. This value should never be null in normal usage.
category
- the category repository item for this
list entry. This value may be null if no parent category was specified
when the list entry was created, and no default parent category exists
for the product in question.
sku
- the sku repository item for this list entry.
This value may be null if no sku was specified when the list entry was
created, and no default sku exists for the product in question.
inventoryInfo
- inventory levels and status information
for the entry's sku, represented as an instance of the
InventoryData
class.
priceInfo
- an
ItemPriceInfo
object describing
the unit price of a single instance of the specified product and sku, or null
if no sku was specified and no default sku exists for the product.
productLink
- an HTML fragment that links to the
product's page in the catalog. The default format of the HTML returned
is <a href=product.template.url?id=product.repositoryId>product.displayName</a>
but this can be changed by setting productLinkFormat
.
The HTML is stored in a property of each list entry to make it easy to
display the link using a TableInfo
component.
categoryLink
- an HTML fragment that links to the
category's page in the catalog. The default format of the HTML returned
is <a href=category.template.url?id=category.repositoryId>category.displayName</a>
but this can be changed by setting productLinkFormat
.
As with productLink
, the HTML is stored in a property of
each list entry to make it easy to display the link using a
TableInfo
component.
Example:
The following JHTML fragment displays the names, category names, and inventory availability of all of the items in a product comparison list:
<droplet bean="ForEach"> <param name="array" value="bean:ComparisonList.items"> <param name="sortProperties" value="bean:ComparisonList.sortString"> <oparam name="output"> Product: <valueof param="element.product.displayName">unknown</valueof><br> Category: <valueof param="element.category.displayName">none</valueof><br> Inventory: <valueof param="element.inventoryInfo.availabilityStatusMsg">unknown</valueof>< </oparam> </droplet>
Nested Class Summary | |
---|---|
static class |
ProductComparisonList.Entry
Inner class representing the data stored in the product comparison list. |
Field Summary | |
---|---|
static java.lang.String |
CATEGORY_KEY
|
static java.lang.String |
CATEGORY_LINK_KEY
|
static java.lang.String |
CATEGORY_PROPERTY
|
static java.lang.String |
CLASS_VERSION
|
static java.lang.String |
ID_KEY
|
static java.lang.String |
INVENTORY_KEY
|
protected CatalogTools |
mCatalogTools
|
static java.lang.String |
MY_RESOURCE_NAME
|
static java.lang.String |
PRICE_INFO_KEY
|
static java.lang.String |
PRODUCT_KEY
|
static java.lang.String |
PRODUCT_LINK_KEY
|
static java.lang.String |
SKU_KEY
|
static java.lang.String |
SKULIST_PROPERTY
|
Fields inherited from class atg.nucleus.GenericService |
---|
SERVICE_INFO_KEY |
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging |
---|
DEFAULT_LOG_TRACE_STATUS |
Fields inherited from interface atg.nucleus.logging.ApplicationLogging |
---|
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS |
Constructor Summary | |
---|---|
ProductComparisonList()
|
Method Summary | |
---|---|
boolean |
add(java.lang.String pProductId,
java.lang.String pCategoryId,
java.lang.String pSkuId,
java.lang.String pCatalogKey)
Add a product to the product comparison list, optionally specifying an associated category and sku. |
int |
addAllSkus(java.lang.String pProductId,
java.lang.String pCategoryId,
java.lang.String pCatalogKey)
Add entries to the comparison list for every sku associated with a given product. |
protected boolean |
arrayContains(int[] pIds,
int pTarget)
Return true if the specified array of ints contains the target value. |
boolean |
contains(java.lang.String pProductId)
Return true if the product comparison list contains any entry for the given product id, regardless of that entry's category and sku. |
boolean |
contains(java.lang.String pProductId,
java.lang.String pCategoryId,
java.lang.String pCatalogKey)
Return true if the product comparison list contains any entry for the given product id and category id, regardless of that entry's sku. |
boolean |
contains(java.lang.String pProductId,
java.lang.String pCategoryId,
java.lang.String pSkuId,
java.lang.String pCatalogKey)
Return true if the product comparison list contains an entry for the given product id, category id, and sku id. |
protected ProductComparisonList.Entry |
createListEntry(RepositoryItem pCategory,
RepositoryItem pProduct,
RepositoryItem pSku)
Create a product comparison list Entry for the given category, product, and sku. |
protected RepositoryItem |
defaultCategory(RepositoryItem pProduct)
Get the default parent category for a given product. |
protected RepositoryItem |
defaultSku(RepositoryItem pProduct)
Get the default sku for a given product. |
protected java.lang.String |
errorMsg(java.lang.String pResourceKey,
java.lang.Object[] pArgs)
Get a formatted error message string based on an error message resource key and an array of message arguments. |
CatalogTools |
getCatalogTools()
Get the CatalogTools object to use when looking up products, categories and skus. |
java.lang.String |
getCategoryLinkFormat()
Get the format of the HTML generated for a link to a category page. |
InventoryManager |
getInventoryManager()
Get the InventoryManager object to use when fetching inventory availability information for items in the product comparison list. |
ProductComparisonList.Entry |
getItems(int pEntryId)
Get a product comparison list entry given its uid. |
PricingTools |
getPricingTools()
Get the PricingTools object to use when fetching the ItemPriceInfo for each item in the product comparison list. |
java.lang.String |
getProductLinkFormat()
Get the format of the HTML generated for a link to a product page. |
protected ItemPriceInfo |
getUnitPrice(RepositoryItem pProduct,
RepositoryItem pSku)
Return an ItemPriceInfo object representing the unit price of the product and sku represented by pColumn; return null if the column has no sku information. |
protected boolean |
idMatch(java.lang.String pId,
RepositoryItem pItem)
Return true if pId is considered a match for pItem. |
boolean |
isEncodeLinkURLs()
Query whether to encode URLs on links created using productLinkFormat
and categoryLinkFormat . |
boolean |
isPreloadInventoryData()
Query whether to load inventory data for each entry in the product comparison list when that entry is created, or to leave the inventory information empty until a call is made to refreshInventoryData . |
protected java.lang.String |
makeLink(java.lang.String pFormat,
RepositoryItem pItem)
Expand the format string for a product or category, substituting in the name, repository id, and template url. |
protected java.lang.String |
makeLink(java.lang.String pFormat,
RepositoryItem pItem,
boolean pEncode)
Expand the format string for a product or category, substituting in the name, repository id, and template url. |
void |
refreshInventoryData()
Update the inventory information associated with each product in the product comparison list to obtain the latest inventory levels and status. |
void |
remove(java.util.Collection pEntryIds)
Remove the list entries with the specified uids. |
void |
remove(int pEntryId)
Remove the list entry with the specified uid. |
void |
remove(int[] pEntryIds)
Remove the list entries with the specified uids. |
void |
remove(java.lang.String pProductId,
java.lang.String pCategoryId,
java.lang.String pSkuId,
java.lang.String pCatalogKey)
Remove the list entry containing the given product id, category id, and sku id. |
void |
removeAll(java.lang.String pProductId)
Remove all list entries for the specified product, regardless of the entry's category or sku. |
void |
removeAll(java.lang.String pProductId,
java.lang.String pCategoryId,
java.lang.String pCatalogKey)
Remove all list entries for the specified product and category, regardless of the entry's sku. |
void |
removeCategory(java.lang.String pCategoryId)
Remove all list entries for the specified category, regardless of the entry's product or sku. |
void |
setCatalogTools(CatalogTools pCatalogTools)
Set the CatalogTools object to use when looking up products, categories and skus. |
void |
setCategoryLinkFormat(java.lang.String pCategoryLinkFormat)
Set the format of the HTML generated for a link to a category page. |
void |
setEncodeLinkURLs(boolean pEncodeLinkURLs)
Specify whether or not to call DynamoHttpServletRequest.encodeURL
on links to products and categories built using productLinkFormat
and categoryLinkFormat . |
void |
setInventoryManager(InventoryManager pInventoryManager)
Set the InventoryManager object to use when fetching inventory availability information for items in the product comparison list. |
void |
setPreloadInventoryData(boolean pPreloadInventoryData)
Specifies whether to load inventory data for each entry in the product comparison list when that entry is created, or to leave the inventory information empty until a call is made to refreshInventoryData . |
void |
setPricingTools(PricingTools pPricingTools)
Set the PricingTools object to use when fetching the ItemPriceInfo for each item in the product comparison list. |
void |
setProductLinkFormat(java.lang.String pProductLinkFormat)
Set the format of the HTML generated for a link to a product page. |
void |
setRefreshInventoryData(java.lang.String pUnused)
"set" method to make the refreshInventoryData functionality available from jhtml. |
protected java.util.List |
skuList(RepositoryItem pProduct)
Get the list of skus for a given product. |
Methods inherited from class atg.commerce.catalog.comparison.ComparisonList |
---|
addItem, clear, containsItem, getItem, getItems, getPrimarySortString, getSortString, getTableColumns, getTableInfo, indexOf, removeItem, removeItem, setItems, setTableInfo, size |
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl |
---|
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String CLASS_VERSION
public static final java.lang.String CATEGORY_PROPERTY
public static final java.lang.String SKULIST_PROPERTY
public static final java.lang.String CATEGORY_KEY
public static final java.lang.String CATEGORY_LINK_KEY
public static final java.lang.String PRODUCT_KEY
public static final java.lang.String PRODUCT_LINK_KEY
public static final java.lang.String SKU_KEY
public static final java.lang.String INVENTORY_KEY
public static final java.lang.String PRICE_INFO_KEY
public static final java.lang.String ID_KEY
public static final java.lang.String MY_RESOURCE_NAME
protected CatalogTools mCatalogTools
Constructor Detail |
---|
public ProductComparisonList()
Method Detail |
---|
public ProductComparisonList.Entry getItems(int pEntryId)
pUID
- The unique id of the list entry to return.
public boolean add(java.lang.String pProductId, java.lang.String pCategoryId, java.lang.String pSkuId, java.lang.String pCatalogKey) throws RepositoryException
pProductId
- The repository id of the product being added.pCategoryId
- The repository id of the parent category to use for this list entry.
If null, the product's default parent category will be used instead.
If the product has no default parent category, the category in the
list entry will be null.pSkuId
- The repository id of the sku to use for this list entry. If null, the
first sku in the product's sku list will be used instead. If the product
has no skus, the sku in the list entry will be null.pCatalogKey
- An optional key that is passed to the CatalogTools component, which
uses it to locate an alternate product catalog from which to add
the product. If null, the default catalog is used.
RepositoryException
- if there is any repository error while looking up
categories, products, or skus.public int addAllSkus(java.lang.String pProductId, java.lang.String pCategoryId, java.lang.String pCatalogKey) throws RepositoryException
pProductId
- The repository id of the product being added.pCategoryId
- The repository id of the parent category to use for this list entry.
If null, the product's default parent category will be used instead.
If the product has no default parent category, the category in the
list entry will be null.pCatalogKey
- An optional key that is passed to the CatalogTools component, which
uses it to locate an alternate product catalog from which to add
the product. If null, the default catalog is used.
RepositoryException
- if there is any repository error while looking up
categories, products, or skus.public boolean contains(java.lang.String pProductId, java.lang.String pCategoryId, java.lang.String pSkuId, java.lang.String pCatalogKey) throws RepositoryException
The behavior of contains
therefore parallels the
behavior of add
, so that calling
add(productId, categoryId, skuId)
and then calling
contains(productId, categoryId, skuId)>
with the
same values will return true.
The pCatalogKey
parameter is used to select a
product catalog in cases where it is necessary to locate a
product's default parent category or default sku. A null
value means use the default product catalog.
RepositoryException
public boolean contains(java.lang.String pProductId, java.lang.String pCategoryId, java.lang.String pCatalogKey) throws RepositoryException
The pCatalogKey
parameter is used to select a
product catalog in cases where it is necessary to locate a
product's default parent category. A null value means use the
default product catalog.
RepositoryException
public boolean contains(java.lang.String pProductId) throws RepositoryException
RepositoryException
public void remove(java.lang.String pProductId, java.lang.String pCategoryId, java.lang.String pSkuId, java.lang.String pCatalogKey) throws RepositoryException
The behavior of remove
therefore parallels the behavior of
add
, so that calling add(productId, categoryId, skuId)
and then calling remove(productId, categoryId, skuId)>
with the
same values will remove the item just added.
The pCatalogKey
parameter is used to select a
product catalog in cases where it is necessary to locate a
product's default parent category or default sku. A null
value means use the default product catalog.
RepositoryException
public void remove(int pEntryId)
public void remove(int[] pEntryIds)
public void remove(java.util.Collection pEntryIds)
pEntryIds
- A Collection of Integer objects representing the uid's of
the entries to remove.public void removeAll(java.lang.String pProductId)
public void removeAll(java.lang.String pProductId, java.lang.String pCategoryId, java.lang.String pCatalogKey) throws RepositoryException
The pCatalogKey
parameter is used to select a
product catalog in cases where it is necessary to locate a
product's default parent category. A null value means use
the default product catalog.
RepositoryException
public void removeCategory(java.lang.String pCategoryId)
protected RepositoryItem defaultCategory(RepositoryItem pProduct)
protected java.util.List skuList(RepositoryItem pProduct)
protected RepositoryItem defaultSku(RepositoryItem pProduct)
protected ProductComparisonList.Entry createListEntry(RepositoryItem pCategory, RepositoryItem pProduct, RepositoryItem pSku)
public void refreshInventoryData()
public void setRefreshInventoryData(java.lang.String pUnused)
protected java.lang.String errorMsg(java.lang.String pResourceKey, java.lang.Object[] pArgs)
protected boolean idMatch(java.lang.String pId, RepositoryItem pItem)
protected boolean arrayContains(int[] pIds, int pTarget)
public void setCatalogTools(CatalogTools pCatalogTools)
public CatalogTools getCatalogTools()
public void setInventoryManager(InventoryManager pInventoryManager)
public InventoryManager getInventoryManager()
public void setPreloadInventoryData(boolean pPreloadInventoryData)
refreshInventoryData
.
If your pages explicitly refresh the inventory data before displaying product comparison information, you can set this property to false and avoid one extra query to the inventory manager when each item is created. If your pages do not explicitly refresh the inventory data, you should set this property to true so your comparison list entries will contain a snapshot of the inventory data at the time each entry was added to the list.
The default value for preloadInventoryData
is
true
.
public boolean isPreloadInventoryData()
refreshInventoryData
.
setPreloadInventoryData
public void setPricingTools(PricingTools pPricingTools)
public PricingTools getPricingTools()
public void setProductLinkFormat(java.lang.String pProductLinkFormat)
{0} is replaced by the display name of the product.
{1} is replaced by the repository id of the product.
{2} is replaced by the template url of the product.
The default format is <a href=templateURL?id=repositoryId>productName<a>
public java.lang.String getProductLinkFormat()
public void setCategoryLinkFormat(java.lang.String pCategoryLinkFormat)
{0} is replaced by the display name of the category.
{1} is replaced by the repository id of the category.
{2} is replaced by the template url of the category.
The default format is <a href=templateURL?id=repositoryId>categoryName<a>
public java.lang.String getCategoryLinkFormat()
public void setEncodeLinkURLs(boolean pEncodeLinkURLs)
DynamoHttpServletRequest.encodeURL
on links to products and categories built using productLinkFormat
and categoryLinkFormat
. Links should normally be encoded to
ensure that URL-based session tracking works, and that servlet context paths
are handled correctly when using the Dynamo Application Framework on other
application servers.
public boolean isEncodeLinkURLs()
productLinkFormat
and categoryLinkFormat
. The default value is true
.
protected java.lang.String makeLink(java.lang.String pFormat, RepositoryItem pItem)
pFormat
- The format string, in which {0} is replaced by the item's
displayName, {1} by its repository id, and {2} by its template
URL.pItem
- The product or category RepositoryItem to consult when expanding
the format string.protected java.lang.String makeLink(java.lang.String pFormat, RepositoryItem pItem, boolean pEncode)
pFormat
- The format string, in which {0} is replaced by the item's
displayName, {1} by its repository id, and {2} by its template
URL.pItem
- The product or category RepositoryItem to consult when expanding
the format string.pEncode
- If true, call DynamoHttpServletRequest.encodeURL on the link
before returning it.protected ItemPriceInfo getUnitPrice(RepositoryItem pProduct, RepositoryItem pSku)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |