Issue #1459 resolved

Same item can be registered on wishlist.

Shugo Nakamura
created an issue

Whishlist creates duplicated ProductWish when adding the Product which doesn't have any subtypes.

wishlist.models.ProductWishManager is the following.

class ProductWishManager(models.Manager):
    def create_if_new(self, product, contact, details):
        encoded = simplejson.dumps(details)

        products = ProductWish.objects.filter(product=product, contact=contact, _details=encoded)
        if products and len(products) > 0:
            wish = products[0]
            if len(products) > 1:
                for p in products[1:]:
                    p.delete()
        else:
            wish = ProductWish(product=product, contact=contact)
            wish.details = details
            wish.save()

        return wish

create_if_new seem to check whether same item is already registered or not. But when there are no subtypes, Product._details is None. So the objects.filter should also check whether Product._detail is None or not.

Proposal for solution:

class ProductWishManager(models.Manager):
    def create_if_new(self, product, contact, details):
        if details:
            encoded = simplejson.dumps(details)
            products = ProductWish.objects.filter(product=product, contact=contact, _details=encoded)
        else:
            products = ProductWish.objects.filter(product=product, contact=contact, _details__isnull=True)

        if products and len(products) > 0:
            wish = products[0]
            if len(products) > 1:
                for p in products[1:]:
                    p.delete()
        else:
            wish = ProductWish(product=product, contact=contact)
            wish.details = details
            wish.save()

        return wish

Comments (3)

  1. Chris Moffitt repo owner

    Could you attach a patch or a pull request and I'll apply. This looks good to me but I prefer patches or pull requests to make sure I don't fat finger something.

  2. Log in to comment