Author: mor
Date: Fri May 22 12:42:12 2009 New Revision: 777498 URL: http://svn.apache.org/viewvc?rev=777498&view=rev Log: Now onwards out of stock items will not show up in the ecommerce site. Added a scheduled service that will run hourly and will update the new attribute isOutOfStock on Product entity to Y/N where Y means item is out of stock and N means item is in stock. This process will be efficient in a way that the database interaction to check whether item is out of stock will not take place everytime products are loaded on the ecommerce site. Applied my patch (initially contributed by Amit Sharma, I have done some improvements over this patch), part of OFBIZ-2480 (https://issues.apache.org/jira/browse/OFBIZ-2480) Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy ofbiz/trunk/applications/product/data/ProductScheduledServices.xml ofbiz/trunk/applications/product/entitydef/entitymodel.xml ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml ofbiz/trunk/applications/product/servicedef/services_facility.xml Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy?rev=777498&r1=777497&r2=777498&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/CategoryDetail.groovy Fri May 22 12:42:12 2009 @@ -59,7 +59,18 @@ catResult = dispatcher.runSync("getProductCategoryAndLimitedMembers", andMap); productCategory = catResult.productCategory; -context.productCategoryMembers = catResult.productCategoryMembers; + +// Prevents out of stock product to be displayed on site +productCategoryMembers = catResult.productCategoryMembers; +productsInStock = []; +productCategoryMembers.each { productCategoryMember -> + product = productCategoryMember.getRelatedOne("Product"); + if ((!product.isOutOfStock) || ("N".equals(product.isOutOfStock))) { + productsInStock.add(productCategoryMember); + } +} + +context.productCategoryMembers = productsInStock; context.productCategory = productCategory; context.viewIndex = catResult.viewIndex; context.viewSize = catResult.viewSize; Modified: ofbiz/trunk/applications/product/data/ProductScheduledServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/data/ProductScheduledServices.xml?rev=777498&r1=777497&r2=777498&view=diff ============================================================================== --- ofbiz/trunk/applications/product/data/ProductScheduledServices.xml (original) +++ ofbiz/trunk/applications/product/data/ProductScheduledServices.xml Fri May 22 12:42:12 2009 @@ -21,6 +21,26 @@ <entity-engine-xml> <JobSandbox jobId="8100" jobName="Purge Old Store Auto-Entered Promos" runTime="2000-01-01 00:00:00.000" serviceName="purgeOldStoreAutoPromos" poolId="pool" runAsUser="system" tempExprId="MIDNIGHT_DAILY" maxRecurrenceCount="-1"/> + <RecurrenceRule recurrenceRuleId="500" untilDateTime="" frequency="HOURLY" intervalNumber="1" countNumber="-1"/> + <RecurrenceInfo recurrenceInfoId="500" startDateTime="2008-05-14 22:00:00.000" recurrenceRuleId="500" recurrenceCount="0"/> + <RuntimeData runtimeDataId="8801"> + <runtimeInfo><![CDATA[<?xml version="1.0" encoding="UTF-8"?> + <ofbiz-ser> + <map-HashMap> + <map-Entry> + <map-Key> + <std-String value="recurrenceInfoId"/> + </map-Key> + <map-Value> + <std-String value="500"/> + </map-Value> + </map-Entry> + </map-HashMap> + </ofbiz-ser> + ]]></runtimeInfo> + </RuntimeData> + <JobSandbox jobId="8801" jobName="Check Stock Availability" runTime="2000-01-01 00:00:00.000" serviceName="checkStockAvailability" runtimeDataId="8801" poolId="pool" runAsUser="system" recurrenceInfoId="500"/> + <!--Data for scheduling the service productImportFromSpreadsheet --> <!--RecurrenceRule recurrenceRuleId="500" untilDateTime="" frequency="MINUTELY" intervalNumber="5" countNumber="-1"/> <RecurrenceInfo recurrenceInfoId="500" startDateTime="2006-06-06 01:10:00.000" recurrenceRuleId="500" recurrenceCount="0"/> Modified: ofbiz/trunk/applications/product/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitymodel.xml?rev=777498&r1=777497&r2=777498&view=diff ============================================================================== --- ofbiz/trunk/applications/product/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/applications/product/entitydef/entitymodel.xml Fri May 22 12:42:12 2009 @@ -2589,6 +2589,7 @@ <field name="lastModifiedByUserLogin" type="id-vlong"></field> <field name="inShippingBox" type="indicator"></field> <field name="defaultShipmentBoxTypeId" type="id"></field> + <field name="isOutOfStock" type="indicator"><description>This field defines whether the product is out of stock or not</description></field> <prim-key field="productId"/> <relation type="one" fk-name="PROD_TYPE" rel-entity-name="ProductType"> <key-map field-name="productTypeId"/> Modified: ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml?rev=777498&r1=777497&r2=777498&view=diff ============================================================================== --- ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml (original) +++ ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryServices.xml Fri May 22 12:42:12 2009 @@ -1293,4 +1293,30 @@ </else> </if-empty> </simple-method> + + <simple-method method-name="checkStockAvailability" short-description="Schedule service that check stock availability hourly. If a product is out of stock then it sets flag isOutOfStock on Product entity to Y else it sets it to N" > + <entity-condition entity-name="Product" list="products" use-cache="true"> + <use-iterator/> + </entity-condition> + <iterate list="products" entry="product"> + <set field="serviceInMap.productId" from-field="product.productId"/> + <call-service service-name="getProductInventoryAvailable" in-map-name="serviceInMap"> + <result-to-field result-name="availableToPromiseTotal"/> + </call-service> + <if-compare field="availableToPromiseTotal" operator="less-equals" value="0" type="BigDecimal"> + <set field="product.isOutOfStock" value="Y"/> + <else> + <set field="product.isOutOfStock" value="N"/> + </else> + </if-compare> + <entity-one entity-name="UserLogin" value-field="userLogin" auto-field-map="false"> + <field-map field-name="userLoginId" value="system"/> + </entity-one> + <set-service-fields service-name="updateProduct" map="product" to-map="updateProductCtx"/> + <set-service-fields service-name="updateProduct" map="userLogin" to-map="updateProductCtx"/> + <call-service service-name="updateProduct" in-map-name="updateProductCtx"/> + <clear-field field="product"/> + <clear-field field="updateProductCtx"/> + </iterate> + </simple-method> </simple-methods> \ No newline at end of file Modified: ofbiz/trunk/applications/product/servicedef/services_facility.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_facility.xml?rev=777498&r1=777497&r2=777498&view=diff ============================================================================== --- ofbiz/trunk/applications/product/servicedef/services_facility.xml (original) +++ ofbiz/trunk/applications/product/servicedef/services_facility.xml Fri May 22 12:42:12 2009 @@ -890,4 +890,9 @@ <attribute name="productId" type="String" mode="IN" optional="false"/> <attribute name="LocationList" type="List" mode="OUT" optional="true"/> </service> + <service name="checkStockAvailability" engine="simple" + location="component://product/script/org/ofbiz/product/inventory/InventoryServices.xml" invoke="checkStockAvailability"> + <description>Schedule service that check stock availability hourly. If a product is out of stock then it sets flag isOutOfStock on Product entity to Y else it sets it to N</description> + <attribute name="recurrenceInfoId" mode="IN" type="String" optional="false"/> + </service> </services> |
Free forum by Nabble | Edit this page |