コード例 #1
0
def basket_recalc(request):
    products = SortedDict()
    basket = request.vt_basket['products']
    price_sum = 0
    variants = {}
    full_qty = 0

    for val in basket.itervalues():
        for key, qty in val.iteritems():
            variants[key] = qty

    variant_products = qset_to_dict(
        ProductVariant.active_objects.filter(pk__in=variants.keys()))

    for product in Product.active_objects.filter(pk__in=basket.keys()):
        bp = basket[unicode(product.pk)]

        product.variants = SortedDict()

        for key, qty in bp.iteritems():  #cycle on variants in basket
            key = int(key)
            if key in variant_products:
                vpr = variant_products[key].price_get()
                variant_title = variant_products[key].title
            else:
                vpr = product.price_get()
                variant_title = product.title

            vps = vpr * qty
            price_sum += vps
            full_qty += qty

            product.variants[key] = {
                'qty': qty,
                'sum': vps,
                'vpr': vpr,
                'variant_title': variant_title
            }

        products[product.pk] = product

    request.vt_basket['sum'] = price_sum
    request.vt_basket['qty'] = full_qty

    pc_curr, dt_next, pc_next = Discount.discount_get(price_sum)

    dsc = price_sum * pc_curr / 100
    request.vt_basket['dsc_sum'] = price_sum - dsc

    request.session.save()

    return {
        'sum': price_sum,
        'qty': full_qty,
        'dsc': dsc,
        'dsc_sum': request.vt_basket['dsc_sum'],
        'pc_curr': pc_curr,
        'dt_next': dt_next,  #delta_next
        'pc_next': pc_next
    }, products
コード例 #2
0
    def handle(self, *args, **options):
        st = qset_to_dict(Settings.objects.all(), 'name')
        linked_discount = float(st['linked_discount'].value)

        proxy_data = {'headers': {'User-Agent': random_user_agent()}}
        for lp in LinkedPrice.active_objects.select_related('product', 'linked_site').all():
            s = requests.session()

            proxy_data['headers']['User-Agent'] = random_user_agent()
            res = s.get(lp.url, **proxy_data)

            try:
                pq = PyQuery(res.content)
                price = pq('[itemprop="offers"] .price')
                if len(price):
                    price = float(price.text().replace(' ', '').replace(u'p.', ''))
                    lp.price = price
                    lp.save()

                    price += linked_discount
                    if lp.product.price_stop <= price and lp.product.price > lp.price:
                        lp.product.price = price
                        lp.product.save()
            except BaseException, e:
                logger.debug('cant find price %s' % lp.url)
コード例 #3
0
ファイル: views.py プロジェクト: vaad2/flowershop
def basket_recalc(request):
    products = SortedDict()
    basket = request.vt_basket['products']
    price_sum = 0
    variants = {}
    full_qty = 0

    for val in basket.itervalues():
        for key, qty in val.iteritems():
            variants[key] = qty

    variant_products = qset_to_dict(ProductVariant.active_objects.filter(pk__in=variants.keys()))

    for product in Product.active_objects.filter(pk__in=basket.keys()):
        bp = basket[unicode(product.pk)]

        product.variants = SortedDict()

        for key, qty in bp.iteritems():  #cycle on variants in basket
            key = int(key)
            if key in variant_products:
                vpr = variant_products[key].price_get()
                variant_title = variant_products[key].title
            else:
                vpr = product.price_get()
                variant_title = product.title

            vps = vpr * qty
            price_sum += vps
            full_qty += qty

            product.variants[key] = {
                'qty': qty,
                'sum': vps,
                'vpr': vpr,
                'variant_title': variant_title
            }

        products[product.pk] = product

    request.vt_basket['sum'] = price_sum
    request.vt_basket['qty'] = full_qty

    pc_curr, dt_next, pc_next = Discount.discount_get(price_sum)

    dsc = price_sum * pc_curr / 100
    request.vt_basket['dsc_sum'] = price_sum - dsc

    request.session.save()

    return {
               'sum': price_sum,
               'qty': full_qty,
               'dsc': dsc,
               'dsc_sum': request.vt_basket['dsc_sum'],
               'pc_curr': pc_curr,
               'dt_next': dt_next,  #delta_next
               'pc_next': pc_next

           }, products
コード例 #4
0
def robokassa_get():
    st = qset_to_dict(Settings.objects.all(), 'name')

    robokassa_test_mode = False
    if 'robokassa_test_mode' in st:
        robokassa_test_mode = bool(st['robokassa_test_mode'].value)

    robo = VTRobokassa(TestMode=robokassa_test_mode,
                       MerchantLogin=st['robokassa_login'].value,
                       MerchantPass1=st['robokassa_pass1'].value,
                       MerchantPass2=st['robokassa_pass2'].value)

    return robo
コード例 #5
0
ファイル: views.py プロジェクト: vaad2/flowershop
def robokassa_get():
    st = qset_to_dict(Settings.objects.all(), 'name')

    robokassa_test_mode = False
    if 'robokassa_test_mode' in st:
        robokassa_test_mode = bool(st['robokassa_test_mode'].value)

    robo = VTRobokassa(TestMode=robokassa_test_mode,
                       MerchantLogin=st['robokassa_login'].value,
                       MerchantPass1=st['robokassa_pass1'].value,
                       MerchantPass2=st['robokassa_pass2'].value)

    return robo
コード例 #6
0
ファイル: views.py プロジェクト: vaad2/flowershop
    def get_context_data(self, **kwargs):
        context = super(ViewIndex, self).get_context_data(**kwargs)

        try:
            context['slider'] = Slider.active_objects.get(slug='index')
        except Slider.DoesNotExist:
            logger.debug('slider not found')

        st = qset_to_dict(Settings.objects.all(), key='name')

        index_news = 4
        index_products = 8
        if 'index_news' in st:
            index_news = st['index_news'].value

        if 'index_products' in st:
            index_products = st['index_products'].value

        context['news'] = News.active_objects.all()[0:int(index_news)]
        context['products'] = products_photos_get(
            Product.active_objects.all().order_by('-popular_cnt')[0:int(index_products)])

        return context
コード例 #7
0
    def get_context_data(self, **kwargs):
        context = super(ViewIndex, self).get_context_data(**kwargs)

        try:
            context['slider'] = Slider.active_objects.get(slug='index')
        except Slider.DoesNotExist:
            logger.debug('slider not found')

        st = qset_to_dict(Settings.objects.all(), key='name')

        index_news = 4
        index_products = 8
        if 'index_news' in st:
            index_news = st['index_news'].value

        if 'index_products' in st:
            index_products = st['index_products'].value

        context['news'] = News.active_objects.all()[0:int(index_news)]
        context['products'] = products_photos_get(
            Product.active_objects.all().order_by(
                '-popular_cnt')[0:int(index_products)])

        return context
コード例 #8
0
                                                 product_variant_id=pvk,
                                                 qty=pv['qty'],
                                                 sum=pv['sum'])

            bsk['products'] = {}
            bsk['sum'] = 0
            bsk['qty'] = 0
            #
            request.session.save()

            sms_send(
                u'Сформирован заказ N%s на %s р. Телефон %s, имя %s, email %s '
                % (shop_order.pk, shop_order.summary, shop_order.client_phone,
                   shop_order.client_name, shop_order.client_email))

            st = qset_to_dict(Settings.objects.all(), key='name')
            mail_manager = st[
                'mail_manager'].value if 'mail_manager' in st else '*****@*****.**'

            mail_send_order(shop_order.pk, to=shop_order.client_email)
            mail_send_order(
                shop_order.pk,
                to=mail_manager,
                subject=u'В магазине flowershop.ru сделан заказ №%s' %
                shop_order.pk)

            return True, {
                'redirect':
                reverse('frontend:view_confirm', kwargs={'pk': shop_order.pk})
            }
コード例 #9
0
ファイル: views.py プロジェクト: vaad2/flowershop
            bsk['products'] = {}
            bsk['sum'] = 0
            bsk['qty'] = 0
            #
            request.session.save()

            sms_send(u'Сформирован заказ N%s на %s р. Телефон %s, имя %s, email %s ' % (
                shop_order.pk,
                shop_order.summary,
                shop_order.client_phone,
                shop_order.client_name,
                shop_order.client_email
            ))

            st = qset_to_dict(Settings.objects.all(), key='name')
            mail_manager = st['mail_manager'].value if 'mail_manager' in st else '*****@*****.**'

            mail_send_order(shop_order.pk, to=shop_order.client_email)
            mail_send_order(shop_order.pk, to=mail_manager,
                            subject=u'В магазине flowershop.ru сделан заказ №%s' % shop_order.pk)

            return True, {'redirect': reverse('frontend:view_confirm', kwargs={'pk': shop_order.pk})}

        return False


    def _summary_recalc(self):
        di = self.request.session['delivery_info']

        if di['city'] == 3: