Saturday, September 21, 2013

Assigning a Catalog to a User : ATG

Assigning a Catalog to a User


In order for users to view a catalog, they must have that catalog assigned to their profile. The catalog assumes the existence of a catalog property for the user repository item. The catalog property is a derived property. You can set it in either the user’s myCatalog property or the catalog property of the contract for the user’s parentOrganization. If myCatalog is set, the parent organization’s setting is ignored.

Oracle ATG Web Commerce adds CatalogProfilePropertySetter and PriceListProfilePropertySetter components to the profilePropertySetters property of the /atg/dynamo/servlet/dafpipeline/ProfilePropertyServlet component in the DAF servlet pipeline:


profilePropertySetters+=/atg/userprofiling/CatalogProfilePropertySetter,\
                        /atg/userprofiling/PriceListProfilePropertySetter


For the profile’s catalog property, the CatalogProfilePropertySetter calls the determineCatalog method of the /atg/commerce/catalog/CatalogTools component (class atg.commerce.catalog.custom.CustomCatalogTools). This method invokes the /atg/commerce/util/ContextValueRetriever component, which is the primary mechanism for identifying the catalog to assign so that the appropriate items can be displayed

Note: See below ContextValueRetriever Class for more information.


ContextValueRetriever Class


The class for the ContextValueRetriever component is atg.commerce.util.ContextValueRetriever, which holds most of the logic for determining which catalog to assign to each user. It performs a parallel function for price lists – see PriceListManager for more information. It has one property, useProfile, which is a boolean that defaults to false. The main method, retrieveValue, goes through the following steps. The method does not continue to the next step if it finds a non-null value.

1. It calls the shouldUseProfile method (see below). If this method returns true, it retrieves the requested property from the profile.

2. If a site was provided, it retrieves the requested property from the site. See Assigning Price Lists and Catalogs in a Multisite Configuration for more information.

If ContextValueRetriever returns null, CustomCatalogTools.determineCatalog picks up the default catalog and returns that to the CatalogProfilePropertySetter.

The out-of-the-box implementation of the shouldUseProfile method simply returns the value of the useProfile property. By default this property is set to false, which is appropriate for most multisite environments. The false value means that anything that might already be set in the profile is ignored, and values are retrieved instead from the current site or the global (CatalogTools) default. If you assign catalogs or price lists via your own pipeline servlet or a scenario, set useProfile to true to prevent your profile settings from being overridden with the global defaults.

If your business requires different choices for different customers, you can override shouldUseProfile. For example, assume some special customers (for example employees and sales reps) have values pre-set in their profiles, while most customers should get site defaults. The shouldUseProfile method can look at any profile property to decide if a customer is special or not and return true for the special customers and false for everyone else. In addition, if you want to add another source for catalogs or price lists, beyond profiles and sites, you can override the retrieveValue method.

Note that Oracle ATG Web Commerce provides a single component that handles both catalogs and price lists. This configuration assumes you want to apply the same logic for both types of values, which is common. If you want to apply different logic for catalogs and price lists, you can configure a second Nucleus instance of the ContextValueRetriever component, change its configuration or implementation class, and reconfigure either CatalogTools or PriceListManager to refer to the new instance.



Creating a Configurable Commerce Item : ATG

Creating a Configurable Commerce Item


Configurable commerce items are items with other items as optional components, and are described in the Using and Extending the Standard Catalog.

Follow these steps to create a new ConfigurableCommerceItem and associate it with an Order:


1. Call CommerceItemManager.createCommerceItem() to create the base commerce item.

2. Call CommerceItemManager.addSubItemToConfigurableItem() or addAsSeparateSubItemToConfigurableItem() to add options to the base item.

The example below illustrates how to programmatically create a ConfigurableCommerceItem with subSKU items and then add it to an Order.


ConfigurableCommerceItem configurableItem = (ConfigurableCommerceItem)
getCommerceItemManager().createCommerceItem("configurableCommerceItem",
 "sku10001", null, "prod10001", null, 1, null, null, new ItemPriceInfo());

SubSkuCommerceItem subskuItem = (SubSkuCommerceItem)
getCommerceItemManager().createCommerceItem("subSkuCommerceItem",
"sku20001", null, "prod20001", null, 1, null, null, new ItemPriceInfo());
getCommerceItemManager().addSubItemToConfigurableItem(configurableItem,
subskuItem);

subskuItem = (SubSkuCommerceItem)
getCommerceItemManager().createCommerceItem("subSkuCommerceItem",
"sku20002", null, "prod20002", null, 1, null, null, new ItemPriceInfo());
getCommerceItemManager().addSubItemToConfigurableItem(configurableItem,
subskuItem);

getOrderManager().addItemToOrder(order, configurableItem);




Popular Posts