Hi,
I'm working with a shop which needs to extend CartItem and OrderItem
instances with additional data. I mean it adds *ItemDetails and also
external models which have OneToOne relation to *Item objects. To make
it working without refactoring Satchmo models to my own needs, I tried
to find a flexible solution which could help others create similar
extensions in future.
The result is an extended signals set for Satchmo and changed CartItem
stacking:
1. satchmo_cart_details_query signal, which is launched just before a
new CartItem is created.
#satchmo_cart_details_query.send(cart, product, quantity, details,
request, formdata)
The key item here is details={} dict, which can be filled by listeners
with additional item details.
Please notice that the signal provides listeners with a request object
which has been passed to satchmo_cart_add view. This means additional
parameters for item can be passed to external applications without the
need to override satchmo_cart_add with own custom view.
2. Here comes the CartItems stacking patch which I submitted (http://
www.satchmoproject.com/trac/ticket/484). In simple words, only the
same products with exactly equal set of details can be stacked in a
cart as one CartItem. This allows us to preserve details set by
external applications.
3. satchmo_post_copy_item_to_order signal, which is launched just
after all Product and detail data has been copied from CartItem to
OrderItem.
#satchmo_post_copy_item_to_order.send(cart, cartitem, order,
orderitem)
Both Items are passed as arguments to the listeners. External
applications can copy their model instances.
I think that such changes are completely neutral for existing
applications. The only doubts are expressed in already submitted #484
description, but these are minor issues.
At the moment I cannot provide a complete patch, because after Django
signals refactoring it's already obsolete :)
@Bruce: I know you're working on multi-shop branch and the signals
have been updated there. Can you estimate the date of merging it into
trunk? If it's not going to happen soon, maybe I could switch to
branch and submit my patch there?
--
michał