[OFBiz] Dev - Calling a java event manytimes (suchas theservice-multi events)

Jacopo Cappellato tiz at sastau.it
Tue Jan 18 14:59:03 EST 2005


Oooops,

the attachment!

----- Original Message ----- 
From: "Si Chen" <schen at graciousstyle.com>
To: "OFBiz Project Development Discussion (High Traffic)" 
<dev at lists.ofbiz.org>
Sent: Tuesday, January 18, 2005 7:45 PM
Subject: Re: [OFBiz] Dev - Calling a java event manytimes (suchas 
theservice-multi events)


> Hi Jacopo,
>
> It is possible that the changes are not being triggered automatically. 
> The changes I made were:
>
> in ShoppingCartHelper.addToCart - there is some code to see if we are 
> working on a PURCHASE_ORDER.  If so, it calls a method in 
> ShoppingCartHelper called getProductSupplier to find the right 
> SupplierProduct entity for the given supplier and quantity.  It will then 
> pass this on to ShoppingCart.addOrIncreaseItem
> in ShoppingCart.addOrIncreaseItem - there is a new method which has a 
> parameter at the end, GenericValue supplierProduct.  If there is a 
> supplierProduct, it will call the ShoppingCart.makePurchaseOrderItem 
> method to create the shopping cart item based on the supplier description, 
> etc. etc.
>
> I think you might be able to get the logic in ShoppingCartHelper.addToCart 
> to find the supplier information and then pass it to 
> ShoppingCart.addOrIncreaseItem?
> The changes are in SVN revision #4291, look for ShoppingCartHelper, 
> ShoppingCart, and ShoppingCartItem changes, and let me know if you have 
> any questions.
>
> Si
>
> Jacopo Cappellato wrote:
>
>> Thanks Si,
>>
>> I've found that and I'm using it to do what I need (i.e. adding cart 
>> items from requirements... as you probably know ;-)). About this 
>> subject... is it possible that some of the new logics for po (supplier's 
>> name and price retrieval etc...) that you have implemented are not 
>> triggered when you add multiple item at once instead of using the single 
>> form?
>>
>> Again thanks,
>>
>> Jacopo
>>
>>
>> ----- Original Message ----- From: "Si Chen" <schen at graciousstyle.com>
>> To: "OFBiz Project Development Discussion (High Traffic)" 
>> <dev at lists.ofbiz.org>
>> Sent: Tuesday, January 18, 2005 6:39 PM
>> Subject: Re: [OFBiz] Dev - Calling a java event many times (suchas 
>> theservice-multi events)
>>
>>
>>> Hi Jacopo,
>>>
>>> David showed a "Quick Add" category at the users' conference last year 
>>> where you can add multiple items to the cart at once.  Maybe you can 
>>> take a look at that and see if it satisfies your requirement?
>>>
>>> If not, I have some code for adding multiple items to the cart from a 
>>> form that I can send to you.  Let me know if you want to see it.
>>>
>>> Si
>>>
>>>
>>> Jacopo Cappellato wrote:
>>>
>>>> David, BJ,
>>>>
>>>> thanks for your help.
>>>> David, the only reason for not implementing this as a service is that 
>>>> the additem event is actually implemented as a 'java' event 
>>>> (ShoppingCartEvents.addToCart) and I was trying to re-use it. However 
>>>> it was not probably a good idea, so I'm writing a new 'java' event in 
>>>> ShoppingCartEvents that can process rows from a multi form (actually 
>>>> adding requirements to the shopping cart).
>>>>
>>>> Jacopo
>>>>
>>>>
>>>> ----- Original Message ----- From: "David E. Jones" <jonesde at ofbiz.org>
>>>> To: "OFBiz Project Development Discussion (High Traffic)"
>>>> <dev at lists.ofbiz.org>
>>>> Sent: Tuesday, January 18, 2005 1:09 PM
>>>> Subject: Re: [OFBiz] Dev - Calling a java event many times (such as
>>>> theservice-multi events)
>>>>
>>>>
>>>> Jacopo,
>>>>
>>>> I'm not sure what a multi-event type handler would look like, though I
>>>> suppose it could work.
>>>>
>>>> Wrapping an even with a service is in general a pretty bad idea since
>>>> it requires moving in the wrong direction through the architectural
>>>> tiers, and therefore will most likely cause "real world" problems as
>>>> well.
>>>>
>>>> The approach taken to date for this sort of thing is to have a wrapping
>>>> event, which requires more work per-event, but usually if it is not
>>>> possible to put the logic in a service (why isn't that possible by the
>>>> way?), then other generic tools also don't do so well.
>>>>
>>>> -David
>>>>
>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Dev mailing list
>>>>> Dev at lists.ofbiz.org
>>>>> http://lists.ofbiz.org/mailman/listinfo/dev
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Dev mailing list
>>>> Dev at lists.ofbiz.org
>>>> http://lists.ofbiz.org/mailman/listinfo/dev
>>>>
>>>
>>> _______________________________________________
>>> Dev mailing list
>>> Dev at lists.ofbiz.org
>>> http://lists.ofbiz.org/mailman/listinfo/dev
>>
>>
>>
>> _______________________________________________
>> Dev mailing list
>> Dev at lists.ofbiz.org
>> http://lists.ofbiz.org/mailman/listinfo/dev
>>
>
> _______________________________________________
> Dev mailing list
> Dev at lists.ofbiz.org
> http://lists.ofbiz.org/mailman/listinfo/dev 
-------------- next part --------------


    public int addOrIncreaseItem(String productId, double selectedAmount, double quantity, Timestamp reservStart, double reservLength, double reservPersons, Map features, Map attributes, String prodCatalogId, ProductConfigWrapper configWrapper, LocalDispatcher dispatcher) throws CartItemModifyException, ItemNotFoundException {
        //
        // Product supplier is no more an argument
        GenericValue productSupplier = null;
        // Check for existing cart item.
        for (int i = 0; i < this.cartLines.size(); i++) {
            ShoppingCartItem sci = (ShoppingCartItem) cartLines.get(i);

            if (sci.equals(productId, reservStart, reservLength, reservPersons, features, attributes, prodCatalogId, configWrapper, selectedAmount)) {
                double newQuantity = sci.getQuantity() + quantity;

                if (Debug.verboseOn()) Debug.logVerbose("Found a match for id " + productId + " on line " + i + ", updating quantity to " + newQuantity, module);
                sci.setQuantity(newQuantity, dispatcher, this);

                if (getOrderType().equals("PURCHASE_ORDER")) {
                    supplierProduct = null;
                    Map params = UtilMisc.toMap("productId", productId,
                                                "partyId", this.getPartyId(),
                                                "currencyUomId", this.getCurrency(),
                                                "quantity", new Double(newQuantity));
                    try {
                        Map result = dispatcher.runSync("getSuppliersForProduct", params);
                        List productSuppliers = (List)result.get("supplierProducts");
                        if ((productSuppliers != null) && (productSuppliers.size() > 0)) {
                            supplierProduct = (GenericValue) productSuppliers.get(0);
                        }
                    //} catch (GenericServiceException e) {
                    } catch (Exception e) {
                       Debug.logWarning("Run service [getSuppliersForProduct] error:" + e.getMessage(), module);
                    }
                    if (supplierProduct != null && supplierProduct.getDouble("lastPrice") != null) {
                        sci.setBasePrice(supplierProduct.getDouble("lastPrice").doubleValue());
                        sci.setName(ShoppingCartItem.getPurchaseOrderItemDescription(sci.getProduct(), supplierProduct, this.getLocale()));
                    }
                 }
                return i;
            }
        }
        if (getOrderType().equals("PURCHASE_ORDER")) {
            //GenericValue productSupplier = null;
            supplierProduct = null;
            Map params = UtilMisc.toMap("productId", productId,
                                                "partyId", this.getPartyId(),
                                                "currencyUomId", this.getCurrency(),
                                                "quantity", new Double(quantity));
            try {
                Map result = dispatcher.runSync("getSuppliersForProduct", params);
                List productSuppliers = (List)result.get("supplierProducts");
                if ((productSuppliers != null) && (productSuppliers.size() > 0)) {
                    supplierProduct = (GenericValue) productSuppliers.get(0);
                }
            //} catch (GenericServiceException e) {
            } catch (Exception e) {
                Debug.logWarning("Run service [getSuppliersForProduct] error:" + e.getMessage(), module);
            }
        }
        // Add the new item to the shopping cart if it wasn't found.
        if (supplierProduct != null) {
             return this.addItem(0, ShoppingCartItem.makePurchaseOrderItem(new Integer(0), productId, selectedAmount, quantity, features, attributes, prodCatalogId, configWrapper, dispatcher, this, supplierProduct));
        } else {
            return this.addItem(0, ShoppingCartItem.makeItem(new Integer(0), productId, selectedAmount, quantity, reservStart, reservLength, reservPersons, features, attributes, prodCatalogId, configWrapper, dispatcher, this));
        }
    }


More information about the Dev mailing list