Remove cart item signals

Create issue
Issue #1024 wontfix
clang created an issue

I noticed that there are no signals for items being removed from the cart. I had a need for these so attempted to implement them myself. The patch is attached.

The signals are based on the existing satchmo_cart_add_{verify, complete} signals. However at present satchmo_cart_remove_verify is never raised because Cart.remove_item doesn't seem to be called anywhere.

The signals are also being sent from the add/remove_ajax methods, but these are untested as I have no ajax code in my project.

This is my first foray into editting the satchmo code so if I've made some major errors then please let me know!

Comments (3)

  1. Tay Ray Chuan

    Hi,

    pasting your patch here.

    For this hunk:

    diff -r eaae47b51c8a satchmo/apps/satchmo_store/shop/signals.py
    --- a/satchmo/apps/satchmo_store/shop/signals.py	Thu Feb 11 20:55:08 2010 -0600
    +++ b/satchmo/apps/satchmo_store/shop/signals.py	Fri Feb 12 15:25:05 2010 +0000
    @@ -29,6 +29,14 @@
     #satchmo_cart_add_verify(cart, cart=cart, cartitem=cartitem, added_quantity=Decimal('0'), details=details)
     satchmo_cart_add_verify=django.dispatch.Signal()
     
    +#cart_remove_verify signature:
    +#satchmo_cart_remove_verify(sender, cart, cartitem, removed_quantity)
    +satchmo_cart_remove_verify=django.dispatch.Signal()
    +
    +#cart_remove_complete signature:
    +#satchmo_cart_remove_complete(sender, cart, cartitem, product, request)
    +satchmo_cart_remove_complete=django.dispatch.Signal()
    +
     satchmo_cart_changed=django.dispatch.Signal()
     
     #satchmo_cartitem_price_query.send(cartitem, cartitem=cartitem)
    

    Could you make your # doc follow the rest (ie. # <signal>.send(...))?

    Also, I don't see why satchmo_cart_remov_verify should be added if it isn't used.

    diff -r eaae47b51c8a satchmo/apps/satchmo_store/shop/views/cart.py
    --- a/satchmo/apps/satchmo_store/shop/views/cart.py	Thu Feb 11 20:55:08 2010 -0600
    +++ b/satchmo/apps/satchmo_store/shop/views/cart.py	Fri Feb 12 15:25:05 2010 +0000
    @@ -48,6 +48,7 @@
             return False
         
     
    +
     def _set_quantity(request, force_delete=False):
         """Set the quantity for a specific cartitem.
         Checks to make sure the item is actually in the user's cart.
    

    What's this doing here?

    @@ -85,6 +86,7 @@
     
         if qty == Decimal('0'):
             cartitem.delete()
    +        satchmo_cart_remove_complete.send(cart, cart=cart, cartitem=cartitem, product=cartitem.product, request=request)
             cartitem = NullCartItem(itemid)
         else:
             from satchmo_store.shop.models import Config
    @@ -95,6 +97,9 @@
                 if stock < qty:
                     return (False, cart, cartitem, _("Not enough items of '%s' in stock.") % cartitem.product.translated_name())
     
    +        #check we are removing and not adding cartitems
    +        if cartitem.quantity > qty:
    +           satchmo_cart_remove_complete.send(cart, cart=cart, cartitem=cartitem, product=cartitem.product, request=request)
             cartitem.quantity = round_decimal(qty, places=cartplaces)
             cartitem.save()
    

    Could you move those out and put it near where we trigger satchmo_cart_changed?

    @@ -331,6 +336,7 @@
                 data['cart_total'] = str(cart.total)
                 data['cart_count'] = str(round_decimal(cart.numItems, 2)) 
                 data['item_id'] = cartitem.id
    +            satchmo_cart_remove_complete.send(cart, cart=cart, cartitem=cartitem, product=cartitem.product, request=request)
         return _json_response(data, template)
     
     def set_quantity(request):
    

    I believe the signal has already been triggered in _set_quantity, so this isn't needed.

  2. Hynek Cernoch

    Instead of new signals you can be probably use:

    django.db.models.signals.pre_delete.connect(your_listener_1, sender=satchmo_store.shop.models.Cart)
    django.db.models.signals.pre_delete.connect(your_listener_2, sender=satchmo_store.shop.models.CartItem)
    

    in your code.

    There is a difference between importace of special signals for adding and removing. You probably do not need ever to polite forbid removing. Also generic signal is sufficient.

  3. Log in to comment