Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1368 as a shop owner i can disable multicurrency support and spec #1372

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""add geo_currency_enabled to settings

Revision ID: a4d35e9917f7
Revises: 8c008c1333d5
Create Date: 2024-07-09 04:21:25.517787

"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "a4d35e9917f7"
down_revision = "8c008c1333d5"
branch_labels = None
depends_on = None


def upgrade():
with op.batch_alter_table("setting", schema=None) as batch_op:
batch_op.add_column(
sa.Column(
"geo_currency_enabled", sa.Boolean(), nullable=True, default=False
)
)


def downgrade():
pass
19 changes: 19 additions & 0 deletions subscribie/blueprints/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,25 @@ def show_api_keys():
)


@admin.route("/enable-geo-currency", methods=["GET", "POST"])
@login_required
def enable_geo_currency():
settings = Setting.query.first() # Get current shop settings

if request.method == "POST":
if int(request.form.get("enableGeoCurrency", 0)) == 1:
settings.geo_currency_enabled = 1
else:
settings.geo_currency_enabled = 0
flash("Geo currency updated")
database.session.commit()
return redirect(url_for("admin.enable_geo_currency", settings=settings))

return render_template(
"admin/settings/geo_currency_settings.html", settings=settings
)


@admin.route("/spamcheck/<string:account_name>")
@login_required
def check_spam(account_name) -> int:
Expand Down
4 changes: 4 additions & 0 deletions subscribie/blueprints/admin/templates/admin/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,10 @@ <h3 class="card-title">Templates</h3>
Change Thank You Page/Payment Successful Page URL
</a>

<a class="btn btn-success btn-block"
href="{{ url_for('admin.enable_geo_currency') }}">
Enable/Disable geo currency detection
</a>
</div>

</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{% extends "admin/layout.html" %}
{% block title %} Geo Currency Settings {% endblock %}

{% block body %}

<h2 class="text-center text-dark mb-3">Geo Currency Settings</h2>

<div class="container">
<ul class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Shop</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('admin.dashboard') }}">Manage My Shop</a></li>
<li class="breadcrumb-item active" aria-current="page">Geo Currency Settings</li>
</ul>
</div>

<main>
<div class="section">
<div class="container">

<div class="row row-cols-1 row-cols-md-2">
<div class="col-md-7">
<h2>Geo Currency Settings</h2>
<p>Enable/Disable automatic display of currency based on detected geolocation.</p>

<form action="" method="POST" action="/">
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="radio" name="enableGeoCurrency" value="1" id="yes" {% if settings.geo_currency_enabled is sameas True %}checked {% endif %}>
<label class="form-check-label" for="yes">
Enable
</label>
</div>
<br />
<div class="form-check">
<input class="form-check-input" type="radio" name="enableGeoCurrency" value="0" id="no" {% if settings.geo_currency_enabled is sameas False %}checked {% endif %}>
<label class="form-check-label" for="no">
Disable
</label>
</div>
</div>
<br />
<button type="submit" class="btn btn-primary btn-block mb-3">Save</button>
</form>
</div>

</div>

</div> <!-- end container-->
</div> <!-- end section-->
</main>



{% endblock %}
1 change: 1 addition & 0 deletions subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,7 @@ class Setting(database.Model):
api_key_secret_test = database.Column(database.String(), default=None)
donations_enabled = database.Column(database.Boolean(), default=False)
custom_thank_you_url = database.Column(database.String(), default=None)
geo_currency_enabled = database.Column(database.Boolean(), default=False)


class File(database.Model):
Expand Down
32 changes: 23 additions & 9 deletions subscribie/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,31 @@


def get_geo_currency_code():
"""Return currency code based on current detected (or selected)
country code.
"""If geo currency is enabled,
Return currency code based on current detected (or selected)
country code, otherwise, return the shops default currency code.
"""
country_code = get_geo_country_code()
# Get currency code from COUNTRY_CODE_TO_CURRENCY_CODE mapping
try:
currency_code = COUNTRY_CODE_TO_CURRENCY_CODE[country_code]
except KeyError as e:
log.info(f"Could not map country_code {country_code} to a currency code. {e}")
from subscribie.models import Setting

settings = Setting.query.first()
geo_currency_enabled = settings.geo_currency_enabled
if geo_currency_enabled is True:
country_code = get_geo_country_code()
# Get currency code from COUNTRY_CODE_TO_CURRENCY_CODE mapping
try:
currency_code = COUNTRY_CODE_TO_CURRENCY_CODE[country_code]
except KeyError as e:
log.info(
f"Could not map country_code {country_code} to a currency code. {e}"
)
currency_code = get_shop_default_currency_code()
log.info(f"get_geo_currency_code returned currency_code: {currency_code}")
else:
log.info(
f"geo_currency_enabled is {geo_currency_enabled} so returning shops default currency code" # noqa: E501
)
currency_code = get_shop_default_currency_code()
log.info(f"get_geo_currency_code returned currency_code: {currency_code}")
log.info(f"Default currency code returned: {currency_code}")
return currency_code


Expand Down
Loading