Example #1
0
    def post(self):

        if self.current_user:

            shipping_type = self.get_argument("shipping_type", 1)
            costo_despacho = int(self.get_argument("shipping_price", 0))
            post_office_id = self.get_argument("post_office_id", "")

            user_id = self.current_user["id"]

            cart = Cart()
            cart.user_id = user_id

            lista = cart.GetCartByUserId()

            if len(lista) <= 0:
                self.render("beauty_error.html",
                            message="Carro est&aacute; vac&iacute;o")

            suma = 0

            for l in lista:
                c = Cart()
                c.InitById(l["id"])
                c.shipping_type = shipping_type
                c.Edit()
                suma += l["subtotal"]

            if self.current_user['type_id'] != User().getUserTypeID(
                    UserType.EMPRESA):
                self.render("store/checkout-4.html",
                            data=lista,
                            suma=suma,
                            costo_despacho=costo_despacho,
                            pytz=pytz,
                            post_office_id=post_office_id,
                            shipping_type=shipping_type)
            else:
                self.render("wholesaler/checkout-5.html",
                            data=lista,
                            suma=suma,
                            iva=iva,
                            pytz=pytz)
        else:
            self.redirect("/auth/login")
Example #2
0
    def post(self):

        TBK_TIPO_TRANSACCION = self.get_argument("TBK_TIPO_TRANSACCION", "")
        TBK_MONTO = self.get_argument("TBK_MONTO", "")
        TBK_ID_SESION = self.get_argument("TBK_ID_SESION", "")
        TBK_URL_EXITO = self.get_argument("TBK_URL_EXITO", "")
        TBK_URL_FRACASO = self.get_argument("TBK_URL_FRACASO", "")

        payment_type = self.get_argument("payment_type", 2)
        costo_despacho = int(self.get_argument("shipping_price", 0))
        iva = int(self.get_argument("tax", 0))

        user_id = self.current_user["id"]

        order = Order()

        cart = Cart()
        cart.user_id = user_id

        lista = cart.GetCartByUserId()

        if len(lista) > 0:

            subtotal = 0
            cantidad_items = 0
            cantidad_productos = 0
            id_facturacion = 0
            id_despacho = 0
            total = 0
            info_despacho = ''
            info_facturacion = ''

            for l in lista:
                c = Cart()
                c.InitById(l["id"])
                c.payment_type = payment_type
                c.Edit()
                subtotal += l["subtotal"]
                cantidad_items += l["quantity"]
                cantidad_productos += 1
                id_facturacion = l["billing_id"]
                id_despacho = l["shipping_id"]
                total += l["subtotal"]
                info_despacho = l['shipping_info']
                info_facturacion = l['billing_info']

            order.date = datetime.now(
                pytz.timezone('Chile/Continental')).isoformat()
            order.type = Order.TIPO_WEB
            order.subtotal = subtotal
            order.shipping = costo_despacho
            order.tax = iva
            order.total = total + costo_despacho + iva
            order.items_quantity = cantidad_items
            order.products_quantity = cantidad_productos
            order.user_id = user_id
            order.billing_id = id_facturacion
            order.shipping_id = id_despacho
            order.payment_type = payment_type
            order.voucher = ""
            order.state = Order.ESTADO_PENDIENTE
            order.shipping_info = info_despacho
            order.billing_info = info_facturacion

            response_obj = order.Save()

            if "success" in response_obj:

                for l in lista:

                    detail = OrderDetail()
                    detail.order_id = order.id
                    detail.quantity = l["quantity"]
                    detail.subtotal = l["subtotal"]
                    detail.product_id = l["product_id"]
                    detail.size = l["size"]
                    detail.price = l["price"]
                    detail.Save()

                    # res_obj = detail.Save()
                    # if "error" in res_obj:
                    #     print "{}".format(res_obj["error"])

            # else:

            #     self.write(response_obj["error"])
            #     return

        if os.name != "nt":
            myPath = "{}webpay/dato{}.log" \
                .format(project_path, TBK_ID_SESION)
        else:
            myPath = "C:\Users\YiChun\Documents\giani\webpay\dato{}.log" \
                .format(TBK_ID_SESION)

        f = open(myPath, "w+")
        linea = "{};{}".format(TBK_MONTO, order.id)
        f.write(linea)
        f.close()

        data = {
            "TBK_TIPO_TRANSACCION": TBK_TIPO_TRANSACCION,
            "TBK_MONTO": TBK_MONTO,
            "TBK_ORDEN_COMPRA": order.id,
            "TBK_ID_SESION": TBK_ID_SESION,
            "TBK_URL_EXITO": TBK_URL_EXITO,
            "TBK_URL_FRACASO": TBK_URL_FRACASO,
            "shipping": costo_despacho,
            "subtotal": subtotal
        }

        # self.write(json_util.dumps(data))
        user_id = self.current_user["id"]
        cart = Cart()
        cart.user_id = user_id
        lista = cart.GetCartByUserId()

        self.render("transbank.html", data=data, lista=lista)
Example #3
0
    def post(self):

        if self.current_user:

            costo_despacho = int(self.get_argument("shipping_price", 0))
            user_id = self.current_user["id"]
            nombre = self.get_argument("name", self.current_user["name"])
            apellido = self.get_argument("lastname",
                                         self.current_user["lastname"])
            email = self.get_argument("email", self.current_user["email"])
            direccion = self.get_argument("address", "")
            ciudad = self.get_argument("city_id", "")
            codigo_postal = self.get_argument("zip_code", "")
            informacion_adicional = self.get_argument("additional_info", "")
            telefono = self.get_argument("telephone", "")
            id_contacto = self.get_argument("contact_id", "")
            misma_direccion = self.get_argument("same_address", "")
            comuna = self.get_argument("town", "")
            rut = self.get_argument("rut", "")
            shipping_type = self.get_argument("shipping_type", 1)
            post_office_id = self.get_argument("post_office_id", "")

            cart = Cart()
            cart.user_id = user_id

            lista = cart.GetCartByUserId()

            if len(lista) <= 0:
                self.render("beauty_error.html",
                            message="Carro est&aacute; vac&iacute;o")

            if misma_direccion != "on":

                contact = Contact()

                contact.name = nombre
                contact.lastname = apellido
                contact.telephone = telefono
                contact.email = email
                contact.address = direccion
                contact.city = ciudad
                contact.zip_code = codigo_postal
                contact.user_id = user_id
                contact.additional_info = informacion_adicional
                contact.town = comuna
                contact.rut = rut

                operacion = ""

                if id_contacto != "":
                    contact.id = id_contacto
                    response_obj = contact.Edit()
                    operacion = "editar"
                else:
                    response_obj = contact.Save()
                    operacion = "guardar"

                if "error" in response_obj:
                    self.render("beauty_error.html",
                                message="Error al {} contacto {}".format(
                                    operacion, response_obj["error"]))
                else:
                    suma = 0

                    for l in lista:
                        c = Cart()
                        c.InitById(l["id"])
                        c.billing_id = contact.id
                        c.billing_info = contact.additional_info
                        c.Edit()
                        suma += l["subtotal"]

                    # self.render("store/checkout-2.html",contactos=contactos,data=lista,suma=suma,selected_address=direccion)
                    if self.current_user['type_id'] == User().getUserTypeID(
                            UserType.EMPRESA):
                        self.render("wholesaler/checkout-4.html",
                                    data=lista,
                                    suma=suma,
                                    iva=iva)
                    else:
                        self.render("store/checkout-3.html",
                                    data=lista,
                                    suma=suma,
                                    costo_despacho=costo_despacho,
                                    shipping_type=shipping_type,
                                    post_office_id=post_office_id)
            else:

                contact = Contact()
                cart = Cart()
                cart.user_id = user_id

                lista = cart.GetCartByUserId()

                billing_info = ''
                suma = 0

                try:
                    billing_info = contact.getAdditionalInfo(
                        c.shipping_id)['success']
                except:
                    pass

                for l in lista:
                    c = Cart()
                    c.InitById(l["id"])
                    c.billing_info = billing_info
                    c.billing_id = c.shipping_id
                    c.Edit()
                    suma += l["subtotal"]

                if self.current_user['type_id'] == User().getUserTypeID(
                        UserType.EMPRESA):
                    self.render("wholesaler/checkout-4.html",
                                data=lista,
                                suma=suma,
                                iva=iva)
                else:
                    self.render("store/checkout-3.html",
                                data=lista,
                                suma=suma,
                                costo_despacho=costo_despacho,
                                shipping_type=shipping_type,
                                post_office_id=post_office_id)

        else:

            self.redirect("/auth/login")
Example #4
0
    def get(self):

        if self.current_user:
            user_id = self.current_user["id"]
            nombre = self.get_argument("name", self.current_user["name"])
            apellido = self.get_argument("lastname",
                                         self.current_user["lastname"])
            email = self.get_argument("email", self.current_user["email"])
            direccion = self.get_argument("address", "")
            ciudad = self.get_argument("city_id", "")
            codigo_postal = self.get_argument("zip_code", "")
            informacion_adicional = self.get_argument("additional_info", "")
            telefono = self.get_argument("telephone", "")
            id_contacto = self.get_argument("contact_id", "")
            comuna = self.get_argument("town", "")
            rut = self.get_argument("rut", "")
            shipping_type = self.get_argument("shipping_type", "")
            post_office_id = self.get_argument("post_office_id", "")

            shipping_type_id = 1

            cart = Cart()
            cart.user_id = user_id

            lista = cart.GetCartByUserId()

            if len(lista) <= 0:
                self.render("beauty_error.html",
                            message="Carro est&aacute; vac&iacute;o")

            contact = Contact()

            contact.name = nombre
            contact.lastname = apellido
            contact.telephone = telefono
            contact.email = email
            contact.address = direccion
            if shipping_type == "chilexpress":
                po = PostOffice()
                po.InitById(post_office_id)
                post_office_name = po.name
                contact.address = "Oficina {}".format(post_office_name)
            contact.city = ciudad
            contact.zip_code = codigo_postal
            contact.user_id = user_id
            contact.additional_info = informacion_adicional
            contact.town = comuna
            contact.rut = rut

            operacion = ""

            if id_contacto != "":
                contact.id = id_contacto
                response_obj = contact.Edit()
                operacion = "editar"
            else:
                response_obj = contact.Save()
                operacion = "guardar"

            if "error" in response_obj:
                self.render("beauty_error.html",
                            message="Error al {} contacto {}".format(
                                operacion, response_obj["error"]))
            else:

                items = 0
                suma = 0

                for l in lista:
                    c = Cart()
                    response_obj = c.InitById(l["id"])

                    if "success" in response_obj:
                        c.shipping_id = contact.id
                        c.shipping_info = contact.additional_info
                        c.Edit()
                    else:
                        print response_obj["error"]

                    suma += l["subtotal"]
                    items += l["quantity"]

                contactos = []
                cities = []

                response_obj = contact.ListByUserId(user_id)

                city = City()
                res_city = city.List()

                if "success" in response_obj:
                    contactos = json_util.loads(response_obj["success"])

                if "success" in res_city:
                    cities = res_city["success"]

                c = Cellar()
                res_cellar_id = c.GetWebCellar()

                web_cellar_id = cellar_id

                if "success" in res_cellar_id:
                    web_cellar_id = res_cellar_id["success"]

                res_web_cellar = c.InitById(web_cellar_id)

                if "success" in res_web_cellar:
                    if shipping_type != "chilexpress":
                        cellar_city_id = c.city_id

                        shipping = Shipping()
                        shipping.from_city_id = int(cellar_city_id)
                        shipping.to_city_id = int(ciudad)
                        res = shipping.GetGianiPrice()
                        if "error" in res:
                            self.render(
                                "beauty_error.html",
                                message="Error al calcular costo de despacho, {}"
                                .format(res["error"]))
                    else:
                        shipping_type_id = 2
                        shipping = Shipping()
                        shipping.post_office_id = post_office_id
                        res = shipping.GetPriceByPostOfficeId()

                    if "error" in res:
                        self.render(
                            "beauty_error.html",
                            message=
                            "Error al calcular costo de despacho de Chilexpress, {}"
                            .format(res["error"]))
                    else:
                        if shipping.charge_type == 1:
                            costo_despacho = shipping.price * items
                        else:
                            costo_despacho = shipping.price

                        self.render("store/checkout-2.html",
                                    contactos=contactos,
                                    data=lista,
                                    suma=suma,
                                    selected_address=direccion,
                                    cities=cities,
                                    costo_despacho=costo_despacho,
                                    shipping_type=shipping_type_id,
                                    post_office_id=post_office_id)
        else:

            self.redirect("/auth/login")