Liquid, JavaScript, Themes
Hallo!
Ich habe folgendes Problem:
ich muss den Produktpreis in Netto führen und dann beim Produkt Brutto anzeigen lassen:
{{ product.price | times: 1.1 | money }}
Soweit alles gut. Jedoch habe ich mehrere Varianten der Produkte und diese haben unterschiedliche Preise.
Gibt es eine Möglichkeit mit Javascript nach der Auswahl des Radiobuttons (Produktvariante) den Preis zu aktualisieren lassen? Der Preis ist ja beim Produkt zu jeweiliger Variante hinzugefügt.
Danke für eure Hilfestellung!
LG Franz
Gelöst! Zur Lösung
Erfolg.
Hallo @franz-messner,
so wie es ausschaut bist du an der richtigen Stelle. Aber wie man jetzt am Besten die Anpassung macht, bzw. die Daten abfängt, hängt von verschiedenen Faktoren ab. Im Prinzip gibt es viele Möglichkeiten dazu, aber für die Diskussion hier im Forum ist das zu komplex.
Falls ich dir da helfen soll, schicke mir doch eine private Nachricht.
Gruß
Thomas
Hallo Franz, @franz-messner
das geht wohl nur über JavaScript, vermutlich am einfachsten mit jQuery. Wenn die Seite auf der Serverseite mit der Liquid-Engine gerendert ist, kommst du mit Liquid nicht mehr weiter.
Gruß
Thomas
Hallo Tewe!
Danke für die Rückmeldung! Das ich Javascript brauchen werde ist klar... ich denke gerade nach wo ich die Infos abfangen kann ... in der theme.js habe ich den code:
/**
* This callback is called whenever the variant changes and allows to update data about the active variant
*/
}, {
key: '_onVariantChanged',
value: function _onVariantChanged(previousVariant, newVariant) {
// 1st: the prices
this._updateProductPrices(newVariant, previousVariant);
// 2nd: update inventory
this._updateInventory(newVariant, previousVariant);
// 3rd: update SKU
this._updateSku(newVariant, previousVariant);
// 4th: update the price measurement
this._updateUnitPrice(newVariant, previousVariant);
// 5th: the add to cart button
this._updateAddToCartButton(newVariant, previousVariant);
// 6th: store availability
this.storeAvailability.updateWithVariant(newVariant);
// Finally, we send an event so that other system could hook and do their own logic
this.element.dispatchEvent(new CustomEvent('variant:changed', {
bubbles: true,
detail: { variant: newVariant, previousVariant: previousVariant }
}));
}
/**
* Update the prices (optionally showing compare at price)
*/
}, {
key: '_updateProductPrices',
value: function _updateProductPrices(newVariant, previousVariant) {
var productMetaPrices = this.element.querySelector('.ProductMeta__PriceList');
if (!newVariant) {
productMetaPrices.style.display = 'none';
} else {
if (previousVariant && previousVariant['price'] === newVariant['price'] && previousVariant['compare_at_price'] === newVariant['compare_at_price']) {
return; // The price do not have changed so let's return to avoid changing the DOM for nothing
}
productMetaPrices.innerHTML = '';
if (newVariant['compare_at_price'] > newVariant['price']) {
productMetaPrices.innerHTML += '<span class="ProductMeta__Price Price Price--highlight Text--subdued u-h4" data-money-convertible>' + __WEBPACK_IMPORTED_MODULE_4__helper_Currency__["default"].formatMoney(newVariant['price'], window.theme.moneyFormat) + '</span>';
productMetaPrices.innerHTML += '<span class="ProductMeta__Price Price Price--compareAt Text--subdued u-h4" data-money-convertible>' + __WEBPACK_IMPORTED_MODULE_4__helper_Currency__["default"].formatMoney(newVariant['compare_at_price'], window.theme.moneyFormat) + '</span>';
} else {
productMetaPrices.innerHTML += '<span class="ProductMeta__Price Price Text--subdued u-h4" data-money-convertible>' + __WEBPACK_IMPORTED_MODULE_4__helper_Currency__["default"].formatMoney(newVariant['price'], window.theme.moneyFormat) + '</span>';
}
productMetaPrices.style.display = '';
}
}
gefunden.
Wie komme ich aber jetzt dort hin, dass ich das HTML/Liquid Element refreshe....
LG
Erfolg.
Hallo @franz-messner,
so wie es ausschaut bist du an der richtigen Stelle. Aber wie man jetzt am Besten die Anpassung macht, bzw. die Daten abfängt, hängt von verschiedenen Faktoren ab. Im Prinzip gibt es viele Möglichkeiten dazu, aber für die Diskussion hier im Forum ist das zu komplex.
Falls ich dir da helfen soll, schicke mir doch eine private Nachricht.
Gruß
Thomas
Mit dem Lernpfad der Shopify Academy und dem Verified Skills-Badge Expanding Your Sho...
By Shopify Feb 7, 2025Den Verkauf im Großhandel steigern: In der Shopify Academy lernst du, wie das geht, zum...
By Shopify Feb 3, 2025Teil 2 - Wie die Prinzipien des UX-Designs dir dabei helfen können einen großartigen Shop ...
By Kai Sep 16, 2024