Migrate to global currency system in commerce app
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.
This commit is contained in:
45
backend/commerce/currency_info_view.py
Normal file
45
backend/commerce/currency_info_view.py
Normal file
@@ -0,0 +1,45 @@
|
||||
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
|
||||
]
|
||||
})
|
||||
Reference in New Issue
Block a user