lfs-bulk-prices 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lfs_bulk_prices/__init__.py +3 -0
- lfs_bulk_prices/admin.py +4 -0
- lfs_bulk_prices/apps.py +33 -0
- lfs_bulk_prices/calculator.py +25 -0
- lfs_bulk_prices/locale/de/LC_MESSAGES/django.mo +0 -0
- lfs_bulk_prices/locale/de/LC_MESSAGES/django.po +61 -0
- lfs_bulk_prices/migrations/0001_initial.py +24 -0
- lfs_bulk_prices/migrations/0002_auto_20151116_0957.py +38 -0
- lfs_bulk_prices/migrations/0003_auto_20151116_0958.py +23 -0
- lfs_bulk_prices/migrations/0004_auto_20151116_1008.py +23 -0
- lfs_bulk_prices/migrations/0005_auto_20151117_1947.py +22 -0
- lfs_bulk_prices/migrations/0006_auto_20151124_1100.py +27 -0
- lfs_bulk_prices/migrations/0007_auto_20151125_0801.py +18 -0
- lfs_bulk_prices/migrations/__init__.py +0 -0
- lfs_bulk_prices/models.py +19 -0
- lfs_bulk_prices/static/lfs_bulk_prices/frontend.js +19 -0
- lfs_bulk_prices/static/lfs_bulk_prices/manage.js +209 -0
- lfs_bulk_prices/templates/lfs_bulk_prices/manage/tab.html +152 -0
- lfs_bulk_prices/templatetags/__init__.py +0 -0
- lfs_bulk_prices/templatetags/lfs_bulk_prices_tags.py +219 -0
- lfs_bulk_prices/tests/__init__.py +0 -0
- lfs_bulk_prices/tests/settings.py +50 -0
- lfs_bulk_prices/tests/test_manage_tab.py +104 -0
- lfs_bulk_prices/tests/urls.py +9 -0
- lfs_bulk_prices/urls.py +10 -0
- lfs_bulk_prices/views.py +87 -0
- lfs_bulk_prices-2.0.0.dist-info/METADATA +62 -0
- lfs_bulk_prices-2.0.0.dist-info/RECORD +31 -0
- lfs_bulk_prices-2.0.0.dist-info/WHEEL +5 -0
- lfs_bulk_prices-2.0.0.dist-info/licenses/LICENSE.txt +27 -0
- lfs_bulk_prices-2.0.0.dist-info/top_level.txt +1 -0
lfs_bulk_prices/admin.py
ADDED
lfs_bulk_prices/apps.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""App configuration: registers the bulk prices tab on the product management page."""
|
|
2
|
+
|
|
3
|
+
from django.apps import AppConfig
|
|
4
|
+
from django.http import HttpRequest
|
|
5
|
+
from django.utils.translation import gettext_lazy as _
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def uses_bulk_prices(request: HttpRequest, product) -> bool:
|
|
9
|
+
"""Return whether ``product`` is priced with the bulk prices calculator (its own or its parent's)."""
|
|
10
|
+
from .calculator import BulkPricesCalculator
|
|
11
|
+
|
|
12
|
+
return isinstance(product.get_price_calculator(request), BulkPricesCalculator)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class LfsBulkPricesConfig(AppConfig):
|
|
16
|
+
"""Adds the "Bulk prices" tab to products that use the bulk prices calculator."""
|
|
17
|
+
|
|
18
|
+
name = "lfs_bulk_prices"
|
|
19
|
+
verbose_name = _("Bulk prices")
|
|
20
|
+
|
|
21
|
+
def ready(self) -> None:
|
|
22
|
+
"""Register the product tab."""
|
|
23
|
+
from lfs.manage.products.tabs import ProductTab, register_product_tab
|
|
24
|
+
|
|
25
|
+
register_product_tab(
|
|
26
|
+
ProductTab(
|
|
27
|
+
key="bulk_prices",
|
|
28
|
+
label=_("Bulk prices"),
|
|
29
|
+
url_name="lfs_manage_product_bulk_prices",
|
|
30
|
+
template="lfs_bulk_prices/manage/tab.html",
|
|
31
|
+
show=uses_bulk_prices,
|
|
32
|
+
)
|
|
33
|
+
)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from lfs.gross_price.calculator import GrossPriceCalculator
|
|
2
|
+
from .models import BulkPrice
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class BulkPricesCalculator(GrossPriceCalculator):
|
|
6
|
+
""" """
|
|
7
|
+
|
|
8
|
+
def get_price(self, with_properties=True, amount=1):
|
|
9
|
+
""" """
|
|
10
|
+
# If a variant has no price calculator the price calculator from the parent is used.
|
|
11
|
+
# See also product.get_price_calculator().
|
|
12
|
+
#
|
|
13
|
+
# Once we are here, we have to check which bulk prices are applicable.
|
|
14
|
+
# That means, if a variant has no bulk prices at all, the bulk prices from the parent are used.
|
|
15
|
+
|
|
16
|
+
# First, determine the relevant product (use parent for variants if necessary)
|
|
17
|
+
target_product = self.product
|
|
18
|
+
if self.product.is_variant() and not BulkPrice.objects.filter(product=self.product).exists():
|
|
19
|
+
target_product = self.product.get_parent()
|
|
20
|
+
|
|
21
|
+
for bulk_price in BulkPrice.objects.filter(product=target_product).order_by("-amount"):
|
|
22
|
+
if amount >= bulk_price.amount:
|
|
23
|
+
return bulk_price.price_absolute
|
|
24
|
+
|
|
25
|
+
return 0.0
|
|
Binary file
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# SOME DESCRIPTIVE TITLE.
|
|
2
|
+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
|
3
|
+
# This file is distributed under the same license as the PACKAGE package.
|
|
4
|
+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
|
5
|
+
#
|
|
6
|
+
msgid ""
|
|
7
|
+
msgstr ""
|
|
8
|
+
"Project-Id-Version: 1.0\n"
|
|
9
|
+
"Report-Msgid-Bugs-To: \n"
|
|
10
|
+
"POT-Creation-Date: 2015-11-24 13:01+0100\n"
|
|
11
|
+
"PO-Revision-Date: 2015-11-24 12:59+0100\n"
|
|
12
|
+
"Last-Translator: Kai Diefenbach <kai.diefenbach@iqpp.de>\n"
|
|
13
|
+
"Language-Team: DE <kai.diefenbach@iqpp.de>\n"
|
|
14
|
+
"Language: De\n"
|
|
15
|
+
"MIME-Version: 1.0\n"
|
|
16
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
|
17
|
+
"Content-Transfer-Encoding: 8bit\n"
|
|
18
|
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
|
19
|
+
|
|
20
|
+
#: models.py:16
|
|
21
|
+
msgid "Product"
|
|
22
|
+
msgstr "Produkt"
|
|
23
|
+
|
|
24
|
+
#: models.py:17 templates/lfs_bulk_prices/lfs_bulk_prices.html:13
|
|
25
|
+
msgid "Amount"
|
|
26
|
+
msgstr "Anzahl"
|
|
27
|
+
|
|
28
|
+
#: models.py:18
|
|
29
|
+
msgid "Price absolute"
|
|
30
|
+
msgstr "Absoluter Preis"
|
|
31
|
+
|
|
32
|
+
#: models.py:19
|
|
33
|
+
msgid "Price percentual"
|
|
34
|
+
msgstr "Prozentualer Preis"
|
|
35
|
+
|
|
36
|
+
#: templates/lfs_bulk_prices/lfs_bulk_prices.html:4
|
|
37
|
+
msgid "Bulk prices"
|
|
38
|
+
msgstr "Staffelpreise"
|
|
39
|
+
|
|
40
|
+
msgid "Bulk prices calculator"
|
|
41
|
+
msgstr "Staffelpreise"
|
|
42
|
+
|
|
43
|
+
#: templates/lfs_bulk_prices/lfs_bulk_prices.html:16
|
|
44
|
+
msgid "Absolute"
|
|
45
|
+
msgstr "Absolut"
|
|
46
|
+
|
|
47
|
+
#: templates/lfs_bulk_prices/lfs_bulk_prices.html:19
|
|
48
|
+
msgid "Percentual"
|
|
49
|
+
msgstr "Prozentual"
|
|
50
|
+
|
|
51
|
+
#: templates/lfs_bulk_prices/lfs_bulk_prices.html:68
|
|
52
|
+
msgid "Save"
|
|
53
|
+
msgstr "Speichern"
|
|
54
|
+
|
|
55
|
+
#: templates/lfs_bulk_prices/lfs_bulk_prices.html:69
|
|
56
|
+
msgid "Reset"
|
|
57
|
+
msgstr "Zurücksetzen"
|
|
58
|
+
|
|
59
|
+
#: views.py:44
|
|
60
|
+
msgid "Duplicated prices have been removed."
|
|
61
|
+
msgstr "Doppelte Preise wurden entfernt."
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import unicode_literals
|
|
3
|
+
|
|
4
|
+
from django.db import models, migrations
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
operations = [
|
|
9
|
+
migrations.CreateModel(
|
|
10
|
+
name="BulkPrice",
|
|
11
|
+
fields=[
|
|
12
|
+
("id", models.AutoField(verbose_name="ID", serialize=False, auto_created=True, primary_key=True)),
|
|
13
|
+
("price", models.DecimalField(verbose_name="Price", max_digits=10, decimal_places=2)),
|
|
14
|
+
("product", models.ForeignKey(to="catalog.Product", on_delete=models.CASCADE)),
|
|
15
|
+
],
|
|
16
|
+
options={
|
|
17
|
+
"ordering": ("price",),
|
|
18
|
+
},
|
|
19
|
+
),
|
|
20
|
+
migrations.AlterUniqueTogether(
|
|
21
|
+
name="bulkprice",
|
|
22
|
+
unique_together=set([("product", "price")]),
|
|
23
|
+
),
|
|
24
|
+
]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import unicode_literals
|
|
3
|
+
|
|
4
|
+
from django.db import migrations, models
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
dependencies = [
|
|
9
|
+
("lfs_bulk_prices", "0001_initial"),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.AlterModelOptions(
|
|
14
|
+
name="bulkprice",
|
|
15
|
+
options={"ordering": ("amount",)},
|
|
16
|
+
),
|
|
17
|
+
migrations.RenameField(
|
|
18
|
+
model_name="bulkprice",
|
|
19
|
+
old_name="price",
|
|
20
|
+
new_name="price_total",
|
|
21
|
+
),
|
|
22
|
+
migrations.AddField(
|
|
23
|
+
model_name="bulkprice",
|
|
24
|
+
name="amount",
|
|
25
|
+
field=models.SmallIntegerField(default=1),
|
|
26
|
+
preserve_default=False,
|
|
27
|
+
),
|
|
28
|
+
migrations.AddField(
|
|
29
|
+
model_name="bulkprice",
|
|
30
|
+
name="price_percentual",
|
|
31
|
+
field=models.DecimalField(default=0, verbose_name="Price", max_digits=10, decimal_places=2),
|
|
32
|
+
preserve_default=False,
|
|
33
|
+
),
|
|
34
|
+
migrations.AlterUniqueTogether(
|
|
35
|
+
name="bulkprice",
|
|
36
|
+
unique_together=set([("product", "price_total")]),
|
|
37
|
+
),
|
|
38
|
+
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import unicode_literals
|
|
3
|
+
|
|
4
|
+
from django.db import migrations, models
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
dependencies = [
|
|
9
|
+
("lfs_bulk_prices", "0002_auto_20151116_0957"),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.AlterField(
|
|
14
|
+
model_name="bulkprice",
|
|
15
|
+
name="price_percentual",
|
|
16
|
+
field=models.DecimalField(default=0.0, verbose_name="Price", max_digits=10, decimal_places=2),
|
|
17
|
+
),
|
|
18
|
+
migrations.AlterField(
|
|
19
|
+
model_name="bulkprice",
|
|
20
|
+
name="price_total",
|
|
21
|
+
field=models.DecimalField(default=0.0, verbose_name="Price", max_digits=10, decimal_places=2),
|
|
22
|
+
),
|
|
23
|
+
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import unicode_literals
|
|
3
|
+
|
|
4
|
+
from django.db import migrations, models
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
dependencies = [
|
|
9
|
+
("lfs_bulk_prices", "0003_auto_20151116_0958"),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.AlterField(
|
|
14
|
+
model_name="bulkprice",
|
|
15
|
+
name="price_percentual",
|
|
16
|
+
field=models.FloatField(default=0.0, verbose_name="Price percentual"),
|
|
17
|
+
),
|
|
18
|
+
migrations.AlterField(
|
|
19
|
+
model_name="bulkprice",
|
|
20
|
+
name="price_total",
|
|
21
|
+
field=models.FloatField(default=0.0, verbose_name="Price absolute"),
|
|
22
|
+
),
|
|
23
|
+
]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import unicode_literals
|
|
3
|
+
|
|
4
|
+
from django.db import migrations, models
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
dependencies = [
|
|
9
|
+
("lfs_bulk_prices", "0004_auto_20151116_1008"),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.RenameField(
|
|
14
|
+
model_name="bulkprice",
|
|
15
|
+
old_name="price_total",
|
|
16
|
+
new_name="price_absolute",
|
|
17
|
+
),
|
|
18
|
+
migrations.AlterUniqueTogether(
|
|
19
|
+
name="bulkprice",
|
|
20
|
+
unique_together=set([("product", "price_absolute")]),
|
|
21
|
+
),
|
|
22
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import unicode_literals
|
|
3
|
+
|
|
4
|
+
from django.db import migrations, models
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
dependencies = [
|
|
9
|
+
("lfs_bulk_prices", "0005_auto_20151117_1947"),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.AlterField(
|
|
14
|
+
model_name="bulkprice",
|
|
15
|
+
name="amount",
|
|
16
|
+
field=models.SmallIntegerField(verbose_name="Amount"),
|
|
17
|
+
),
|
|
18
|
+
migrations.AlterField(
|
|
19
|
+
model_name="bulkprice",
|
|
20
|
+
name="product",
|
|
21
|
+
field=models.ForeignKey(verbose_name="Product", to="catalog.Product", on_delete=models.CASCADE),
|
|
22
|
+
),
|
|
23
|
+
migrations.AlterUniqueTogether(
|
|
24
|
+
name="bulkprice",
|
|
25
|
+
unique_together=set([("product", "price_absolute"), ("product", "amount")]),
|
|
26
|
+
),
|
|
27
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import unicode_literals
|
|
3
|
+
|
|
4
|
+
from django.db import migrations, models
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
dependencies = [
|
|
9
|
+
("lfs_bulk_prices", "0006_auto_20151124_1100"),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
operations = [
|
|
13
|
+
migrations.AlterField(
|
|
14
|
+
model_name="bulkprice",
|
|
15
|
+
name="amount",
|
|
16
|
+
field=models.FloatField(verbose_name="Amount"),
|
|
17
|
+
),
|
|
18
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from django.db import models
|
|
2
|
+
from django.utils.translation import gettext_lazy as _
|
|
3
|
+
from lfs.catalog.models import Product
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BulkPrice(models.Model):
|
|
7
|
+
""" """
|
|
8
|
+
|
|
9
|
+
class Meta:
|
|
10
|
+
ordering = ("amount",)
|
|
11
|
+
unique_together = (
|
|
12
|
+
("product", "price_absolute"),
|
|
13
|
+
("product", "amount"),
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
product = models.ForeignKey(Product, verbose_name=_("Product"), on_delete=models.CASCADE)
|
|
17
|
+
amount = models.FloatField(_("Amount"))
|
|
18
|
+
price_absolute = models.FloatField(_("Price absolute"), default=0.0)
|
|
19
|
+
price_percentual = models.FloatField(_("Price percentual"), default=0.0)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
2
|
+
document.addEventListener('keyup', function(event) {
|
|
3
|
+
if (event.target.matches('.product input[name=quantity]')) {
|
|
4
|
+
var url = event.target.getAttribute('bulk_prices_update_url');
|
|
5
|
+
var amount = event.target.value;
|
|
6
|
+
|
|
7
|
+
fetch(url + '?amount=' + encodeURIComponent(amount))
|
|
8
|
+
.then(response => response.json())
|
|
9
|
+
.then(data => {
|
|
10
|
+
document.querySelectorAll('.standard-price-value').forEach(element => {
|
|
11
|
+
element.innerHTML = data['standard_price'];
|
|
12
|
+
});
|
|
13
|
+
document.querySelectorAll('.base-price .money').forEach(element => {
|
|
14
|
+
element.innerHTML = data['base_price'];
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Global namespace set by template
|
|
4
|
+
window.BP = window.BP || {};
|
|
5
|
+
|
|
6
|
+
function qs(selector, root) {
|
|
7
|
+
return (root || document).querySelector(selector);
|
|
8
|
+
}
|
|
9
|
+
function qsa(selector, root) {
|
|
10
|
+
return Array.prototype.slice.call((root || document).querySelectorAll(selector));
|
|
11
|
+
}
|
|
12
|
+
function closest(el, selector) {
|
|
13
|
+
return el && (el.closest ? el.closest(selector) : null);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function decimalCommaToDot(s) {
|
|
17
|
+
return String(s || "").replace(",", ".");
|
|
18
|
+
}
|
|
19
|
+
function decimalDotToComma(n) {
|
|
20
|
+
return String(n).replace(".", ",");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function newRowId() {
|
|
24
|
+
return String(new Date().getTime());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function updateTierNumbers() {
|
|
28
|
+
var cards = qsa(".bulk-price-card");
|
|
29
|
+
cards.forEach(function (card, index) {
|
|
30
|
+
// Skip the first card (base price)
|
|
31
|
+
if (index === 0) return;
|
|
32
|
+
|
|
33
|
+
var header = qs(".card-header h6", card);
|
|
34
|
+
if (header) {
|
|
35
|
+
var icon = qs("i", header);
|
|
36
|
+
if (icon) {
|
|
37
|
+
header.innerHTML = '<i class="bi bi-tag-fill me-2"></i>Price Tier ' + (index + 1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function updateAddButtons() {
|
|
44
|
+
var cards = qsa(".bulk-price-card");
|
|
45
|
+
var headers = qsa(".bulk-price-card .card-header");
|
|
46
|
+
|
|
47
|
+
// Remove all add buttons first
|
|
48
|
+
qsa(".add-bulk-price-button").forEach(function (btn) {
|
|
49
|
+
if (!btn.closest("#bulk-prices-content > .d-flex > .btn")) {
|
|
50
|
+
btn.remove();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Add add button to the last card only
|
|
55
|
+
if (cards.length > 0) {
|
|
56
|
+
var lastCard = cards[cards.length - 1];
|
|
57
|
+
var lastHeader = qs(".card-header", lastCard);
|
|
58
|
+
var buttonContainer = qs(".d-flex", lastHeader);
|
|
59
|
+
|
|
60
|
+
if (buttonContainer && !qs(".add-bulk-price-button", buttonContainer)) {
|
|
61
|
+
var addBtn = document.createElement("button");
|
|
62
|
+
addBtn.type = "button";
|
|
63
|
+
addBtn.className = "btn btn-sm btn-outline-primary add-bulk-price-button";
|
|
64
|
+
addBtn.title = "Add new price tier";
|
|
65
|
+
addBtn.innerHTML = '<i class="bi bi-plus-circle"></i>';
|
|
66
|
+
buttonContainer.insertBefore(addBtn, buttonContainer.firstChild);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function bulk_price_card() {
|
|
72
|
+
var id = newRowId();
|
|
73
|
+
var vals = [];
|
|
74
|
+
qsa(".bulk-price-card input.amount").forEach(function (item) {
|
|
75
|
+
vals.push(decimalCommaToDot(item.value));
|
|
76
|
+
});
|
|
77
|
+
var max = 1;
|
|
78
|
+
if (vals.length) {
|
|
79
|
+
try {
|
|
80
|
+
max = Math.max.apply(null, vals.map(parseFloat)) + 1;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
max = 1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var cardCount = qsa(".bulk-price-card").length;
|
|
87
|
+
var tierNumber = cardCount + 1;
|
|
88
|
+
|
|
89
|
+
var card = '' +
|
|
90
|
+
'<div class="bulk-price-card card mb-3">' +
|
|
91
|
+
' <div class="card-header d-flex justify-content-between align-items-center">' +
|
|
92
|
+
' <h6 class="mb-0">' +
|
|
93
|
+
' <i class="bi bi-tag-fill me-2"></i>Price Tier ' + tierNumber +
|
|
94
|
+
' </h6>' +
|
|
95
|
+
' <div class="d-flex gap-2">' +
|
|
96
|
+
' <button type="button" class="btn btn-sm btn-outline-danger delete-bulk-price-button" title="Remove this price tier">' +
|
|
97
|
+
' <i class="bi bi-trash"></i>' +
|
|
98
|
+
' </button>' +
|
|
99
|
+
' </div>' +
|
|
100
|
+
' </div>' +
|
|
101
|
+
' <div class="card-body">' +
|
|
102
|
+
' <input type="hidden" name="price_id" value="' + id + '" />' +
|
|
103
|
+
' <div class="row g-3">' +
|
|
104
|
+
' <div class="col-md-4">' +
|
|
105
|
+
' <label class="form-label fw-semibold">Minimum Quantity</label>' +
|
|
106
|
+
' <div class="input-group">' +
|
|
107
|
+
' <input type="text" class="form-control number amount" name="amount-' + id + '" value="' + decimalDotToComma(max.toFixed ? max.toFixed(1) : max) + '" />' +
|
|
108
|
+
' <span class="input-group-text">' + (BP.price_unit || "") + '</span>' +
|
|
109
|
+
' </div>' +
|
|
110
|
+
' </div>' +
|
|
111
|
+
' <div class="col-md-4">' +
|
|
112
|
+
' <label class="form-label fw-semibold">Price per Unit</label>' +
|
|
113
|
+
' <div class="input-group">' +
|
|
114
|
+
' <input type="text" class="form-control price-absolute price-absolute-' + id + ' number" name="price_absolute-' + id + '" value="0,0" />' +
|
|
115
|
+
' <span class="input-group-text">' + (BP.currency || "") + '</span>' +
|
|
116
|
+
' </div>' +
|
|
117
|
+
' </div>' +
|
|
118
|
+
' <div class="col-md-4">' +
|
|
119
|
+
' <label class="form-label fw-semibold">Discount</label>' +
|
|
120
|
+
' <div class="input-group">' +
|
|
121
|
+
' <input type="text" class="form-control price-percentual price-percentual-' + id + ' number" name="price_percentual-' + id + '" value="0,0" />' +
|
|
122
|
+
' <span class="input-group-text">%</span>' +
|
|
123
|
+
' </div>' +
|
|
124
|
+
' </div>' +
|
|
125
|
+
' </div>' +
|
|
126
|
+
' </div>' +
|
|
127
|
+
'</div>';
|
|
128
|
+
return card;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function calculate_absolute_prices(basePrice) {
|
|
132
|
+
qsa(".price-absolute").forEach(function (item) {
|
|
133
|
+
if (!item.classList.contains("first")) {
|
|
134
|
+
var id = (item.getAttribute("name") || "").split("-")[1];
|
|
135
|
+
var percentEl = qs(".price-percentual-" + id);
|
|
136
|
+
if (!percentEl) return;
|
|
137
|
+
var percent = parseFloat(decimalCommaToDot(percentEl.value)) || 0;
|
|
138
|
+
var price = ((basePrice / 100) * percent).toFixed(2);
|
|
139
|
+
item.value = decimalDotToComma(price);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function calculate_percentual_price(input) {
|
|
145
|
+
var absolute = parseFloat(decimalCommaToDot(input.value)) || 0;
|
|
146
|
+
var baseEl = qs(".price-absolute.first");
|
|
147
|
+
if (!baseEl) return;
|
|
148
|
+
var base = parseFloat(decimalCommaToDot(baseEl.value)) || 1;
|
|
149
|
+
var id = (input.getAttribute("name") || "").split("-")[1];
|
|
150
|
+
var price = ((absolute / base) * 100).toFixed(2);
|
|
151
|
+
var target = qs(".price-percentual-" + id);
|
|
152
|
+
if (target) target.value = decimalDotToComma(price);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function calculate_absolute_price(input) {
|
|
156
|
+
var percent = parseFloat(decimalCommaToDot(input.value)) || 0;
|
|
157
|
+
var baseEl = qs(".price-absolute.first");
|
|
158
|
+
if (!baseEl) return;
|
|
159
|
+
var base = parseFloat(decimalCommaToDot(baseEl.value)) || 0;
|
|
160
|
+
var id = (input.getAttribute("name") || "").split("-")[1];
|
|
161
|
+
var price = ((base / 100) * percent).toFixed(2);
|
|
162
|
+
var target = qs(".price-absolute-" + id);
|
|
163
|
+
if (target) target.value = decimalDotToComma(price);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
document.addEventListener("click", function (e) {
|
|
167
|
+
var delBtn = closest(e.target, ".delete-bulk-price-button");
|
|
168
|
+
if (delBtn) {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
var card = closest(delBtn, ".bulk-price-card");
|
|
171
|
+
if (card) {
|
|
172
|
+
card.remove();
|
|
173
|
+
updateTierNumbers();
|
|
174
|
+
updateAddButtons();
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
var addBtn = closest(e.target, ".add-bulk-price-button");
|
|
179
|
+
if (addBtn) {
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
var html = bulk_price_card();
|
|
182
|
+
var container = qs("#bulk-prices-container");
|
|
183
|
+
if (container) {
|
|
184
|
+
container.insertAdjacentHTML("beforeend", html);
|
|
185
|
+
updateAddButtons();
|
|
186
|
+
}
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
document.addEventListener("change", function (e) {
|
|
192
|
+
var target = e.target;
|
|
193
|
+
if (target.matches(".price-percentual")) {
|
|
194
|
+
calculate_absolute_price(target);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (target.matches(".price-absolute")) {
|
|
198
|
+
calculate_percentual_price(target);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
document.addEventListener("input", function (e) {
|
|
204
|
+
var target = e.target;
|
|
205
|
+
if (target.matches(".price-absolute.first")) {
|
|
206
|
+
var firstPrice = parseFloat(decimalCommaToDot(target.value)) || 0;
|
|
207
|
+
calculate_absolute_prices(firstPrice);
|
|
208
|
+
}
|
|
209
|
+
});
|