Removed per-product currency in favor of a global site currency managed via SiteConfiguration. Updated models, views, templates, and Stripe integration to use the global currency. Added migration, management command for migration, and API endpoint for currency info. Improved permissions and filtering for orders, reviews, and carts. Expanded supported currencies in configuration.
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
from rest_framework.views import APIView
|
|
from rest_framework.response import Response
|
|
from rest_framework import status
|
|
from drf_spectacular.utils import extend_schema
|
|
from configuration.models import SiteConfiguration
|
|
|
|
class CurrencyInfoView(APIView):
|
|
"""
|
|
Get current site currency and display information.
|
|
"""
|
|
|
|
@extend_schema(
|
|
summary="Get site currency information",
|
|
description="Returns the current site currency and available options",
|
|
tags=["configuration"]
|
|
)
|
|
def get(self, request):
|
|
config = SiteConfiguration.get_solo()
|
|
|
|
currency_symbols = {
|
|
'EUR': '€',
|
|
'CZK': 'Kč',
|
|
'USD': '$',
|
|
'GBP': '£',
|
|
'PLN': 'zł',
|
|
'HUF': 'Ft',
|
|
'SEK': 'kr',
|
|
'DKK': 'kr',
|
|
'NOK': 'kr',
|
|
'CHF': 'Fr'
|
|
}
|
|
|
|
return Response({
|
|
'current_currency': config.currency,
|
|
'currency_symbol': currency_symbols.get(config.currency, config.currency),
|
|
'currency_name': dict(SiteConfiguration.CURRENCY.choices)[config.currency],
|
|
'available_currencies': [
|
|
{
|
|
'code': choice[0],
|
|
'name': choice[1],
|
|
'symbol': currency_symbols.get(choice[0], choice[0])
|
|
}
|
|
for choice in SiteConfiguration.CURRENCY.choices
|
|
]
|
|
}) |