When using catalogs to store product prices, the prices may be set to become active at a future date. A temporary catalog containing the future prices is created and a batch job (called "Process Future Prices") runs at regular intervals (these can be adjusted by setting the "cron-expression" in the Trigger for the Quartz batch job) to move the future prices to the regular catalog when the future date is reached. The temporary catalog is associated with the actual catalog but is of a different type and has an activation date. When the batch job detects that the activation date has been reached, it moves the prices and deletes the temporary catalog.
The "Process Future Prices" batch job can be configured to first empty Solr of all products and/or load all products into Solr after the future catalogs are processed.
Future prices may be set for a single product using the Admin API call:
editProductWithOptions(String sessionId, AdminProduct product, AdminProductMgrOptions mgrOptions)
When making the call, the attributes catalogId and priceDate of the AdminProductMgrOptions must be set and useExternalPrice must also be set to true. The priceDate attribute contains the future date for when the prices will become active. If it is left empty, then the edit works on the catalog referenced by catalogId and the new prices become active immediately. The future prices may be read back in a similar fashion using the Admin API call:
getProductWithOptions(String sessionId, int productId, AdminProductMgrOptions mgrOptions)
or
searchForProductsWithOptions(String sessionId, AdminDataDescriptor dataDesc, AdminProductSearch prodSearch, int languageId, AdminProductMgrOptions mgrOptions)
In order to receive the future prices, the AdminProductMgrOptions object must be configured as explained above.
We imagine that the setting of future prices will be typically managed through the APIs. However it is possible to create a future price catalog using the Admin App and then to use this catalog in the Admin App to generate future prices or to insert / edit future prices for a product at a specified time. Also the Admin App may be used to view the future price catalogs that were generated through the APIs. The keys of the catalogs created through the API calls follow a naming convention which is the catalog key followed by the activation date.
When using the Admin App to create a future price catalog you must create a new temporary catalog of type "Future". You need to define a "Destination Catalog" - options will be available in the droplist. You also need to define the "Active Date". This is the date when the prices in the temporary catalog will be copied over to the destination catalog and become active. The default format for the active date/time is "dd/MM/yyyy HH:mm" but this format is defined in a configuration variable (on the "Store Configuration" panel) and can be changed if required.
In the example below a temporary future catalog called "NewYearSales-31/12/2020-23:59" has been created. When the time comes (right at the end of the year) for the prices to be active they are copied to the "NewYearSales" catalog so that the New Year Sales prices will become active.
A batch job is provided for processing the future price catalogs. By default the batch job is set up in Quartz but not defined to execute. In order to define the batch job to run you need to enable Quartz (uncomment the Quartz section in the konakartadmin webapp's web.xml file) and define a Trigger for the job to run at the required frequency. For example, this Trigger would configure the job to execute every hour on the hour:
<trigger> <cron> <name>ProcessFuturePricesTrigger</name> <group>KonaKart Triggers</group> <description>Trigger for ProcessFuturePrices</description> <job-name>ProcessFuturePrices</job-name> <job-group>KonaKart Batch Jobs</job-group> <!-- every hour 0 0 * ? * * --> <!-- every 30 seconds 0,30 * * ? * * --> <!-- every day @ 9:00pm 0 0 21 ? * * --> <cron-expression>0 0 * ? * *</cron-expression> </cron> </trigger>
The batch job processes each future price catalog in ascending date order. If the active date is earlier or equal to the current date/time all the prices in the future price catalog are copied to the defined destination catalog. Following successful processing of each future price catalog they are deleted from the system (along with their associated prices in the database).
The source code for the batch job is provided in the "*\custom\batch\src\com\konakartadmin\bl\AdminCatalogBatchMgr.java" file and can be modified to suit your own requirements.