Fix multilingual routing for virtual product pages
Use site()->visit() to properly set language context for virtual pages. This ensures UI translations and language-specific content work correctly on both /slug (French) and /en/slug (English) routes. Changes: - Add site()->visit($page, $lang) in routes to set page language - Create product controller for language detection - Fix add-to-cart button to update text in .txt div instead of button - Remove broken hooks approach Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
4489e705b8
commit
f4ecdcf947
7 changed files with 41 additions and 20 deletions
|
|
@ -10,6 +10,13 @@
|
|||
return;
|
||||
}
|
||||
|
||||
const buttonTextDiv = addToCartBtn.querySelector('.txt[data-button-text]');
|
||||
|
||||
if (!buttonTextDiv) {
|
||||
console.error('Button text div not found');
|
||||
return;
|
||||
}
|
||||
|
||||
const texts = {
|
||||
add: addToCartBtn.dataset.textAdd || 'Add to cart',
|
||||
adding: addToCartBtn.dataset.textAdding || 'Adding...',
|
||||
|
|
@ -28,13 +35,13 @@
|
|||
}
|
||||
|
||||
addToCartBtn.disabled = true;
|
||||
const originalText = addToCartBtn.textContent;
|
||||
addToCartBtn.textContent = texts.adding;
|
||||
const originalText = buttonTextDiv.textContent;
|
||||
buttonTextDiv.textContent = texts.adding;
|
||||
|
||||
try {
|
||||
const cartResult = await cart.addToCart(variantId, 1);
|
||||
|
||||
addToCartBtn.textContent = texts.added;
|
||||
buttonTextDiv.textContent = texts.added;
|
||||
addToCartBtn.classList.add('success');
|
||||
|
||||
document.dispatchEvent(new CustomEvent('cart:updated', {
|
||||
|
|
@ -43,19 +50,19 @@
|
|||
|
||||
setTimeout(() => {
|
||||
addToCartBtn.disabled = false;
|
||||
addToCartBtn.textContent = originalText;
|
||||
buttonTextDiv.textContent = originalText;
|
||||
addToCartBtn.classList.remove('success');
|
||||
}, 1500);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error adding to cart:', error);
|
||||
|
||||
addToCartBtn.textContent = texts.error;
|
||||
buttonTextDiv.textContent = texts.error;
|
||||
addToCartBtn.classList.add('error');
|
||||
|
||||
setTimeout(() => {
|
||||
addToCartBtn.disabled = false;
|
||||
addToCartBtn.textContent = originalText;
|
||||
buttonTextDiv.textContent = originalText;
|
||||
addToCartBtn.classList.remove('error');
|
||||
}, 2000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue