DEV Community

Jeremy Libeskind
Jeremy Libeskind

Posted on

Modernizing Online Cosmetic Sales

Modernizing Online Cosmetic Sales: Building a Dynamic Pricing & Cart Calculator in Python

Cosmetic e-commerce (vente en ligne de produits cosmétiques) is one of the fastest-growing sectors in online retail. From clean skincare serums and organic makeup to luxury fragrances and haircare, independent brands and dropshippers are selling directly to customers worldwide.

Yet many small sellers still rely on spreadsheets or manual calculations to figure out:

  • Product bundles and quantity discounts
  • Promo codes and seasonal sales
  • Shipping fees (flat rate or weight-based)
  • VAT / sales tax compliance
  • Final profit margins

That’s where a simple Python script can save hours every day and eliminate costly pricing mistakes.

In this article, I’ll show you a practical, ready-to-use Cosmetic Cart & Pricing Calculator that any beauty entrepreneur can run locally or turn into a web app in minutes.

Why Automation Matters for Online Cosmetic Sellers

  • Speed: Generate accurate quotes or order totals in seconds
  • Consistency: No more forgotten discounts or wrong shipping fees
  • Profitability: Automatically calculate margins and break-even points
  • Professionalism: Clean, branded order summaries you can email instantly
  • Scalability: Handle flash sales, Black Friday, or influencer bundles without stress

Let’s Build the Tool: Cosmetic Order Calculator

Here’s a clean, extensible Python script. It supports multiple products, promo codes, dynamic shipping, and tax calculation — all while keeping the code simple enough for beginners.


python
def calculate_subtotal(cart: dict) -> float:
    """cart = {'product_name': (price, quantity)}"""
    return sum(price * qty for price, qty in cart.values())

def apply_promo(subtotal: float, promo_code: str = None) -> float:
    """Realistic promo rules for beauty brands"""
    promos = {
        "BEAUTY20": 0.20,   # 20% off
        "FREESHIP": 0.0,     # Free shipping (handled separately)
        "BUNDLE15": 0.15,    # Bundle discount
        "WELCOME10": 0.10,   # First-order discount
    }
    discount_rate = promos.get(promo_code.upper() if promo_code else "", 0.0)
    return subtotal * (1 - discount_rate)

def get_shipping(subtotal: float, country: str = "France") -> float:
    """Simple shipping logic — customize for your store"""
    if country.lower() in ["france", "fr"]:
        return 0.0 if subtotal >= 50 else 6.90
    elif country.lower() in ["eu", "europe"]:
        return 0.0 if subtotal >= 80 else 12.50
    else:
        return 0.0 if subtotal >= 100 else 18.00  # International

def calculate_tax(subtotal_after_discount: float, country: str = "France") -> float:
    """VAT example — France is 20% for cosmetics"""
    vat_rate = 0.20 if country.lower() in ["france", "fr"] else 0.0  # simplify for demo
    return subtotal_after_discount * vat_rate

def generate_cosmetic_order(
    cart: dict,
    promo_code: str = None,
    country: str = "France",
    include_tax: bool = True
) -> dict:

    subtotal = calculate_subtotal(cart)
    subtotal_after_promo = apply_promo(subtotal, promo_code)
    shipping = get_shipping(subtotal_after_promo, country)
    tax = calculate_tax(subtotal_after_promo, country) if include_tax else 0.0

    total = subtotal_after_promo + shipping + tax

    return {
        "subtotal": round(subtotal, 2),
        "discount_applied": round(subtotal - subtotal_after_promo, 2),
        "shipping": round(shipping, 2),
        "tax": round(tax, 2),
        "total": round(total, 2),
        "promo_code": promo_code.upper() if promo_code else "NONE",
        "items": len(cart)
    }

# Example usage — real cosmetic products
if __name__ == "__main__":
    my_cart = {
        "Vitamin C Serum 30ml": (32.90, 2),
        "Hydrating Moisturizer": (24.50, 1),
        "Lip Glow Oil Set": (18.90, 3),
        "Organic Face Mask": (12.00, 1),
    }

    order = generate_cosmetic_order(
        cart=my_cart,
        promo_code="BEAUTY20",
        country="France"
    )

    print("═" * 50)
    print("     COSMETIC ORDER SUMMARY")
    print("═" * 50)
    print(f"Items in cart     : {order['items']}")
    print(f"Subtotal          : €{order['subtotal']}")
    print(f"Promo ({order['promo_code']})   : -€{order['discount_applied']}")
    print(f"Shipping          : €{order['shipping']}")
    print(f"VAT (20%)         : €{order['tax']}")
    print("─" * 50)
    print(f"**TOTAL TO PAY    : €{order['total']}**")
    print("═" * 50)
    print("Thank you for shopping at [Your Beauty Brand] 💄")
Enter fullscreen mode Exit fullscreen mode

Top comments (0)