Jump to content
Fórum Script Brasil
  • 0

Como Criar um Script de cupom de desconto


Luciano Gaspar

Question

Olá, boa noite

Gostaria de saber como implementar cupom de desconto, para que o cliente possa colocar o código quando estiver na tela de pagamento e automaticamente seja verificado se o código é verdadeiro ou não. 

Podendo alterar e remover no painel administrativo.

 

obrigado

Edited by Luciano Gaspar
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

# Flask example with SQLite database
from flask import Flask, request, render_template
import sqlite3

app = Flask(__name__)

# Function to check coupon validity and return discount amount
def validate_coupon(coupon_code):
    # Connect to the database
    conn = sqlite3.connect('your_database.db')
    cursor = conn.cursor()

    # Query the database for the coupon code
    cursor.execute("SELECT * FROM coupons WHERE code=?", (coupon_code,))
    coupon = cursor.fetchone()

    # Close the database connection
    conn.close()

    # Validate coupon and return discount amount
    if coupon and coupon[2] >= datetime.now():  # Assuming the third column is the expiration date
        return coupon[1]  # Assuming the second column is the discount amount
    else:
        return None

# Route to handle coupon submission
@app.route('/apply_coupon', methods=['POST'])
def apply_coupon():
    coupon_code = request.form.get('coupon_code')

    # Validate the coupon
    discount_amount = validate_coupon(coupon_code)

    if discount_amount is not None:
        # Apply the discount to the order total
        # Your logic to update the order total goes here

        return render_template('checkout.html', discount_applied=True)
    else:
        return render_template('checkout.html', discount_applied=False)

if __name__ == '__main__':
    app.run(debug=True)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      651.9k
×
×
  • Create New...