예제 #1
0
def get_delivery_opts(request, region_id='', new_product=None):
    res_dt = {}
    cur_site = get_current_site(request)

    # city = City.objects.get(pk=region_id)

    if region_id == '':
        cities = City.objects.filter(site=cur_site)
    else:
        cities = City.objects.filter(pk=region_id)

    cart_items = cart.get_cart_items(request)
    products = []
    for item in cart_items:
        products.append(item.product)
    if new_product:
        products.append(new_product)

    delivery_options = DeliveryOption.objects.filter(
        active=True).filter(Q(city__in=cities)
                            | Q(city=None)).filter(site=cur_site)

    res_dt['delivery_options'] = []
    for delivery_option in delivery_options:
        logger.info(str(delivery_option))
        checked_products = []

        pr = 0
        additional_pr = 0
        try:
            delivery_prices = DeliveryPrice.objects.filter(
                delivery_option=delivery_option, product__in=products)
        except:
            delivery_prices = DeliveryPrice.objects.none()

        for delivery_price in delivery_prices:
            pr = delivery_price.price
            additional_pr = delivery_price.additional_price
            if delivery_price.product not in checked_products:
                checked_products.append(delivery_price.product)
        if len(checked_products) == len(products):
            res_dt['delivery_options'].append({
                'id':
                delivery_option.id,
                'name':
                delivery_option.name,
                #'price': "{:.2f}".format(float(delivery_option.price)),
                #'additional_price': "{:.2f}".format(float(delivery_option.additional_price)),
                'price':
                "{:.2f}".format(float(pr)),
                'additional_price':
                "{:.2f}".format(float(additional_pr)),
                'online_payment':
                delivery_option.online_payment
            })
    if len(res_dt['delivery_options']) > 0:
        res_dt['can_continue'] = True
    else:
        res_dt['can_continue'] = False
    return res_dt
예제 #2
0
파일: views.py 프로젝트: xorsnn/lugati
def check_if_order_paid(request):
    res_dt = {'paid': False}
    if not cart.get_cart_items(request).exists():
        orders = Order.objects.filter(cart_id=cart._cart_id(request))
        if orders.exists():
            res_dt['order_id'] = orders[0].id
        res_dt['paid'] = True

    return HttpResponse(json.dumps(res_dt))
예제 #3
0
def can_add_to_cart(request, prod_id=''):
    res_dt = {
        'result': 'success'
    }

    if cart.get_cart_items(request).count() > 0:
        opts_dt = get_delivery_opts(request, new_product=Product.objects.get(pk=prod_id))
        if (not opts_dt['can_continue']):
            res_dt['result'] = 'error'

    return HttpResponse(json.dumps(res_dt))
예제 #4
0
def confirm_order_form_bootstrap(context):
    res_dt = {
        'form': LugatiCofirmOrderForm,
    }
    cart_items = cart.get_cart_items(context['request'])

    if cart_items.count() > 0:
        res_dt['has_items'] = True
    else:
        res_dt['has_items'] = False

    return res_dt
예제 #5
0
파일: views.py 프로젝트: xorsnn/lugati
def get_delivery_opts(request, region_id='', new_product=None):
    res_dt = {}
    cur_site = get_current_site(request)

    # city = City.objects.get(pk=region_id)

    if region_id == '':
        cities = City.objects.filter(site=cur_site)
    else:
        cities = City.objects.filter(pk=region_id)

    cart_items = cart.get_cart_items(request)
    products = []
    for item in cart_items:
        products.append(item.product)
    if new_product:
        products.append(new_product)

    delivery_options = DeliveryOption.objects.filter(active=True).filter(Q(city__in=cities) | Q(city=None)).filter(
        site=cur_site)

    res_dt['delivery_options'] = []
    for delivery_option in delivery_options:
        logger.info(str(delivery_option))
        checked_products = []

        pr = 0
        additional_pr = 0
        try:
            delivery_prices = DeliveryPrice.objects.filter(delivery_option=delivery_option, product__in=products)
        except:
            delivery_prices = DeliveryPrice.objects.none()

        for delivery_price in delivery_prices:
            pr = delivery_price.price
            additional_pr = delivery_price.additional_price
            if delivery_price.product not in checked_products:
                checked_products.append(delivery_price.product)
        if len(checked_products) == len(products):
            res_dt['delivery_options'].append({
                'id': delivery_option.id,
                'name': delivery_option.name,
                #'price': "{:.2f}".format(float(delivery_option.price)),
                #'additional_price': "{:.2f}".format(float(delivery_option.additional_price)),
                'price': "{:.2f}".format(float(pr)),
                'additional_price': "{:.2f}".format(float(additional_pr)),
                'online_payment': delivery_option.online_payment
            })
    if len(res_dt['delivery_options']) > 0:
        res_dt['can_continue'] = True
    else:
        res_dt['can_continue'] = False
    return res_dt
예제 #6
0
def confirm_order_form_bootstrap(context):
    res_dt = {
        'form': LugatiCofirmOrderForm,
    }
    cart_items = cart.get_cart_items(context['request'])

    if cart_items.count() > 0:
        res_dt['has_items'] = True
    else:
        res_dt['has_items'] = False

    return res_dt
예제 #7
0
def lugati_cart_widget(context):
    request = context['request']
    lugati_base_url = request.path
    cur_site = get_current_site(request)

    cart_items = cart.get_cart_items(request)

    total_sum = 0
    for cart_item in cart_items:
        total_sum += cart_item.product.get_price()

    return {
        'lugati_base_url': lugati_base_url,
        'cart_items': cart_items,
        'total_sum': total_sum
    }
예제 #8
0
def lugati_cart_widget(context):
    request = context['request']
    lugati_base_url = request.path
    cur_site = get_current_site(request)

    cart_items = cart.get_cart_items(request)

    total_sum = 0
    for cart_item in cart_items:
        total_sum += cart_item.product.get_price()

    return {
        'lugati_base_url': lugati_base_url,
        'cart_items': cart_items,
        'total_sum': total_sum
    }
예제 #9
0
def get_btc_invoice(request):
    res_dt = {}
    cart_items = cart.get_cart_items(request)
    cart_id = ''
    cart_total = 0
    cart_total_btc = 0
    for cart_item in cart_items:
        cart_total += cart_item.total()
        cart_total_btc += cart_item.get_total_btc()
        if cart_id == '':
            cart_id = cart_item.cart_id

    callback_ticket = CallbackTickets()
    logger.info('creating ticket: ' + str(cart_id))
    callback_ticket.cart_id = str(cart_id)
    callback_ticket.site = get_current_site(request)
    callback_ticket.save()

    PAYMENT_CALLBACK_URL = 'http://merchant.mycelium.com/payment/lugati_coinbase/callback/'

    params = {
        "address": {
            'callback_url':
            PAYMENT_CALLBACK_URL + str(callback_ticket.id) + '/'
        }
    }

    if settings.SHOP_TYPE == 'MPS' and False:
        from lugati.lugati_payment.lugati_mycelium import payment_procs as mycelium_payment_procs
        res = mycelium_payment_procs.make_request(
            settings.MYCELIUM_API_URL + '/generate_receive_address',
            body=json.dumps(params)).read()
    else:
        res = make_request(
            'https://api.coinbase.com/v1/account/generate_receive_address',
            body=json.dumps(params)).read()

    addr_dt = json.loads(res)
    logger.info('adr dt ->')
    logger.info(res)

    res_dt['addr_dt'] = addr_dt
    res_dt['custom'] = str(cart_id)
    res_dt['price'] = str(round(cart_total_btc, 5))
    return HttpResponse(json.dumps(res_dt))
예제 #10
0
파일: views.py 프로젝트: xorsnn/lugati
def get_coinbase_invoce(request):
    cart_items = cart.get_cart_items(request)
    cart_id = ''
    cart_total = 0
    cart_total_btc = 0
    for cart_item in cart_items:
        cart_total += cart_item.total()
        cart_total_btc += cart_item.get_total_btc()
        if cart_id == '':
            cart_id = cart_item.cart_id

    res_dt = {}

    callback_ticket = CallbackTickets()
    logger.info('creating ticket: ' + str(cart_id))
    callback_ticket.cart_id = str(cart_id)
    callback_ticket.site = get_current_site(request)
    callback_ticket.save()

    # addr_dt = account.generate_receive_address(str(callback_ticket.id))
    PAYMENT_CALLBACK_URL = 'http://merchant.mycelium.com/payment/lugati_coinbase/callback/'
    params = {
        "address": {
            'callback_url':
            PAYMENT_CALLBACK_URL + str(callback_ticket.id) + '/'
        }
    }
    res = make_request(
        'https://api.coinbase.com/v1/account/generate_receive_address',
        body=json.dumps(params)).read()
    addr_dt = json.loads(res)

    res_dt['addr_dt'] = addr_dt
    res_dt['custom'] = str(cart_id)
    # res_dt['price'] = str(cart_total)
    # remove !!!!
    # res_dt['price'] = str(0.0001)
    res_dt['price'] = str(round(cart_total_btc, 5))
    return HttpResponse(json.dumps(res_dt))
예제 #11
0
파일: views.py 프로젝트: xorsnn/lugati
def get_btc_invoice(request):
    res_dt = {}
    cart_items = cart.get_cart_items(request)
    cart_id = ''
    cart_total = 0
    cart_total_btc = 0
    for cart_item in cart_items:
        cart_total += cart_item.total()
        cart_total_btc += cart_item.get_total_btc()
        if cart_id == '':
            cart_id = cart_item.cart_id

    callback_ticket = CallbackTickets()
    logger.info('creating ticket: ' + str(cart_id))
    callback_ticket.cart_id = str(cart_id)
    callback_ticket.site = get_current_site(request)
    callback_ticket.save()

    PAYMENT_CALLBACK_URL = 'http://merchant.mycelium.com/payment/lugati_coinbase/callback/'

    params = {"address": {
        'callback_url': PAYMENT_CALLBACK_URL + str(callback_ticket.id) + '/'
    }}

    if settings.SHOP_TYPE == 'MPS' and False:
        from lugati.lugati_payment.lugati_mycelium import payment_procs as mycelium_payment_procs
        res = mycelium_payment_procs.make_request(settings.MYCELIUM_API_URL + '/generate_receive_address', body=json.dumps(params)).read()
    else:
        res = make_request('https://api.coinbase.com/v1/account/generate_receive_address', body=json.dumps(params)).read()

    addr_dt = json.loads(res)
    logger.info('adr dt ->')
    logger.info(res)

    res_dt['addr_dt'] = addr_dt
    res_dt['custom'] = str(cart_id)
    res_dt['price'] = str(round(cart_total_btc, 5))
    return HttpResponse(json.dumps(res_dt))
예제 #12
0
def cart_block_wo_delivery(context):
    res_dt = {}
    cart_items = cart.get_cart_items(context['request'])
    res_dt['cart_items'] = cart_items
    res_dt['wo_delivery'] = True
    return res_dt
예제 #13
0
def cart_block(context):
    res_dt = {}
    cart_items = cart.get_cart_items(context['request'])
    res_dt['cart_items'] = cart_items
    return res_dt
예제 #14
0
def cart_block_wo_delivery(context):
    res_dt = {}
    cart_items = cart.get_cart_items(context['request'])
    res_dt['cart_items'] = cart_items
    res_dt['wo_delivery'] = True
    return res_dt
예제 #15
0
def cart_block(context):
    res_dt = {}
    cart_items = cart.get_cart_items(context['request'])
    res_dt['cart_items'] = cart_items
    return res_dt