mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-13 16:16:59 +02:00
Create, renew, transfer - calculate correct prices in CP
This commit is contained in:
parent
e2a7e9b054
commit
a2d8f53c23
4 changed files with 60 additions and 23 deletions
|
@ -892,11 +892,11 @@ class SystemController extends Controller
|
|||
[ $args ]);
|
||||
|
||||
if ($tld) {
|
||||
$createPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id = ? AND command = ?', [$tld['id'], NULL, 'create']);
|
||||
$renewPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id = ? AND command = ?', [$tld['id'], NULL, 'renew']);
|
||||
$transferPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id = ? AND command = ?', [$tld['id'], NULL, 'transfer']);
|
||||
$tld_restore = $db->selectRow('SELECT * FROM domain_restore_price WHERE tldid = ? AND registrar_id = ? ',
|
||||
[ $tld['id'], NULL ]);
|
||||
$createPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id IS NULL AND command = ?', [$tld['id'], 'create']);
|
||||
$renewPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id IS NULL AND command = ?', [$tld['id'], 'renew']);
|
||||
$transferPrices = $db->selectRow('SELECT * FROM domain_price WHERE tldid = ? AND registrar_id IS NULL AND command = ?', [$tld['id'], 'transfer']);
|
||||
$tld_restore = $db->selectRow('SELECT * FROM domain_restore_price WHERE tldid = ? AND registrar_id IS NULL ',
|
||||
[ $tld['id'] ]);
|
||||
$premium_pricing = $db->selectRow('SELECT * FROM premium_domain_pricing WHERE tld_id = ?',
|
||||
[ $tld['id'] ]);
|
||||
$premium_categories = $db->select('SELECT * FROM premium_domain_categories');
|
||||
|
|
|
@ -267,6 +267,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
const removeNameserverBtn = document.getElementById('removeNameserver');
|
||||
const nameserverFields = document.getElementById('nameserverFields');
|
||||
const authInfoField = document.getElementById('authInfo');
|
||||
const registrarDropdown = document.getElementById('registrarDropdown');
|
||||
|
||||
// Display year value from slider
|
||||
yearSlider.addEventListener('input', function() {
|
||||
|
@ -371,7 +372,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
}
|
||||
}
|
||||
|
||||
function getDomainPrice(domain, years) {
|
||||
function getDomainPrice(domain, years, registrarId) {
|
||||
const tld = extractTLD(domain);
|
||||
if (!tld) {
|
||||
return Promise.reject("Invalid TLD");
|
||||
|
@ -396,12 +397,22 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
(!record.years_of_promotion || record.years_of_promotion >= years)
|
||||
);
|
||||
|
||||
// Find the regular price for the TLD
|
||||
const tldData = pricingData.records.find(record =>
|
||||
// Find the regular price for the TLD with registrar ID
|
||||
let tldData = pricingData.records.find(record =>
|
||||
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||
record.command === 'create'
|
||||
record.command === 'create' &&
|
||||
record.registrar_id == registrarId
|
||||
);
|
||||
|
||||
// If no registrar-specific price found, find the generic price
|
||||
if (!tldData) {
|
||||
tldData = pricingData.records.find(record =>
|
||||
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||
record.command === 'create' &&
|
||||
record.registrar_id == null
|
||||
);
|
||||
}
|
||||
|
||||
if (tldData) {
|
||||
const priceField = `m${years * 12}`;
|
||||
let price = parseFloat(tldData[priceField]);
|
||||
|
@ -434,7 +445,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
|
||||
function updatePrice() {
|
||||
if (domainInput.value) {
|
||||
getDomainPrice(domainInput.value, yearInput.value).then(price => {
|
||||
const registrarId = registrarDropdown.value;
|
||||
getDomainPrice(domainInput.value, yearInput.value, registrarId).then(price => {
|
||||
priceValue.innerText = formatPrice(price);
|
||||
priceDisplay.style.display = 'block';
|
||||
});
|
||||
|
@ -445,6 +457,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
|
||||
domainInput.addEventListener('input', updatePrice);
|
||||
yearInput.addEventListener('input', updatePrice);
|
||||
registrarDropdown.addEventListener('change', updatePrice);
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -84,6 +84,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
yearValueDisplay.textContent = `${yearSlider.value} Year${yearSlider.value > 1 ? 's' : ''}`;
|
||||
});
|
||||
|
||||
const registrarId = "{{ registrars.id }}"; // Embedded securely in JavaScript
|
||||
const domainInput = document.getElementById('domainName');
|
||||
const yearInput = document.getElementById('renewalYears');
|
||||
const priceDisplay = document.getElementById('domainPriceDisplay');
|
||||
|
@ -102,7 +103,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
}
|
||||
}
|
||||
|
||||
function getDomainPrice(domain, years) {
|
||||
function getDomainPrice(domain, years, registrarId) {
|
||||
const tld = extractTLD(domain);
|
||||
if (!tld) {
|
||||
return Promise.reject("Invalid TLD");
|
||||
|
@ -127,12 +128,22 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
(!record.years_of_promotion || record.years_of_promotion >= years)
|
||||
);
|
||||
|
||||
// Find the regular price for the TLD
|
||||
const tldData = pricingData.records.find(record =>
|
||||
// Find the regular price for the TLD with registrar ID
|
||||
let tldData = pricingData.records.find(record =>
|
||||
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||
record.command === 'renew'
|
||||
record.command === 'renew' &&
|
||||
record.registrar_id == registrarId
|
||||
);
|
||||
|
||||
// If no registrar-specific price found, find the generic price
|
||||
if (!tldData) {
|
||||
tldData = pricingData.records.find(record =>
|
||||
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||
record.command === 'renew' &&
|
||||
record.registrar_id == null
|
||||
);
|
||||
}
|
||||
|
||||
if (tldData) {
|
||||
const priceField = `m${years * 12}`;
|
||||
let price = parseFloat(tldData[priceField]);
|
||||
|
@ -164,8 +175,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
}
|
||||
|
||||
function updatePrice() {
|
||||
if (domainInput.value) {
|
||||
getDomainPrice(domainInput.value, yearInput.value).then(price => {
|
||||
if (domainInput.textContent) {
|
||||
getDomainPrice(domainInput.textContent, yearInput.value, registrarId).then(price => {
|
||||
priceValue.innerText = formatPrice(price);
|
||||
priceDisplay.style.display = 'block';
|
||||
}).catch(error => {
|
||||
|
|
|
@ -101,6 +101,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
const yearInput = document.getElementById('transferYears');
|
||||
const priceDisplay = document.getElementById('domainPriceDisplay');
|
||||
const priceValue = document.getElementById('domainPrice');
|
||||
const registrarDropdown = document.getElementById('registrarDropdown');
|
||||
|
||||
function extractTLD(domain) {
|
||||
const parts = domain.split('.');
|
||||
|
@ -115,7 +116,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
}
|
||||
}
|
||||
|
||||
function getDomainPrice(domain, years) {
|
||||
function getDomainPrice(domain, years, registrarId) {
|
||||
const tld = extractTLD(domain);
|
||||
if (!tld) {
|
||||
return Promise.reject("Invalid TLD");
|
||||
|
@ -140,12 +141,22 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
(!record.years_of_promotion || record.years_of_promotion >= years)
|
||||
);
|
||||
|
||||
// Find the regular price for the TLD
|
||||
const tldData = pricingData.records.find(record =>
|
||||
// Find the regular price for the TLD with registrar ID
|
||||
let tldData = pricingData.records.find(record =>
|
||||
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||
record.command === 'transfer'
|
||||
record.command === 'transfer' &&
|
||||
record.registrar_id == registrarId
|
||||
);
|
||||
|
||||
// If no registrar-specific price found, find the generic price
|
||||
if (!tldData) {
|
||||
tldData = pricingData.records.find(record =>
|
||||
record.tldid && tldRegex.test(record.tldid.tld.toLowerCase()) &&
|
||||
record.command === 'transfer' &&
|
||||
record.registrar_id == null
|
||||
);
|
||||
}
|
||||
|
||||
if (tldData) {
|
||||
const priceField = `m${years * 12}`;
|
||||
let price = parseFloat(tldData[priceField]);
|
||||
|
@ -178,7 +189,8 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
|
||||
function updatePrice() {
|
||||
if (domainInput.value) {
|
||||
getDomainPrice(domainInput.value, yearInput.value).then(price => {
|
||||
const registrarId = registrarDropdown.value;
|
||||
getDomainPrice(domainInput.value, yearInput.value, registrarId).then(price => {
|
||||
priceValue.innerText = formatPrice(price);
|
||||
priceDisplay.style.display = 'block';
|
||||
});
|
||||
|
@ -189,6 +201,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||
|
||||
domainInput.addEventListener('input', updatePrice);
|
||||
yearInput.addEventListener('input', updatePrice);
|
||||
registrarDropdown.addEventListener('change', updatePrice);
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue