Exemple #1
0
def foxyfeed(request):
    if request.POST and 'FoxyData' in request.POST:
        try:
            data = FoxyData.from_crypted_str(urllib.unquote_plus(request.POST['FoxyData']), settings.FOXYCART_DATAFEED_KEY)	# IMPORTANT: unquote_plus is necessary for the non-ASCII binary that FoxyCart sends.
            for transaction in data.transactions:
                order = Order(order_xml=data.markup)
                order.order_id = transaction.id
                for f in transaction_fields:
                    setattr(order, f, getattr(transaction, f))

                items = ""
                for item in transaction.items:
                    product_code = item["product_code"]
                    product_variation = item["detail"]["shirt"]
                    quantity = item["product_quantity"]

                    product = Product.objects.get(slug=product_code)
                    variation = product.productvariation_set.get(description=product_variation)

                    quantity_int = int(quantity)

                    product.total_sold += quantity_int
                    product.save()

                    variation.num_ordered += quantity_int

                    if product.has_inventory:
                        variation.inventory = variation.inventory-quantity_int

                    variation.save()

                    items += "Product Name:" + item["product_name"] + "\n"
                    items += "Product Code:" + product_code + "\n"
                    items += "Product Quantity:" + quantity + "\n"
                    items += "Product Variation:" + product_variation + "\n"
                    items += "\n"

                order.items_ordered = items
                order.save()

            return HttpResponse('foxy')

        except Exception, e:
            # Something went wrong, handle the error...
            raise
Exemple #2
0
def orderlist(request, product_code):
    if request.user.is_staff:
        items = "PONumber,OrderDate,ConsigneeFullName,ConsigneeAddress1,ConsigneeAddress2,ConsigneeCity,ConsigneeState,ConsigneeZip,ConsigneeCountry,ConsigneePhone,ConsigneeEmail,ItemSKU,ItemQuantity,Carrier,ShippingLevel,Comments,ConfirmationNumber</br>"
        orders = Order.objects.filter(items_ordered__contains=product_code)
        for o in orders:
            try:
                data = FoxyData.from_str(urllib.unquote_plus(o.order_xml))
                for transaction in data.transactions:
                    for item in transaction.items:
                        product_code = item["product_code"]
                        product_variation = item["detail"]["shirt"]
                        quantity = item["product_quantity"]
                    
                        order = o.order_id+","+str(o.transaction_date)+","

                        if o.shipping_first_name and o.shipping_first_name != "" and o.shipping_last_name and o.shipping_last_name != "":
                            consignee_fullname = o.shipping_first_name +" "+ o.shipping_last_name
                        else:
                            consignee_fullname = o.customer_first_name +" "+ o.customer_last_name

                        order += '"'+consignee_fullname + '",'

                        if o.shipping_address1 and o.shipping_address1 != "":
                            consignee_address1 = o.shipping_address1
                        else:
                            consignee_address1 = o.customer_address1

                        order += '"'+consignee_address1 + '",'

                        if o.shipping_address2 and o.shipping_address2 != "":
                            consignee_address2 = o.shipping_address2
                        else:
                            consignee_address2 = o.customer_address2

                        order += '"'+consignee_address2 + '",'
                        
                        if o.shipping_city and o.shipping_city != "":
                            consignee_city = o.shipping_city
                        else:
                            consignee_city = o.customer_city

                        order += '"'+consignee_city + '",'    

                        if o.shipping_state and o.shipping_state != "":
                            consignee_state = o.shipping_state
                        else:
                            consignee_state = o.customer_state

                        order += '"'+consignee_state + '",'
                        
                        if o.shipping_postal_code and o.shipping_postal_code != "":
                            consignee_postal_code = o.shipping_postal_code
                        else:
                            consignee_postal_code = o.customer_postal_code

                        order += '"'+consignee_postal_code + '",'

                        if o.shipping_country and o.shipping_country != "":
                            consignee_country = o.shipping_country
                        else:
                            consignee_country = o.customer_country

                        order += '"' + consignee_country + '",'

                        if o.shipping_phone and o.shipping_phone != "":
                            consignee_phone = o.shipping_phone
                        else:
                            consignee_phone = o.customer_phone

                        order += '"'+consignee_phone + '",'+o.customer_email+","+product_code+"-"+product_variation+","+quantity+",USPS"+",,,<br/>"
                        items += order

            except Exception, e:
                # Something went wrong, handle the error...
                raise

        return HttpResponse(items)