shopping cart is broken while removing promotions in some use cases

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

shopping cart is broken while removing promotions in some use cases

Adam Heath-2
We have a client that has requested being able to assign ship group
assignments during browse.  We have this part supported, by adding a
free-form attribute specifying the 'named' target on each ship group.

Where this falls apart, is that as products are added, the promotions
get added and removed each time the products are manipulated.  This
requires us to remember which ship groups have promos attached, then
reapply the promos to all ship groups after any promo work has been done.

I'm having a rather hard time with this logic.

Does anyone else understand what I am trying to do?  If so, are there
any suggestions of existing code somewhere?
Reply | Threaded
Open this post in threaded view
|

Re: shopping cart is broken while removing promotions in some use cases

David E. Jones-2

On Mar 5, 2010, at 12:46 PM, Adam Heath wrote:

> We have a client that has requested being able to assign ship group
> assignments during browse.  We have this part supported, by adding a
> free-form attribute specifying the 'named' target on each ship group.

Based on the rest of this message I'm guessing that "assign ship group assignments" means something like "assign a promotion to a ship group." Is that correct? If so, what does that mean, something like you want to restrict a promotion to a particular ship group? Does the user explicitly select the promotion and associate it to the ship group?

> Where this falls apart, is that as products are added, the promotions
> get added and removed each time the products are manipulated.  This
> requires us to remember which ship groups have promos attached, then
> reapply the promos to all ship groups after any promo work has been done.
>
> I'm having a rather hard time with this logic.
>
> Does anyone else understand what I am trying to do?  If so, are there
> any suggestions of existing code somewhere?

I'm not exactly sure what you're trying to do based on the first paragraph, so I'm not sure how what you describe in the second paragraph is different from what you want.

Based on a guess it sounds like you want some sort of user-selected promotion rather than letting the system select promotions based on promo rule conditions. I'm not sure how the ship groups fit into that, but generally it's probably best to keep those explicit/manual promos in a separate place and add them after the automatic promotions so they don't interfere with the auto promos, unless of course you want a manual one to be able to disqualify an automatic one and then you'd do it before.

-David

Reply | Threaded
Open this post in threaded view
|

Re: shopping cart is broken while removing promotions in some use cases

Adam Heath-2
David E Jones wrote:
> On Mar 5, 2010, at 12:46 PM, Adam Heath wrote:
>
>> We have a client that has requested being able to assign ship group
>> assignments during browse.  We have this part supported, by adding a
>> free-form attribute specifying the 'named' target on each ship group.
>
> Based on the rest of this message I'm guessing that "assign ship group assignments" means something like "assign a promotion to a ship group." Is that correct? If so, what does that mean, something like you want to restrict a promotion to a particular ship group? Does the user explicitly select the promotion and associate it to the ship group?

Yeah, I th ought I wasn't clear enough.

When a user picks a product from the catalog, the client wishes to be
able to assign a ship group to that regular product, and a quantity,
during catalog browse time.

This is complicated by having to support anonymous browsing, without
anyone logged in.  I have this part supported, by setting a generic,
free-form attribute on the ShoppingCartItem(it's a patch I added
recently).

The question becomes what to do with any promos that are added to the
cart.  What ship group should they be assigned to?

What happens if multiple ship groups have been created during browse,
and the quantities get updated?  Any promos that have been assigned to
a previous ship group are removed during the doPromotions logic.

Reply | Threaded
Open this post in threaded view
|

Re: shopping cart is broken while removing promotions in some use cases

Adam Heath-2
Adam Heath wrote:

> David E Jones wrote:
>> On Mar 5, 2010, at 12:46 PM, Adam Heath wrote:
>>
>>> We have a client that has requested being able to assign ship group
>>> assignments during browse.  We have this part supported, by adding a
>>> free-form attribute specifying the 'named' target on each ship group.
>> Based on the rest of this message I'm guessing that "assign ship group assignments" means something like "assign a promotion to a ship group." Is that correct? If so, what does that mean, something like you want to restrict a promotion to a particular ship group? Does the user explicitly select the promotion and associate it to the ship group?
>
> Yeah, I th ought I wasn't clear enough.
>
> When a user picks a product from the catalog, the client wishes to be
> able to assign a ship group to that regular product, and a quantity,
> during catalog browse time.
>
> This is complicated by having to support anonymous browsing, without
> anyone logged in.  I have this part supported, by setting a generic,
> free-form attribute on the ShoppingCartItem(it's a patch I added
> recently).
>
> The question becomes what to do with any promos that are added to the
> cart.  What ship group should they be assigned to?
>
> What happens if multiple ship groups have been created during browse,
> and the quantities get updated?  Any promos that have been assigned to
> a previous ship group are removed during the doPromotions logic.

Wow.  Just got it working.  Man, was it painful.  I'm already on the
third iteration.  I'll try to explain it(but you guys can't see the
code yet, so hopfully I do it well enough).

Existing ofbiz ecommerce let's you add products to your cart.  It also
 can edit quantities, and remove products.  When any of these mutative
events occur, all promo info is cleared out, and promos get re-calulated.

Whenever an item is removed from the cart, it has to also be removed
from any assigned ship groups and item groups.

When new products get added to the cart, you can specify the ship
group and item group to put them in.  You can't do these for promos;
instead, they get added to ship group 0, and no item group.

Our client wanted to be able to assign products to ship groups while
browsing the catalog.  This was simple enough for normal product items.

The difficulty was that promo items get added and removed all the
time, as the cart is mutated.  These promo items get auto-added to
ship group 0, which is very very confusing.  Additionally, if you by 5
of a normal item, and a promo fires to give you a GWP, you'll get 5
separate cart items, all with a quantity of 1, instead of a single
cart item with a quantity of 5.

Now here is my solution.  All this code sits in a custom wrapper
called by our frontend, so shouldn't break any existing ofbiz logic.

1: any product item added to the cart has it's own item group
assigned.  This means every single product item is in a unqiue item group.
2: any time new promos are detected, I add them to the current item
group that is being manipulated.
3: whenever a mutation event occurs for the cart, I go thru all item
groups, find all promos in each item group, and create a map of [item
group]->[product id]->[quantity].
4: mutate the cart
5: all old promos have been removed, and new promos added(most with 1
as the quantity, but it might be that there are some with >1).  These
promos are all in ship group 0, with no item group
6: walk all cart items, skipping promo items, and skipping the cart
item that was just mutated.  any other cart items have their previous
promo items reassigned, by noting a quantity interest in the list of
new promos(again, this is done with an item group/product id/quantity
mapping)
7: any left over promo items get added to the cart item being mutated.
 This handles the case of quantity increasing or decreasing.
8: remove all promo items from the cart(yes, again, in my wrapper).
9: apply all promo quantity interests, merging any duplicate promo
items, so that they have the correct quantity now.  I also have to
merge any promo item adjustments.




Normally, this isn't a problem, as ofbiz currently wai

>

Reply | Threaded
Open this post in threaded view
|

Re: shopping cart is broken while removing promotions in some use cases

Jacopo Cappellato-4
Hi Adam,

On Mar 6, 2010, at 12:09 AM, Adam Heath wrote:

>
> 1: any product item added to the cart has it's own item group
> assigned.  This means every single product item is in a unqiue item group.

Does it mean that we will create an order one ship group per product?

Regards,

Jacopo

Reply | Threaded
Open this post in threaded view
|

Re: shopping cart is broken while removing promotions in some use cases

Adam Heath-2
Jacopo Cappellato wrote:
> Hi Adam,
>
> On Mar 6, 2010, at 12:09 AM, Adam Heath wrote:
>
>> 1: any product item added to the cart has it's own item group
>> assigned.  This means every single product item is in a unqiue item group.
>
> Does it mean that we will create an order one ship group per product?

ship groups are different from item groups.

Reply | Threaded
Open this post in threaded view
|

Re: shopping cart is broken while removing promotions in some use cases

Adam Heath-2
Adam Heath wrote:

> Jacopo Cappellato wrote:
>> Hi Adam,
>>
>> On Mar 6, 2010, at 12:09 AM, Adam Heath wrote:
>>
>>> 1: any product item added to the cart has it's own item group
>>> assigned.  This means every single product item is in a unqiue item group.
>> Does it mean that we will create an order one ship group per product?
>
> ship groups are different from item groups.

I might remove this use of item groups, instead using a cart item
attribute, to store which real items are the cause of which promo
items, per ship group.