Author: hansbak
Date: Wed Mar 17 08:08:00 2010 New Revision: 924187 URL: http://svn.apache.org/viewvc?rev=924187&view=rev Log: Ebay store update: Automatic repost a product listing when the duration time of the listing has ended. This service will start after the user has checked 'enable AutoRelistingItem' in auto preferences screen. Modified: ofbiz/trunk/specialpurpose/ebaystore/config/EbayStoreUiLabels.xml ofbiz/trunk/specialpurpose/ebaystore/servicedef/services.xml ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreAutoPreferences.java ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java ofbiz/trunk/specialpurpose/ebaystore/widget/EbaySellingManagerForms.xml ofbiz/trunk/specialpurpose/ebaystore/widget/EbaySellingManagerScreens.xml Modified: ofbiz/trunk/specialpurpose/ebaystore/config/EbayStoreUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/config/EbayStoreUiLabels.xml?rev=924187&r1=924186&r2=924187&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/config/EbayStoreUiLabels.xml (original) +++ ofbiz/trunk/specialpurpose/ebaystore/config/EbayStoreUiLabels.xml Wed Mar 17 08:08:00 2010 @@ -296,4 +296,10 @@ <property key="EbayActive"> <value xml:lang="en">Active</value> </property> + <property key="EbayAutoRelistingItems"> + <value xml:lang="en">Auto Relisting Items</value> + </property> + <property key="EbayAutoRelistingItemsDescription"> + <value xml:lang="en">Auto Relisting Items when they are end item.</value> + </property> </resource> \ No newline at end of file Modified: ofbiz/trunk/specialpurpose/ebaystore/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/servicedef/services.xml?rev=924187&r1=924186&r2=924187&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/servicedef/services.xml (original) +++ ofbiz/trunk/specialpurpose/ebaystore/servicedef/services.xml Wed Mar 17 08:08:00 2010 @@ -427,4 +427,10 @@ under the License. <attribute name="unsoldeSize" mode="OUT" type="Integer" optional="true"/> <attribute name="scheduledSize" mode="OUT" type="Integer" optional="true"/> </service> + <service name="autoRelistingItems" engine="java" transaction-timeout="7200" + location="org.ofbiz.ebaystore.EbayStoreAutoPreferences" invoke="autoRelistingItems" auth="false"> + <description>Automatic service to re-listing items when They are end item</description> + <attribute name="jobId" mode="IN" type="String" optional="false"/> + <attribute name="productStoreId" mode="IN" type="String" optional="false"/> + </service> </services> \ No newline at end of file Modified: ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreAutoPreferences.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreAutoPreferences.java?rev=924187&r1=924186&r2=924187&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreAutoPreferences.java (original) +++ ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreAutoPreferences.java Wed Mar 17 08:08:00 2010 @@ -59,6 +59,7 @@ import com.ebay.sdk.ApiContext; import com.ebay.sdk.ApiException; import com.ebay.sdk.SdkException; import com.ebay.sdk.SdkSoapException; +import com.ebay.sdk.call.AddItemCall; import com.ebay.sdk.call.AddOrderCall; import com.ebay.sdk.call.AddDisputeCall; import com.ebay.sdk.call.DeleteSellingManagerTemplateCall; @@ -70,6 +71,7 @@ import com.ebay.soap.eBLBaseComponents.A import com.ebay.soap.eBLBaseComponents.AddOrderResponseType; import com.ebay.soap.eBLBaseComponents.AmountType; import com.ebay.sdk.call.RelistItemCall; +import com.ebay.sdk.util.eBayUtil; import com.ebay.soap.eBLBaseComponents.AutomatedLeaveFeedbackEventCodeType; import com.ebay.soap.eBLBaseComponents.BuyerPaymentMethodCodeType; import com.ebay.soap.eBLBaseComponents.CommentTypeCodeType; @@ -83,6 +85,8 @@ import com.ebay.soap.eBLBaseComponents.F import com.ebay.soap.eBLBaseComponents.GetSellingManagerInventoryRequestType; import com.ebay.soap.eBLBaseComponents.GetSellingManagerInventoryResponseType; import com.ebay.soap.eBLBaseComponents.ItemType; +import com.ebay.soap.eBLBaseComponents.ListingDurationCodeType; +import com.ebay.soap.eBLBaseComponents.ListingDurationDefinitionType; import com.ebay.soap.eBLBaseComponents.OrderType; import com.ebay.soap.eBLBaseComponents.ItemType; import com.ebay.soap.eBLBaseComponents.SellingManagerOrderStatusType; @@ -1097,4 +1101,49 @@ public class EbayStoreAutoPreferences { return result; } + public static Map<String, Object> autoRelistingItems(DispatchContext dctx, Map<String, ? extends Object> context) { + Map<String, Object> itemObject = FastMap.newInstance(); + LocalDispatcher dispatcher = dctx.getDispatcher(); + Delegator delegator = dctx.getDelegator(); + Locale locale = (Locale) context.get("locale"); + try { + GenericValue userLogin = delegator.findOne("UserLogin", false, "userLoginId", "system"); + EntityCondition expression1 = EntityCondition.makeCondition("autoRelisting", EntityOperator.EQUALS, "Y"); + EntityCondition expression2 = EntityCondition.makeCondition("endDateTime", EntityOperator.LESS_THAN, UtilDateTime.nowTimestamp()); + EntityCondition expression3 = EntityCondition.makeCondition("itemId", EntityOperator.NOT_EQUAL, null); + List expressions = FastList.newInstance(); + expressions.add(expression1); + expressions.add(expression2); + expressions.add(expression3); + EntityCondition cond = EntityCondition.makeCondition(expressions, EntityOperator.AND); + List<GenericValue> ebayProductListings = delegator.findList("EbayProductListing", cond , null, null, null, false); + for (int index = 0; index < ebayProductListings.size(); index++) { + Map<String, Object> inMap = FastMap.newInstance(); + AddItemCall addItemCall = new AddItemCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator)); + GenericValue ebayProductListing = ebayProductListings.get(index); + ItemType item = EbayStoreHelper.prepareAddItem(delegator, ebayProductListing); + addItemCall.setItem(item); + itemObject.put("addItemCall", addItemCall); + itemObject.put("productListingId", ebayProductListing.getString("productListingId")); + inMap.put("itemObject", itemObject); + inMap.put("userLogin", userLogin); + Map<String, Object>result = dispatcher.runSync("exportProductEachItem", inMap); + String success = (String) result.get("responseMessage"); + if ("success".equals(success)) { + String duration = item.getListingDuration(); + if (duration.length() > 4) { + Timestamp startDateTime = UtilDateTime.nowTimestamp(); + int durationInt = Integer.parseInt(duration.replace("DAYS_", "")); + Timestamp endDateTime = UtilDateTime.addDaysToTimestamp(startDateTime, durationInt); + ebayProductListing.set("startDateTime", startDateTime); + ebayProductListing.set("endDateTime", endDateTime); + ebayProductListing.store(); + } + } + } + } catch (Exception e) { + return ServiceUtil.returnError(e.getMessage()); + } + return ServiceUtil.returnSuccess(); + } } Modified: ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java?rev=924187&r1=924186&r2=924187&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java (original) +++ ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java Wed Mar 17 08:08:00 2010 @@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletReq import javolution.util.FastMap; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; @@ -57,11 +58,24 @@ import com.ebay.sdk.ApiLogging; import com.ebay.sdk.call.AddItemCall; import com.ebay.soap.eBLBaseComponents.AddItemRequestType; import com.ebay.soap.eBLBaseComponents.AddItemResponseType; +import com.ebay.soap.eBLBaseComponents.AmountType; import com.ebay.soap.eBLBaseComponents.BuyerPaymentMethodCodeType; +import com.ebay.soap.eBLBaseComponents.CategoryType; +import com.ebay.soap.eBLBaseComponents.CountryCodeType; +import com.ebay.soap.eBLBaseComponents.CurrencyCodeType; import com.ebay.soap.eBLBaseComponents.GeteBayDetailsResponseType; import com.ebay.soap.eBLBaseComponents.ItemType; +import com.ebay.soap.eBLBaseComponents.ListingDesignerType; +import com.ebay.soap.eBLBaseComponents.ListingTypeCodeType; +import com.ebay.soap.eBLBaseComponents.PictureDetailsType; +import com.ebay.soap.eBLBaseComponents.ReturnPolicyType; +import com.ebay.soap.eBLBaseComponents.ShippingDetailsType; +import com.ebay.soap.eBLBaseComponents.ShippingServiceCodeType; +import com.ebay.soap.eBLBaseComponents.ShippingServiceOptionsType; +import com.ebay.soap.eBLBaseComponents.ShippingTypeCodeType; import com.ebay.soap.eBLBaseComponents.SiteCodeType; import com.ebay.soap.eBLBaseComponents.ShippingLocationDetailsType; +import com.ebay.soap.eBLBaseComponents.VATDetailsType; import org.ofbiz.ebay.EbayHelper; @@ -473,5 +487,120 @@ public class EbayStoreHelper { return ServiceUtil.returnSuccess(); } - + public static ItemType prepareAddItem(Delegator delegator, GenericValue attribute) { + ItemType item = new ItemType(); + try { + List<GenericValue> attrs = delegator.findByAnd("EbayProductListingAttribute", UtilMisc.toMap("productListingId", attribute.getString("productListingId"))); + AmountType amount = new AmountType(); + AmountType shippingServiceCost = new AmountType(); + PictureDetailsType picture = new PictureDetailsType(); + CategoryType category = new CategoryType(); + ListingDesignerType designer = new ListingDesignerType(); + ShippingDetailsType shippingDetail = new ShippingDetailsType(); + ShippingServiceOptionsType shippingOption = new ShippingServiceOptionsType(); + for (int index = 0; index < attrs.size(); index++) { + if ("Title".equals(attrs.get(index).getString("attrName"))) { + item.setTitle(attrs.get(index).getString("attrValue")); + } else if ("SKU".equals(attrs.get(index).getString("attrName"))) { + item.setSKU(attrs.get(index).getString("attrValue")); + } else if ("Currency".equals(attrs.get(index).getString("attrName"))) { + amount.setCurrencyID(CurrencyCodeType.valueOf(attrs.get(index).getString("attrValue"))); + } else if ("Description".equals(attrs.get(index).getString("attrName"))) { + item.setDescription(attrs.get(index).getString("attrValue")); + } else if ("ApplicationData".equals(attrs.get(index).getString("attrName"))) { + item.setApplicationData(attrs.get(index).getString("attrValue")); + } else if ("Country".equals(attrs.get(index).getString("attrName"))) { + item.setCountry(CountryCodeType.valueOf(attrs.get(index).getString("attrValue"))); + } else if ("PictureURL".equals(attrs.get(index).getString("attrName"))) { + String[] pictureUrl = {attrs.get(index).getString("attrValue")}; + picture.setPictureURL(pictureUrl); + } else if ("Site".equals(attrs.get(index).getString("attrName"))) { + item.setSite(SiteCodeType.valueOf(attrs.get(index).getString("attrValue"))); + } else if ("UseTaxTable".equals(attrs.get(index).getString("attrName"))) { + item.setUseTaxTable(Boolean.valueOf(attrs.get(index).getString("attrValue"))); + } else if ("BestOfferEnabled".equals(attrs.get(index).getString("attrName"))) { + item.setBestOfferEnabled(Boolean.valueOf(attrs.get(index).getString("attrValue"))); + } else if ("AutoPayEnabled".equals(attrs.get(index).getString("attrName"))) { + item.setAutoPay(Boolean.valueOf(attrs.get(index).getString("attrValue"))); + } else if ("CategoryID".equals(attrs.get(index).getString("attrName"))) { + category.setCategoryID(attrs.get(index).getString("attrValue")); + } else if ("CategoryLevel".equals(attrs.get(index).getString("attrName"))) { + category.setCategoryLevel(Integer.parseInt(attrs.get(index).getString("attrValue"))); + } else if ("CategoryName".equals(attrs.get(index).getString("attrName"))) { + category.setCategoryName(attrs.get(index).getString("attrValue")); + } else if ("CategoryParentID".equals(attrs.get(index).getString("attrName"))) { + String[] parent = {attrs.get(index).getString("attrValue")}; + category.setCategoryParentID(parent ); + } else if ("LeafCategory".equals(attrs.get(index).getString("attrName"))) { + category.setLeafCategory(Boolean.valueOf(attrs.get(index).getString("attrValue"))); + } else if ("LSD".equals(attrs.get(index).getString("attrName"))) { + category.setLSD(Boolean.valueOf(attrs.get(index).getString("attrValue"))); + } else if ("ReturnsAcceptedOption".equals(attrs.get(index).getString("attrName"))) { + ReturnPolicyType policy = new ReturnPolicyType(); + policy.setReturnsAcceptedOption(attrs.get(index).getString("attrValue")); + item.setReturnPolicy(policy); + } else if ("LayoutID".equals(attrs.get(index).getString("attrName"))) { + designer.setLayoutID(Integer.parseInt(attrs.get(index).getString("attrValue"))); + } else if ("ThemeID".equals(attrs.get(index).getString("attrName"))) { + designer.setThemeID(Integer.parseInt(attrs.get(index).getString("attrValue"))); + } else if ("BuyItNowPrice".equals(attrs.get(index).getString("attrName"))) { + amount = new AmountType(); + amount.setValue(Double.parseDouble(attrs.get(index).getString("attrValue"))); + item.setBuyItNowPrice(amount); + } else if ("ReservePrice".equals(attrs.get(index).getString("attrName"))) { + amount = new AmountType(); + amount.setValue(Double.parseDouble(attrs.get(index).getString("attrValue"))); + item.setReservePrice(amount); + } else if ("ListingType".equals(attrs.get(index).getString("attrName"))) { + item.setListingType(ListingTypeCodeType.valueOf(attrs.get(index).getString("attrValue"))); + } else if ("StartPrice".equals(attrs.get(index).getString("attrName"))) { + amount = new AmountType(); + amount.setValue(Double.parseDouble(attrs.get(index).getString("attrValue"))); + item.setStartPrice(amount); + } else if ("ShippingService".equals(attrs.get(index).getString("attrName"))) { + shippingOption.setShippingService(attrs.get(index).getString("attrValue")); + } else if ("ShippingServiceCost".equals(attrs.get(index).getString("attrName"))) { + shippingServiceCost.setValue(Double.parseDouble(attrs.get(index).getString("attrValue"))); + shippingOption.setShippingServiceCost(shippingServiceCost); + } else if ("ShippingServiceCostCurrency".equals(attrs.get(index).getString("attrName"))) { + shippingServiceCost.setCurrencyID(CurrencyCodeType.valueOf(attrs.get(index).getString("attrValue"))); + shippingOption.setShippingServiceCost(shippingServiceCost); + } else if ("ShippingServicePriority".equals(attrs.get(index).getString("attrName"))) { + shippingOption.setShippingServicePriority(Integer.parseInt(attrs.get(index).getString("attrValue"))); + } else if ("ShippingType".equals(attrs.get(index).getString("attrName"))) { + shippingDetail.setShippingType(ShippingTypeCodeType.valueOf(attrs.get(index).getString("attrValue"))); + } else if ("VATPercent".equals(attrs.get(index).getString("attrName"))) { + VATDetailsType vat = new VATDetailsType(); + vat.setVATPercent(new Float(attrs.get(index).getString("attrValue"))); + item.setVATDetails(vat); + } else if ("Location".equals(attrs.get(index).getString("attrName"))) { + item.setLocation(attrs.get(index).getString("attrValue")); + } else if ("Quantity".equals(attrs.get(index).getString("attrName"))) { + item.setQuantity(Integer.parseInt(attrs.get(index).getString("attrValue"))); + } else if ("ListingDuration".equals(attrs.get(index).getString("attrName"))) { + item.setListingDuration(attrs.get(index).getString("attrValue")); + } else if ("LotSize".equals(attrs.get(index).getString("attrName"))) { + item.setLotSize(Integer.parseInt(attrs.get(index).getString("attrValue"))); + } else if ("PostalCode".equals(attrs.get(index).getString("attrName"))) { + item.setPostalCode(attrs.get(index).getString("attrValue")); + } else if ("Title".equals(attrs.get(index).getString("attrName"))) { + item.setTitle(attrs.get(index).getString("attrValue")); + } + if (category != null) { + item.setPrimaryCategory(category); + } + if (shippingOption != null) { + ShippingServiceOptionsType[] options = {shippingOption}; + shippingDetail.setShippingServiceOptions(options); + } + if (shippingDetail != null) { + item.setShippingDetails(shippingDetail); + } + } + } catch (GenericEntityException e) { + Debug.logError(e.getMessage(), module); + return null; + } + return item; + } } Modified: ofbiz/trunk/specialpurpose/ebaystore/widget/EbaySellingManagerForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/widget/EbaySellingManagerForms.xml?rev=924187&r1=924186&r2=924187&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/widget/EbaySellingManagerForms.xml (original) +++ ofbiz/trunk/specialpurpose/ebaystore/widget/EbaySellingManagerForms.xml Wed Mar 17 08:08:00 2010 @@ -26,9 +26,7 @@ value="${bsh:billingAccount != null ? or <form name="EditAutomationRelistSoldItems" target="createEbayProductStorePref" type="single" default-map-name="ebayPrefRelisting" > <alt-target use-when="ebayPrefRelisting!=null" target="updateEbayProductStorePref"/> <field name="productStoreId"><hidden value="${parameters.productStoreId}"/></field> - <field name="enabled" tooltip="${uiLabelMap.EbayAutoRelisting}" tooltip-style="h3"><check/></field> - <field name="condition1" title="${uiLabelMap.CommonFromDate}"><date-time/></field> - <field name="condition2" title="${uiLabelMap.CommonThruDate}"><date-time/></field> + <field name="enabled" title ="${uiLabelMap.EbayAutoRelistingItems}" tooltip="${uiLabelMap.EbayAutoRelistingItemsDescription}"><check/></field> <field name="serviceName"><hidden value="${serviceName}"/></field> <field name="autoPrefEnumId"><hidden value="${autoPrefEnumId}"/></field> <field name="submit" title="${uiLabelMap.CommonApply}"><submit/></field> Modified: ofbiz/trunk/specialpurpose/ebaystore/widget/EbaySellingManagerScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/widget/EbaySellingManagerScreens.xml?rev=924187&r1=924186&r2=924187&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/widget/EbaySellingManagerScreens.xml (original) +++ ofbiz/trunk/specialpurpose/ebaystore/widget/EbaySellingManagerScreens.xml Wed Mar 17 08:08:00 2010 @@ -279,7 +279,7 @@ <actions> <set field="headerItem" value="ebayStore"/> <set field="autoPrefEnumId" value="EBAY_AUTO_RELISTING"/> - <set field="serviceName" value="automaticEbayRelistSoldItems"/> + <set field="serviceName" value="autoRelistingItems"/> <entity-one value-field="ebayPrefRelisting" entity-name="EbayProductStorePref"> <field-map field-name="productStoreId" from-field="parameters.productStoreId"/> <field-map field-name="autoPrefEnumId" from-field="autoPrefEnumId"/> |
Free forum by Nabble | Edit this page |