def _add_upsell(form, cart, i):
    field_include = "upsell_include_%s" % i
    field_qty = "upsell_qty_%s" % i
    field_slug = "upsell_slug_%s" % i
    slug = ""
    qty = Decimal('0')

    if form.get(field_include, "false") == "true":
        slug = form.get(field_slug, "")
        if slug:
            try:
                rawqty = form.get(field_qty, 0)
                if rawqty == "MATCH":
                    qty = Decimal(form['quantity'])
                elif rawqty:
                    qty = Decimal(rawqty)
            except __HOLE__:
                log.debug('Bad upsell qty=%d', rawqty)
                qty = Decimal('0')
            except InvalidOperation:
                log.debug('Bad upsell qty=%d', rawqty)
                qty = Decimal('0')


        if qty > 0:
            from product.models import Product
            try:
                product = Product.objects.get_by_site(slug=slug)

                try:
                    cart.add_item(product, number_added=qty)
                    log.info('Added upsell item: %s qty=%d', product.slug, qty)
                    return (True, product)

                except CartAddProhibited, cap:
                    vetomsg = cap.veto_messages()
                    msg = _("'%(product)s' couldn't be added to the cart. %(details)s") % {
                        'product' : product.slug,
                        'detail' : cap.message
                        }
                    log.debug("Failed to add upsell item: '%s', message= %s", product.slug, msg)
                    return (False, product)

            except Product.DoesNotExist:
                log.debug("Could not find product: %s", slug)
                return (False, None)

    return (False, None)
dataset/ETHPy150Open dokterbob/satchmo/satchmo/apps/satchmo_ext/upsell/views.py/_add_upsell