Author: jleroux
Date: Sun Sep 28 19:48:53 2014
New Revision: 1628096
URL: http://svn.apache.org/r1628096
Log:
A patch from Anahita Goljahani for "Duplicated 'ALSO_BOUGHT' associations in
product details page" https://issues.apache.org/jira/browse/OFBIZ-5782
I have noticed an undesired behavior when two products are associated by the
"ALSO_BOUGHT" association type.
Specifically, when a product, e.g., Tiny Gizmo (productId = "GZ-1000"), is
associated to another product, e.g., Micro Chrome Widget (productIdTo =
"WG-1111"), by setting productAssocTypeId equal to "ALSO_BOUGHT" in
ProductAssoc, the Tiny Gizmo web page in the ecommerce site correctly shows the
Micro Chrome Widget as "Customers who bought this item also bought:".
Accordingly with the current software behavior, even if Micro Chrome Widget
(productId = "WG-1111") was not explicitly associated to Tiny Gizmo
(productIdTo = "GZ-1000"), also the Micro Chrome Widget web page shows Tiny
Gizmo as "Customers who bought this item also bought:", which may be useful in
cases where the 'ALSO_BOUGHT' association is meant to be necessarily
bidirectional, i.e., if prodA is associated to prodB, then prodB is associated
to prodA and vice-versa. However, when the user wants to express the symmetric
nature of the relationship by explicitly associating both Tiny Gizmo to Micro
Chrome Widget and Micro
Chrome Widget to Tiny Gizmo in ProductAssoc, the system erroneously shows the
associated products twice, both in the Tiny Gizmo and Micro Chrome web pages.
The undesired behavior can be reproduced as follows:
# Run OFBiz with demo data
# import the following associations from the OFBiz XML Data Import form
{code}
<ProductAssoc productId="GZ-1000" productIdTo="WG-1111"
productAssocTypeId="ALSO_BOUGHT" fromDate="2014-09-02 12:00:00.000"/>
<ProductAssoc productId="WG-1111" productIdTo="GZ-1000"
productAssocTypeId="ALSO_BOUGHT" fromDate="2014-09-02 12:00:00.000"/>
{code}
# click on Tiny Gizmo or Micro Chrome Widget from the main page of the
ecommerce site.
The attached patch modifies the above behavior as follows:
- if only "prodA" (productId = "prodA") is associated to "prodB" (productIdTo =
"prodB") in ProductAssoc, and not vice-versa, only "prodA" web page shows
"prodB" as "Customers who bought this item also bought:". This means that the
'ALSO_BOUGHT' association type becomes not necessarily bidirectional by
default, which is in accordance with most common algorithms for the automatic
generation of "WHO BOUGHT X ALSO BOUGHT Y" recommendations that may produce
bidirectional associations for some couple of products and not for others,
based on conditional probabilities and actual users behavior;
- in those specific cases in which the association is actually bidirectional
for a certain couple of products (prodA, prodB), i.e., both 'prodA to prodB'
and 'prodB to prodA' associations are present in ProductAssoc, associated
products are shown only ones in prodA and prodB web pages.
The patch simply sets the value of the parameter "bidirectional" to its default
value, i.e., "false", when alsoBoughtProducts are collected by calling
getAssociatedProducts() from
applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy.
Modified:
ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy
Modified:
ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy?rev=1628096&r1=1628095&r2=1628096&view=diff
==============================================================================
---
ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy
(original)
+++
ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy
Sun Sep 28 19:48:53 2014
@@ -577,7 +577,7 @@ if (product) {
context.availableInventory = availableInventory;
// get product associations
- alsoBoughtProducts = dispatcher.runSync("getAssociatedProducts",
[productId : productId, type : "ALSO_BOUGHT", checkViewAllow : true,
prodCatalogId : currentCatalogId, bidirectional : true, sortDescending : true]);
+ alsoBoughtProducts = dispatcher.runSync("getAssociatedProducts",
[productId : productId, type : "ALSO_BOUGHT", checkViewAllow : true,
prodCatalogId : currentCatalogId, bidirectional : false, sortDescending :
true]);
context.alsoBoughtProducts = alsoBoughtProducts.assocProducts;
obsoleteProducts = dispatcher.runSync("getAssociatedProducts", [productId
: productId, type : "PRODUCT_OBSOLESCENCE", checkViewAllow : true,
prodCatalogId : currentCatalogId]);