예제 #1
0
 def read(self, request, pk=None):
     cart = Cart(request)
     cart_info = cart.summary()
 
     if pk:
         try:
             cart_item = CartItem.objects.get(pk=pk, cart=cart_info.pk)
         except CartItem.DoesNotExist:
             return rc.NOT_FOUND
         
         response = {
             'pk' : cart_item.pk,
             'item' : cart_item.stock_item,
             'quantity' : cart_item.quantity,
         }
         
     else:
         cart_items = []                
         for i in cart:
             item_gallery = ProductGallery.objects.get(product=i.stock_item.product, color=i.stock_item.color)                
             cart_items.append({
                 'product' : i.stock_item.product,
                 'package_count' : i.stock_item.package_count,
                 'color' : i.stock_item.color,
                 'measurement': i.stock_item.measurement,
                 'thumbnails' : build_thumbnail_list(item_gallery),
             })
     
         response = {
             'checked_out' : cart_info.checked_out,
             'created_on' : cart_info.created_on,
             'items' : cart_items,
         }
         
     return response
예제 #2
0
    def update(self, request):
        try:
            item = StockItem.objects.get(
                color=request.form.cleaned_data['color'],
                measurement=request.form.cleaned_data['measurement'],
                product=request.form.cleaned_data['product'])
        except StockItem.DoesNotExist:
            return rc.NOT_FOUND

        quantity = request.form.cleaned_data['quantity']
        cart = Cart(request)
        cart.update(item, item.get_price(), quantity)
        cart_info = cart.summary()
        cart_items = []
        for i in cart:
            thumb = i.stock_item.product.get_thumb()
            cart_items.append({
                'product': i.stock_item.product,
                'package_count': i.stock_item.package_count,
                'quantity': i.quantity,
                'unit_price': i.stock_item.get_price(),
                'color': i.stock_item.color,
                'measurement': i.stock_item.measurement,
                'thumbnail': {
                    '80x80': thumb.url_80x80,
                }
            })

        thumb = item.product.get_thumb()
        response = {
            'checked_out': cart_info.checked_out,
            'created_on': cart_info.created_on,
            'items': cart_items,
            'last_added': {
                'product': item.product,
                'package_count': item.package_count,
                'quantity': quantity,
                'unit_price': item.get_price(),
                'color': item.color,
                'measurement': item.measurement,
                'thumbnail': {
                    '80x80': thumb.url_80x80,
                }
            }
        }
        return response
예제 #3
0
 def update(self, request):
     try:
         item = StockItem.objects.get(
             color=request.form.cleaned_data['color'], 
             measurement=request.form.cleaned_data['measurement'], 
             product=request.form.cleaned_data['product'])
     except StockItem.DoesNotExist:
         return rc.NOT_FOUND
     
     quantity = request.form.cleaned_data['quantity']
     cart = Cart(request)
     cart.update(item, item.get_price(), quantity)
     cart_info = cart.summary()
     cart_items = []
     for i in cart:
         thumb = i.stock_item.product.get_thumb()
         cart_items.append({
             'product' : i.stock_item.product,
             'package_count' : i.stock_item.package_count,
             'quantity' : i.quantity,
             'unit_price' : i.stock_item.get_price(),
             'color' : i.stock_item.color,
             'measurement': i.stock_item.measurement,
             'thumbnail' : {
                 '80x80' : thumb.url_80x80,
             }
         })
             
     thumb = item.product.get_thumb()        
     response = {
         'checked_out' : cart_info.checked_out,
         'created_on' : cart_info.created_on,
         'items' : cart_items,
         'last_added' : {
             'product' : item.product,
             'package_count' : item.package_count,
             'quantity' : quantity,
             'unit_price' : item.get_price(),
             'color' : item.color,
             'measurement' : item.measurement,
             'thumbnail' : {
                 '80x80' : thumb.url_80x80,
             }
         }
     }
     return response
예제 #4
0
    def read(self, request, pk=None):
        cart = Cart(request)
        cart_info = cart.summary()

        if pk:
            try:
                cart_item = CartItem.objects.get(pk=pk, cart=cart_info.pk)
            except CartItem.DoesNotExist:
                return rc.NOT_FOUND

            response = {
                'pk': cart_item.pk,
                'item': cart_item.stock_item,
                'quantity': cart_item.quantity,
            }

        else:
            cart_items = []
            for i in cart:
                item_gallery = ProductGallery.objects.get(
                    product=i.stock_item.product, color=i.stock_item.color)
                cart_items.append({
                    'product':
                    i.stock_item.product,
                    'package_count':
                    i.stock_item.package_count,
                    'color':
                    i.stock_item.color,
                    'measurement':
                    i.stock_item.measurement,
                    'thumbnails':
                    build_thumbnail_list(item_gallery),
                })

            response = {
                'checked_out': cart_info.checked_out,
                'created_on': cart_info.created_on,
                'items': cart_items,
            }

        return response