Provides static helper methods for managing orders.
Pipelet GetOrder and methods provided to access orders such as getOrder(String) and searchOrders(String, String, Object...) can be limited by the site preference 'Limit Storefront Order Access'. An insecure order access occurs in a storefront session when all of the following are true:
- The current storefront session isnβt the session in which the order was created.
- The session customer doesnβt match the order customer.
- The order status isnβt CREATED.
- If the preference is ACTIVE, the action is disallowed and a SecurityException with a message beginning 'Unauthorized access to order' is thrown.
- If the preference is NOT ACTIVE, a SecurityException with a message beginning 'Unauthorized access to order' is logged as an error.
- In the same request, pass the dw.order.Order object reference to the followup logic.
- For storefront use cases, especially when passing the order reference to a third party, use the order token for security by using getOrder(String, String).
This method cancels an order.
This method creates an order based on a basket.
This method functions the same as createOrder(Basket), but allows the optional specification of an orderNo
.
Creates an order number.
Creates an order number.
Triggers the shipping order creation for an order.
Returns the meta data for Orders.
This method fails an unplaced order and is usually called if payment could not be authorized.
This method fails an unplaced order and is usually called if payment could not be authorized.
Resolves an order using the orderNumber and orderToken.
This method places an order and is usually called after payment has been authorized.
Executes a user-definable function on a set of orders.
Searches for a single order instance.
Searches for order instances.
Searches for order instances.
Searches for a single order instance.
Searches for order instances.
Searches for order instances.
This method is used to turn a CANCELLED order into an OPEN order.
This method is used to turn a FAILED order into a CREATED order.
This method cancels an order. Only orders in status OPEN, NEW, or COMPLETED can be cancelled.
Setting of cancel code and cancel description can be done by calling
Order.setCancelCode(String)
and Order.setCancelDescription(String)
. *
If the order contains product or gift certificate line items associated with product list items, records of the
purchase of the product list items will be removed.
Inventory transactions and coupon redemptions associated with the order will be rolled back.
It is important to consider that this method will cancel orders with gift certificate line items.
If an order has any active post-processing objects (e.g. shipping orders, returns, appeasements), then it cannot be cancelled directly. Its status is set automatically, based on the statuses of its post-processing objects. To cancel such an order, you must cancel all related post-processing objects.
If your B2C Commerce instance is integrated with Order Management, then you manage order statuses in Order Management. Use Order Management API endpoints.
This method creates an order based on a basket. If successful, the new order will be in status Order.ORDER_STATUS_CREATED. The basket will be removed from the session and marked for removal.
This method throws an APIException with type 'CreateOrderException' if any of the following conditions are encountered:
- any of the totals (net, gross, tax) of the basket is N/A
- any of the product items is not available (this takes previously reserved items into account)
- any campaign-based coupon in the basket is invalid (see CouponLineItem.isValid()
- the basket represents an order being edited, but the order has already been replaced by another order
- the basket represents an order being edited, but the customer associated with the original order is not the same as the current customer
The method removes all empty shipments from the basket before creating the order. A shipment is said to be empty if all of the following are true:
- it contains no product or gift certificate line items
- all total prices (net, gross, tax) are 0.0
This method decrements inventory for all products contained in the order. A previous call to Basket.reserveInventory() is unnecessary and discouraged within the same request. The method takes any items with reserved inventory into account, allowing an early reservation of items, e.g. at the beginning of the checkout process. As described above, an APIException is thrown if any item is not available.
If the basket contains product or gift certificate line items associated with product list items, the method updates the purchased quantity of the product list items; see ProductListItem.getPurchasedQuantity().
The system generates an order number via hook OrderHooks.createOrderNo(). If no hook is registered for the endpoint, the number is generated by calling createOrderSequenceNo(). The format of the number is based on the Order Number scheme defined in the Sequence Numbers preference configured for the site or organization. The number is guaranteed to be unique, but is not guaranteed to be sequential. It can be higher or lower than a previously created number. As a result, sorting orders by order number is not guaranteed to sort them in their order of creation.
This method must not be used with the ReserveInventoryForOrder pipelet or Basket.reserveInventory() in the same request.
When an order is created, search results don't include it until the next asynchronous update of the order search index. See OrderMgr.
Please note that this method might result in an order with a different customer ID than the originating
registered customer attached to the session. This happens if a registered customer logs in with the "RememberMe"
flag set to true
, but is later logged out (either explicitly, or automatically via session
expiration) before calling this method. This is due to the internal order creation logic, which creates a new
guest customer and attaches it to the order in such cases. To avoid this situation, have your custom code verify
that the customer is authenticated before it calls this method.
Usage:
var basket : Basket; // known try { var order : Order = OrderMgr.createOrder(basket); } catch (e if e instanceof APIException && e.type === 'CreateOrderException') { // handle e }
This method functions the same as createOrder(Basket), but allows the optional specification of
an orderNo
. The orderNo
must be unique within the context of a site.
If the orderNo
is not specified, the behavior is the same as that of
createOrder(Basket). In that case, the system generates an order number via hook
OrderHooks.createOrderNo(). If no hook is registered for the endpoint, the number is
generated by calling createOrderSequenceNo(). The format of the number is based on the Order Number
scheme defined in the Sequence Numbers preference configured for the site or organization. The number is
guaranteed to be unique, but is not guaranteed to be sequential. It can be higher or lower than a previously
created number. As a result, sorting orders by order number is not guaranteed to sort them in their order of
creation.
This method must not be used with the ReserveInventoryForOrder pipelet or Basket.reserveInventory() in the same request.
When an order is created, search results don't include it until the next asynchronous update of the order search index. See OrderMgr.
Please note that this method might result in an order with a different customer ID than the originating
registered customer attached to the session. This happens if a registered customer logs in with the "RememberMe"
flag set to true
, but is later logged out (either explicitly, or automatically via session
expiration) before calling this method. This is due to the internal order creation logic, which creates a new
guest customer and attaches it to the order in such cases. To avoid this situation, have your custom code verify
that the customer is authenticated before it calls this method.
Usage:
var basket : Basket; // known var orderNo : String; // known try { var order : Order = OrderMgr.createOrder(basket, orderNo); } catch (e if e instanceof APIException && e.type === 'CreateOrderException') { // handle e }
null
is specified, an order number is generated
Creates an order number.
The order number is created via hook OrderHooks.createOrderNo(). If no hook is registered for the endpoint, the number is generated by calling createOrderSequenceNo(). The format of the number is based on the Order Number scheme defined in the Sequence Numbers preference configured for the site or organization.
The number is guaranteed to be unique, but is not guaranteed to be sequential. It can be higher or lower than a previously created number. As a result, sorting orders by order number is not guaranteed to sort them in their order of creation.
Creates an order number.
The format of the number is based on the Order Number scheme defined in the Sequence Numbers preference configured for the site or organization.
The number is guaranteed to be unique, but is not guaranteed to be sequential. It can be higher or lower than a previously created number. As a result, sorting orders by order number is not guaranteed to sort them in their order of creation.
Triggers the shipping order creation for an order.
Must be run outside of a transaction. Will call hooks of the shipping order creation process, which are:
- ShippingOrderHooks.extensionPointPrepareCreateShippingOrders
- ShippingOrderHooks.extensionPointCreateShippingOrders
- ShippingOrderHooks.extensionPointAfterStatusChange
- ShippingOrderHooks.extensionPointNotifyStatusChange
As a result, zero, one, or multiple ShippingOrders are created.
Order post-processing APIs (gillian) are now inactive by default and will throw an exception if accessed. Activation needs preliminary approval by Product Management. Please contact support in this case. Existing customers using these APIs are not affected by this change and can use the APIs until further notice.
Returns the meta data for Orders.
This method fails an unplaced order and is usually called if payment could not be authorized. The specified Order must be in status CREATED, and will be set to status FAILED.
Inventory transactions and coupon redemptions associated with the Order will be rolled back.
If the order is failed in the same session in which it was created, the basket will be reopened such that it can be used for a subsequent order.
This method fails an unplaced order and is usually called if payment could not be authorized. The specified Order must be in status CREATED, and will be set to status FAILED.
Inventory transactions and coupon redemptions associated with the Order will be rolled back.
A basket can only be reopened if no other basket for the customer exists at the moment of the call to
failOrder
, since a customer is limited to 1 storefront basket at a time. If, after order creation, a
call was made to BasketMgr.getCurrentOrNewBasket() or pipelet GetBasket with parameter Create=true, then
a new basket has been created, and failOrder
cannot reopen the basket the order was created with. If
a basket is reopened, it always masks sensitive information (e.g., credit card number), because during order
creation, basket payment information is permanently masked.
Returns the order with the specified order number. Order access in the storefront can be limited; see the class description. Use getOrder(String, String) instead for secure access in a storefront session.
If Limit Storefront Order Access site preference is enabled, this method throws an exception when an insecure access is attempted (refer to the conditions of insecure access in the description of OrderMgr class). Use getOrder(String, String) instead.
Resolves an order using the orderNumber and orderToken.
The order token is generated during order creation in a secure way that is designed to reduce the possibility of unauthorized access. You can retrieve the token via (Order.getOrderToken().
This version of the getOrder method doesnβt return an exception when the Limit Storefront Order Access site preference is enabled. Best security practice is to always enable this preference, and to use this method when appropriate.
You should always use this method in the following cases.
- Integration use cases (such as asynchronous payment processing)
- When resolving orders from links (for example, order confirmation)
- Storefront use cases
This method places an order and is usually called after payment has been authorized. The specified order must be in status CREATED, and will be set to status NEW.
If the order contains product or gift certificate line items associated with product list items, records of the purchase of the product list items will be made. For example, if the basket contains an item added from a gift registry, the purchase history of the respective gift registry item is updated.
The order will count toward product and customer active data.
Placing an order leads to the generation of shipment numbers for all shipments and the invoice number of the order. See Shipment.getShipmentNo() and Order.getInvoiceNo(). This is done using sequences.
Executes a user-definable function on a set of orders. This method is intended to be used in batch processes and jobs, since it allows efficient processing of large result sets (which might take a while to process). First, a search with the given parameters is executed. Then the given function is executed once for each order of the search result. The order is handed over as the only parameter to this function.
The search can be configured using a simple query language, which provides most common filter and operator functionality. The callback function will be supplied with a single argument of type 'Order'. When the function defines additional arguments, they will be undefined when called. When the method doesn't define any argument, it will be called anyway. Error during execution of the callback will be logged, and execution will continue with the next element from the result set. This method can be used as in this example (which counts the number of orders):
var count=0; function callback(order: Order) { count++; dw.system.Logger.debug("order found: "+order.documentNo) } OrderMgr.processOrders(callback, "buyerno=1"); dw.system.Logger.debug("found "+count+" orders for buyerno 1");
Searches for a single order instance. Order access in the storefront can be limited; see the class description.
The search can be configured using a simple query language, which provides most common filter and operator functionality.
The identifier for an attribute to use in a query condition is always the ID of the attribute as defined
in the type definition. For custom-defined attributes, the prefix 'custom' is required in the search term (e.g.
custom.color = {1}
), while for system attributes no prefix is used (e.g. name = {4}
).
Supported attribute value types with sample expression values:
- String
'String', 'Str*', 'Strin?'
- Integer
1, 3E4
- Number
1.0, 3.99E5
- Date
yyyy-MM-dd e.g. 2007-05-31 (Default TimeZone = UTC)
- DateTime
yyyy-MM-dd'T'hh:mm:ss+Z e.g. 2007-05-31T00:00+Z (Z TimeZone = UTC) or 2007-05-31T00:00:00
- Boolean
true, false
- Email
'[email protected]', '*@demandware.com'
- Set of String
'String', 'Str*', 'Strin?'
- Set of Integer
1, 3E4
- Set of Number
1.0, 3.99E5
- Enum of String
'String', 'Str*', 'Strin?'
- Enum of Integer
1, 3E4
The following types of attributes are not queryable:
- Image
- HTML
- Text
- Quantity
- Password
Note that some system attributes are not queryable by default, regardless of the actual value type code.
The following operators are supported in a condition:
=
Equals - All types; supports NULL value (thumbnail = NULL
)!=
Not equals - All types; supports NULL value (thumbnail != NULL
)<
Less than - Integer, Number, and Date types only>
Greater than - Integer, Number, and Date types only<=
Less or equals than - Integer, Number, and Date types only>=
Greater or equals than - Integer, Number, and Date types onlyLIKE
Like - String types and Email only; use if leading or trailing wildcards will be used to support substring search (e.g.custom.country LIKE 'US*'
)ILIKE
Caseindependent Like - String types and Email only; use to support case-insensitive queries (e.g.custom.country ILIKE 'usa'
); also supports wildcards for substring matching
Conditions can be combined using logical expressions 'AND', 'OR', and 'NOT', and nested using parentheses, e.g.
gender = {1} AND (age >= {2} OR (NOT profession LIKE {3}))
.
The query language provides a placeholder syntax to pass objects as additional search parameters. Each passed
object is related to a placeholder in the query string. The placeholder must be an Integer that is surrounded by
braces. The first Integer value must be '0', the second '1', and so on, e.g.
querySystemObjects("sample", "age = {0} or creationDate >= {1}", 18, date)
If there is more than one object matching the specified query criteria, the result is not deterministic. In order
to retrieve a single object from a sorted result set, it is recommended to use the following code:
queryOrders("", "custom.myAttr asc", null).first()
. The method first()
returns only the
next element and closes the iterator. This method will be deprecated in a future release. We recommend to use
methods searchOrder(String, Object...), searchOrders(Map, String), and
searchOrders(String, String, Object...) to search for orders, and to use method
processOrders(Function, String, Object...) to search for and process orders in jobs.
queryString
.
Searches for order instances. Order access in the storefront can be limited; see the class description.
The search can be configured using a simple query language, which provides most common filter and operator functionality. When implementing order history functionality, don't use the search or query methods in this class. Instead, use OrderHistory.getOrders(String, String, Object...).
The identifier for an attribute to use in a query condition is always the ID of the attribute as defined
in the type definition. For custom-defined attributes, the prefix 'custom' is required in the search term (e.g.
custom.color = {1}
), while for system attributes no prefix is used (e.g. name = {4}
).
Supported attribute value types with sample expression values:
- String
'String', 'Str*', 'Strin?'
- Integer
1, 3E4
- Number
1.0, 3.99E5
- Date
yyyy-MM-dd e.g. 2007-05-31 (Default TimeZone = UTC)
- DateTime
yyyy-MM-dd'T'hh:mm:ss+Z e.g. 2007-05-31T00:00+Z (Z TimeZone = UTC) or 2007-05-31T00:00:00
- Boolean
true, false
- Email
'[email protected]', '*@demandware.com'
- Set of String
'String', 'Str*', 'Strin?'
- Set of Integer
1, 3E4
- Set of Number
1.0, 3.99E5
- Enum of String
'String', 'Str*', 'Strin?'
- Enum of Integer
1, 3E4
The following types of attributes are not queryable:
- Image
- HTML
- Text
- Quantity
- Password
Note that some system attributes are not queryable by default, regardless of the actual value type code.
The following operators are supported in a condition:
=
Equals - All types; supports NULL value (thumbnail = NULL
)!=
Not equals - All types; supports NULL value (thumbnail != NULL
)<
Less than - Integer, Number, and Date types only>
Greater than - Integer, Number, and Date types only<=
Less or equals than - Integer, Number, and Date types only>=
Greater or equals than - Integer, Number, and Date types onlyLIKE
Like - String types and Email only; use if leading or trailing wildcards will be used to support substring search (e.g.custom.country LIKE 'US*'
)ILIKE
Caseindependent Like - String types and Email only; use to support case-insensitive queries (e.g.custom.country ILIKE 'usa'
); also supports wildcards for substring matching
Conditions can be combined using logical expressions 'AND', 'OR', and 'NOT', and nested using parentheses, e.g.
gender = {1} AND (age >= {2} OR (NOT profession LIKE {3}))
.
The query language provides a placeholder syntax to pass objects as additional search parameters. Each passed
object is related to a placeholder in the query string. The placeholder must be an Integer that is surrounded by
braces. The first Integer value must be '0', the second '1', and so on, e.g.
querySystemObjects("sample", "age = {0} or creationDate >= {1}", 18, date)
The sorting parameter is optional and may contain a comma-separated list of attribute names to sort by. Each sort attribute name may be followed by an optional sort direction specifier ('asc' | 'desc'). The default sorting direction is ascending, if no direction was specified.
Example: age desc, name
Please note that specifying a localized custom attribute as the sorting attribute is currently not supported.
Sometimes it is desired to get all instances of a specified type with a special sorting condition. This can be
easily done by providing the 'type' of the custom object and the 'sortString' in combination with an empty
'queryString', e.g. queryOrders("sample", "", "custom.myAttr asc")
.
It is strongly recommended to call SeekableIterator.close()
on the returned
SeekableIterator if not all of its elements are being retrieved. This will ensure the proper cleanup of system
resources.
This method will be deprecated in a future release. We recommend to use methods searchOrder(String, Object...), searchOrders(Map, String), and searchOrders(String, String, Object...) to search for orders, and to use the method processOrders(Function, String, Object...) to search for and process orders in jobs.
Searches for order instances. Order access in the storefront can be limited; see the class description.
The search can be configured with a map, which converts key-value pairs into a query expression. The key-value pairs are turned into a sequence of '=' or 'like' conditions, which are combined with AND statements. When implementing order history functionality, don't use the search or query methods in this class. Instead, use OrderHistory.getOrders(String, String, Object...).
Example:
A map with the key/value pairs: 'name'/'tom*', 'age'/66 will be converted as follows:
"name like 'tom*' and age = 66"
The identifier for an attribute to use in a query condition is always the ID of the attribute as defined
in the type definition. For custom-defined attributes, the prefix 'custom' is required in the search term (e.g.
custom.color = {1}
), while for system attributes no prefix is used (e.g. name = {4}
).
Supported attribute value types with sample expression values:
- String
'String', 'Str*', 'Strin?'
- Integer
1, 3E4
- Number
1.0, 3.99E5
- Date
yyyy-MM-dd e.g. 2007-05-31 (Default TimeZone = UTC)
- DateTime
yyyy-MM-dd'T'hh:mm:ss+Z e.g. 2007-05-31T00:00+Z (Z TimeZone = UTC) or 2007-05-31T00:00:00
- Boolean
true, false
- Email
'[email protected]', '*@demandware.com'
- Set of String
'String', 'Str*', 'Strin?'
- Set of Integer
1, 3E4
- Set of Number
1.0, 3.99E5
- Enum of String
'String', 'Str*', 'Strin?'
- Enum of Integer
1, 3E4
The following types of attributes are not queryable:
- Image
- HTML
- Text
- Quantity
- Password
Note that some system attributes are not queryable by default, regardless of the actual value type code.
The sorting parameter is optional and may contain a comma-separated list of attribute names to sort by. Each sort attribute name may be followed by an optional sort direction specifier ('asc' | 'desc'). The default sorting direction is ascending, if no direction was specified.
Example: age desc, name
Please note that specifying a localized custom attribute as the sorting attribute is currently not supported.
It is strongly recommended to call the SeekableIterator.close()
on the returned
SeekableIterator if not all of its elements are being retrieved. This will ensure the proper cleanup of system
resources.
This method will be deprecated in a future release. We recommend to use methods searchOrder(String, Object...), searchOrders(Map, String), and searchOrders(String, String, Object...) to search for orders, and to use method processOrders(Function, String, Object...) to search for and process orders in jobs.
Searches for a single order instance. Order access in the storefront can be limited; see the class description.
The search can be configured using a simple query language, which provides most common filter and operator functionality.
The identifier for an attribute to use in a query condition is always the ID of the attribute as defined
in the type definition. For custom-defined attributes the prefix 'custom' is required in the search term (e.g.
custom.color = {1}
), while for system attributes no prefix is used (e.g. name = {4}
).
Supported attribute value types with sample expression values:
- String
'String', 'Str*', 'Strin?'
- Integer
1, 3E4
- Number
1.0, 3.99E5
- Date
yyyy-MM-dd e.g. 2007-05-31 (Default TimeZone = UTC)
- DateTime
yyyy-MM-dd'T'hh:mm:ss+Z e.g. 2007-05-31T00:00+Z (Z TimeZone = UTC) or 2007-05-31T00:00:00
- Boolean
true, false
- Email
'[email protected]', '*@demandware.com'
- Set of String
'String', 'Str*', 'Strin?'
- Set of Integer
1, 3E4
- Set of Number
1.0, 3.99E5
- Enum of String
'String', 'Str*', 'Strin?'
- Enum of Integer
1, 3E4
The following types of attributes are not queryable:
- Image
- HTML
- Text
- Quantity
- Password
Note that some system attributes are not queryable by default, regardless of the actual value type code.
The following operators are supported in a condition:
=
Equals - All types; supports NULL value (thumbnail = NULL
)!=
Not equals - All types; supports NULL value (thumbnail != NULL
)<
Less than - Integer, Number, and Date types only>
Greater than - Integer, Number, and Date types only<=
Less or equals than - Integer, Number, and Date types only>=
Greater or equals than - Integer, Number, and Date types onlyLIKE
Like - String types and Email only; use if leading or trailing wildcards will be used to support substring search (e.g.custom.country LIKE 'US*'
)ILIKE
Caseindependent Like - String types and Email only; use to support case-insensitive queries (e.g.custom.country ILIKE 'usa'
), also supports wildcards for substring matching
Conditions can be combined using logical expressions 'AND', 'OR', and 'NOT', and nested using parentheses, e.g.
gender = {1} AND (age >= {2} OR (NOT profession LIKE {3}))
.
The query language provides a placeholder syntax to pass objects as additional search parameters. Each passed
object is related to a placeholder in the query string. The placeholder must be an Integer that is surrounded by
braces. The first Integer value must be '0', the second '1', and so on, e.g.
querySystemObjects("sample", "age = {0} or creationDate >= {1}", 18, date)
.
If there is more than one object matching the specified query criteria, the result is not deterministic. In order
to retrieve a single object from a sorted result set, it is recommended to use the following code:
queryOrders("", "custom.myAttr asc", null).first()
. The method first()
returns only the
next element and closes the iterator.
If the order search API is configured to use the new Search Service, the following differences apply:
- wildcards will be filtered from the query (*, %, +) and replaced by spaces
- LIKE and ILIKE queries will be executed as fulltext queries (working on whole words), not as substring searches
- LIKE queries will always be case-insensitive
- using logical operators may change the execution of LIKE/ILIKE clauses to exact string comparison, depending on how they are combined
- using logical operators may result in degraded performance, depending on how they are combined
Order search index updates are asynchronous, triggered only by committing changes to the underlying system.
queryString
.
Searches for order instances. Order access in the storefront can be limited; see the class description.
The search can be configured using a simple query language, which provides most common filter and operator functionality. When implementing order history functionality, don't use the search or query methods in this class. Instead, use OrderHistory.getOrders(String, String, Object...).
The identifier for an attribute to use in a query condition is always the ID of the attribute as defined
in the type definition. For custom-defined attributes the prefix 'custom' is required in the search term (e.g.
custom.color = {1}
), while for system attributes no prefix is used (e.g. name = {4}
).
Supported attribute value types with sample expression values:
- String
'String', 'Str*', 'Strin?'
- Integer
1, 3E4
- Number
1.0, 3.99E5
- Date
yyyy-MM-dd e.g. 2007-05-31 (Default TimeZone = UTC)
- DateTime
yyyy-MM-dd'T'hh:mm:ss+Z e.g. 2007-05-31T00:00+Z (Z TimeZone = UTC) or 2007-05-31T00:00:00
- Boolean
true, false
- Email
'[email protected]', '*@demandware.com'
- Set of String
'String', 'Str*', 'Strin?'
- Set of Integer
1, 3E4
- Set of Number
1.0, 3.99E5
- Enum of String
'String', 'Str*', 'Strin?'
- Enum of Integer
1, 3E4
The following types of attributes are not queryable:
- Image
- HTML
- Text
- Quantity
- Password
Note that some system attributes are not queryable by default, regardless of the actual value type code.
The following operators are supported in a condition:
=
Equals - All types; supports NULL value (thumbnail = NULL
)!=
Not equals - All types; supports NULL value (thumbnail != NULL
)<
Less than - Integer, Number, and Date types only>
Greater than - Integer, Number, and Date types only<=
Less or equals than - Integer, Number, and Date types only>=
Greater or equals than - Integer, Number, and Date types onlyLIKE
Like - String types and Email only; use if leading or trailing wildcards will be used to support substring search (e.g.custom.country LIKE 'US*'
)ILIKE
Caseindependent Like - String types and Email only; use to support case-insensitive queries (e.g.custom.country ILIKE 'usa'
); also supports wildcards for substring matching
Conditions can be combined using logical expressions 'AND', 'OR', and 'NOT', and nested using parentheses, e.g.
gender = {1} AND (age >= {2} OR (NOT profession LIKE {3}))
.
The query language provides a placeholder syntax to pass objects as additional search parameters. Each passed
object is related to a placeholder in the query string. The placeholder must be an Integer that is surrounded by
braces. The first Integer value must be '0', the second '1', and so on, e.g.
querySystemObjects("sample", "age = {0} or creationDate >= {1}", 18, date)
.
The sorting parameter is optional and may contain a comma-separated list of attribute names to sort by. Each sort attribute name may be followed by an optional sort direction specifier ('asc' | 'desc'). The default sorting direction is ascending, if no direction was specified.
Example: age desc, name
Please note that specifying a localized custom attribute as the sorting attribute is currently not supported.
Sometimes it is desired to get all instances of a specified type with a special sorting condition. This can be
easily done by providing the 'type' of the custom object and the 'sortString' in combination with an empty
'queryString', e.g. queryOrders("sample", "", "custom.myAttr asc")
.
It is strongly recommended to call SeekableIterator.close()
on the returned
SeekableIterator if not all of its elements are being retrieved. This will ensure the proper cleanup of system
resources.
If the order search API is configured to use the new Search Service, the following differences apply:
- wildcards will be filtered from the query (*, %, +) and replaced by spaces
- LIKE and ILIKE queries will be executed as fulltext queries (working on whole words), not as substring searches
- LIKE queries will always be case-insensitive
- using logical operators may change the execution of LIKE/ILIKE clauses to exact string comparison, depending on how they are combined
- using logical operators may result in degraded performance, depending on how they are combined
- the result is limited to a maximum of 1000 orders
Order search index updates are asynchronous, triggered only by committing changes to the underlying system.
Searches for order instances. Order access in the storefront can be limited; see the class description.
The search can be configured with a map, which converts key-value pairs into a query expression. The key-value pairs are turned into a sequence of '=' or 'like' conditions, which are combined with AND statements.
Example:
A map with the key/value pairs: 'name'/'tom*', 'age'/66 will be converted as follows:
"name like 'tom*' and age = 66"
Note that wildcards are not supported by Search Service.
The identifier for an attribute to use in a query condition is always the ID of the attribute as defined
in the type definition. For custom-defined attributes, the prefix 'custom' is required in the search term (e.g.
custom.color = {1}
), while for system attributes no prefix is used (e.g. name = {4}
).
Supported attribute value types with sample expression values:
- String
'String', 'Str*', 'Strin?'
- Integer
1, 3E4
- Number
1.0, 3.99E5
- Date
yyyy-MM-dd e.g. 2007-05-31 (Default TimeZone = UTC)
- DateTime
yyyy-MM-dd'T'hh:mm:ss+Z e.g. 2007-05-31T00:00+Z (Z TimeZone = UTC) or 2007-05-31T00:00:00
- Boolean
true, false
- Email
'[email protected]', '*@demandware.com'
- Set of String
'String', 'Str*', 'Strin?'
- Set of Integer
1, 3E4
- Set of Number
1.0, 3.99E5
- Enum of String
'String', 'Str*', 'Strin?'
- Enum of Integer
1, 3E4
The following types of attributes are not queryable:
- Image
- HTML
- Text
- Quantity
- Password
Note that some system attributes are not queryable by default, regardless of the actual value type code.
The sorting parameter is optional and may contain a comma-separated list of attribute names to sort by. Each sort attribute name may be followed by an optional sort direction specifier ('asc' | 'desc'). The default sorting direction is ascending, if no direction was specified.
Example: age desc, name
Please note that specifying a localized custom attribute as the sorting attribute is currently not supported.
It is strongly recommended to call SeekableIterator.close()
on the returned
SeekableIterator if not all of its elements are being retrieved. This will ensure the proper cleanup of system
resources.
If the order search API is configured to use the new Search Service, the following differences apply:
- wildcards will be filtered from the query (*, %, +) and replaced by spaces
- LIKE and ILIKE queries will be executed as fulltext queries (working on whole words), not as substring searches
- LIKE queries will always be case-insensitive
- using logical operators may change the execution of LIKE/ILIKE clauses to exact string comparison, depending on how they are combined
- using logical operators may result in degraded performance, depending on how they are combined
- the result is limited to a maximum of 1000 orders
Order search index updates are asynchronous, triggered only by committing changes to the underlying system.
This method is used to turn a CANCELLED order into an OPEN order.
The specified order must be a cancelled order (Order.ORDER_STATUS_CANCELLED). The method will reserve inventory for all product line items, and create redemptions for all coupons. If successful, the status of the order will be changed to Order.ORDER_STATUS_OPEN. If the order contains product or gift certificate line items associated with product list items, records of the purchase of the product list items will be recreated.
If the undoCancelOrder call fails, the transaction is marked as βrollback onlyβ β all changes in the associated transaction will no longer be committed.
Possible error status codes are:
- OrderProcessStatusCodes.COUPON_INVALID - coupon is not active anymore or maximum amount of redemptions is reached
- OrderProcessStatusCodes.ORDER_NOT_CANCELLED - order is not in status Order.ORDER_STATUS_CANCELLED
- OrderProcessStatusCodes.INVENTORY_RESERVATION_FAILED - Inventory reservation for the order failed. In cases when availability is too low then undoCancel or undoFail results in a reservation failure. This can be avoided using the order site preferences to specifically allow overselling. See order site preferences under "Constraints for Undoing Failed/Cancelled Orders".
This method is used to turn a FAILED order into a CREATED order.
The specified order must be a failed order (Order.ORDER_STATUS_FAILED). The method will reserve inventory for all product line items, and create redemptions for all coupons. If successful, the status of the order will be changed to Order.ORDER_STATUS_CREATED.
If the undoFailOrder call fails, the transaction is marked as βrollback onlyβ β all changes in the associated transaction will no longer be committed.
Possible error status codes are:
- OrderProcessStatusCodes.COUPON_INVALID - coupon is not active anymore or maximum amount of redemptions is reached
- OrderProcessStatusCodes.ORDER_NOT_FAILED - order is not in status Order.ORDER_STATUS_FAILED
- OrderProcessStatusCodes.INVENTORY_RESERVATION_FAILED - Inventory reservation for the order failed. In cases when availability is too low then undoCancel or undoFail results in a reservation failure. This can be avoided using the order site preferences to specifically allow overselling. See order site preferences under "Constraints for Undoing Failed/Cancelled Orders".