Important
You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.
See our Release Process documentation for more information on the currently supported and upcoming releases.
Previously Purchased Products¶
The Previously Purchased Products functionality adds the previously purchased products grid to the customer pages under Account > Previously Purchased on the frontend. By default, previously purchased products are disabled. To enable this functionality, navigate to System > Configuration > Orders > Purchase History > Enabled Purchase History in the admin panel.
Configuration¶
Here is an example of the system config section.
1 purchase_history:
2 children:
3 purchase_history:
4 children:
5 - oro_order.enable_purchase_history
6 - oro_order.order_previously_purchased_period
The oro_order.enable_purchase_history
option turns the feature on or off.
The oro_order.order_previously_purchased_period
option stores the number of days that the purchase history should cover. The products listed as previously purchased are filtered using this timeframe and are displayed in the previously purchased products grid.
For more information about system_config.yml, please see the relevant system configuration documentation.
Website Search Index¶
Class WebsiteSearchProductIndexerListener. This listener contains methods which are called when reindex process is running.
onWebsiteSearchIndex¶
public function onWebsiteSearchIndex(IndexEntityEvent $event)
This method is triggered when search reindex process starts running. For example, we can start the reindex process with the oro:website-search:reindex
command.
This method adds new columns to the records with the oro_product_WEBSITE_ID index and based on order created_at, customer_user_id, and product_id.
Index Field¶
1 Oro\Bundle\ProductBundle\Entity\Product:
2 alias: oro_product_WEBSITE_ID
3 fields:
4 -
5 name: ordered_at_by_CUSTOMER_USER_ID
6 type: datetime
The index field which stores information about the date of the last purchase of the product.
This field is used to select a query in the grid config for select, filter and sort data. For more information, please see datagrids.yml.
1query:
2 select:
3 - datetime.ordered_at_by_CUSTOMER_USER_ID as recency
4 where:
5 and:
6 - datetime.ordered_at_by_CUSTOMER_USER_ID >= @oro_order.previously_purchased.configuration->getPreviouslyPurchasedStartDateString()
Reindex Listeners¶
ReindexProductLineItemListener
Class ReindexProductLineItemListener.
This listener contains methods which are called when the OrderLineItem entity is changed, and if all conditions are correct, a message is sent to the message queue to reindex product data.
reindexProductOnLineItemCreateOrDelete
1public function reindexProductOnLineItemCreateOrDelete(OrderLineItem $lineItem, LifecycleEventArgs $args)
This method is triggered when we create or delete an order line item. Once the order line item is created or deleted, a message is sent to the message queue informing that reindex for a product entity is required. However, if the order has unsuitable status, or the feature has been disabled, the message for reindex is not sent.
reindexProductOnLineItemUpdate
1public function reindexProductOnLineItemUpdate(OrderLineItem $lineItem, PreUpdateEventArgs $event)
This method is triggered when we update the “product” field in the order line item entity, and a message is sent to the message queue that reindex for the product entity is required. However, if the order has unsuitable status, or the feature has been disabled, the message is not sent for reindex.
ReindexProductOrderListener
Class ReindexProductOrderListener.
This listener contains methods which are called when the Order entity is changed, and if all conditions are correct, a message is sent to the message queue to reindex product data.
processIndexOnOrderStatusChange
1public function processIndexOnOrderStatusChange(Order $order, PreUpdateEventArgs $event)
This method is triggered when order status is changed. But if order status is not applicable, the message for reindex is not sent.
processIndexOnOrderWebsiteChange
1public function processIndexOnOrderWebsiteChange(Order $order, PreUpdateEventArgs $event)
This method is triggered when order website is changed. But if order status is not applicable, the message for reindex is not sent.
processOrderRemove
1public function processOrderRemove(Order $order)
This method is triggered when an order is removed. But if order status is not applicable, the message for reindex process is not sent.
processIndexOnCustomerUserChange
1public function processIndexOnCustomerUserChange(Order $order, PreUpdateEventArgs $event)
This method is triggered when order is updated and the customerUser field is changed. However, if order status is not applicable, the message for reindex process is not sent.
processIndexOnOrderCreatedAtChange
1public function processIndexOnOrderCreatedAtChange(Order $order, PreUpdateEventArgs $event)
This method is triggered when order is updated and the createdAt field is changed. However, if order status is not applicable, the message for reindex process is not sent.
PreviouslyPurchasedFeatureToggleListener
Class PreviouslyPurchasedFeatureToggleListener.
This listener contains methods which are called when we turn the feature on or off from the system config.
reindexProducts
1public function reindexProducts(ConfigUpdateEvent $event)
This method is triggered when we change the enable_purchase_history config setting. Once the setting is changed, a message is sent to reindex products in the global or website scope.
Managers¶
ProductReindexManager¶
Class ProductReindexManager.
This manager contains methods which are used when we need to reindex a product or a collection of products. Use it when you need to reindex product data.
reindexProduct
1public function reindexProduct(Product $product, $websiteId = null)
This method triggers reindex process for the current product. If the websiteId is not present, this method takes the default website id.
triggerReindexationRequestEvent
1public function triggerReindexationRequestEvent(array $productIds, $websiteId = null, $isScheduled = true)
This method triggers reindex process for a collection of product ids.
Providers¶
PreviouslyPurchasedConfigProvider
Class PreviouslyPurchasedConfigProvider.
This provider provides you with the configuration for previously purchased products.
Here is a quick overview of its usage:
getDaysPeriod
1$this->get('oro_order.previously_purchased.configuration')->getDaysPeriod();
Returns the count of days for previously purchased products.
getPreviouslyPurchasedStartDateString
1 $this->get('oro_order.previously_purchased.configuration')->getPreviouslyPurchasedStartDateString()
Returns the start date in string format for previously purchased products.
LatestOrderedProductsInfoProvider
Class LatestOrderedProductsInfoProvider.
This provider is used when we need more information about who and when bought products in the order.
getLatestOrderedProductsInfo
1 /**
2 * Returns information about who and when bought those products
3 * [
4 * product id => [
5 * 'customer_user_id' => customer user who bought,
6 * 'created_at' => order create \DateTime,
7 * ],
8 * ...
9 * ]
10 *
11 * @param array $productIds
12 * @param int $websiteId
13 *
14 * @return array
15 */
16 public function getLatestOrderedProductsInfo(array $productIds, $websiteId)
Returns information about who and when bought the products.
PreviouslyPurchasedOrderStatusesProvider
Class PreviouslyPurchasedOrderStatusesProvider.
This service implements OrderStatusesProviderInterface and contains methods which return applicable statuses for the order. For example:
1 /**
2 * @param AbstractEnumValue|null $status
3 * @return bool
4 */
5 protected function isAllowedStatus(AbstractEnumValue $status = null)
6 {
7 // statusProvider implements OrderStatusesProviderInterface
8 $availableStatuses = $this->statusesProvider->getAvailableStatuses();
9 $statusId = $status !== null ? $status->getId() : null;
10
11 return in_array($statusId, $availableStatuses);
12 }
getAvailableStatuses
1public function getAvailableStatuses()
This method returns an array of applicable statuses for an order. It is used in ReindexProductOrderListener, ReindexProductLineItemListener and LatestOrderedProductsInfoProvider.