In Veyton die Anzahl der Produkte im Warenkorb und den Gesamtpreis im Menü anzeigen

Im Hauptmenü soll neben dem Link zum Warenkorb auch die Anzahl der Produkte im Warenkorb und der Gesamtpreis der Produkte sichtbar sein.

Menue mit Warenkorb, Anzahl der Produkte im Warenkorb und Gesamtbetrag der Artikel im Warenkorb
Menue mit Warenkorb, Anzahl der Produkte im Warenkorb und Gesamtbetrag der Artikel im Warenkorb

Um im Online Shop Veyton die Anzahl der Produkte und den Gesamtpreis im Menü anzuzeigen wird eine neue Box erstellt.

1. Folgende Dateien in den Verzeichnissen sind neu zu erstellen

1.1. meine_neue_box.php -> xtCore/boxes/
1.2. box_meine_neue_box.html -> templates/TEMPLATENAME/xtCore/boxes/

2. Inhalt der Datei: xtCore/boxes/meine_neue_box.php

<?php
defined('_VALID_CALL') or die('Direct Access is not allowed.');
if (is_object($_SESSION['cart']) && count($_SESSION['cart']->show_content) > 0){
  $tpl_data = array(
    'content_count' => $_SESSION['cart']->content_count,
    'cart_total' => $_SESSION['cart']->content_total['formated']
  );
$show_box = true;
}else{
  $tpl_data = array('show_cart_content'=>false);
}
?>

3. Inhalt der Datei: templates/TEMPLATENAME/xtCore/boxes/box_meine_neue_box.html

<small>{if $content_count}{$content_count}{else}0{/if} {txt key=TEXT_PRODUCTS_MENU}{if $cart_total} | {$cart_total}{/if}</small>

4. Eine neue Sprachvariable für Produkte anlegen

Die Variable wurde oben als „TEXT_PRODUCTS_MENU“ mit dem Wert „Produkte“ definiert. Damit es nicht 1 Produkte heißt, kann ggf. eine zusätzliche Sprachvariable für „Produkt“ angelegt werden. In der „box_meine_neue_box.html“ kann „$cart_total“ schließlich auf „1“ geprüft und die entsprechende Sprachvariable ausgegeben werden.

5. Box im Menü darstellen

Das Menü wird in der Datei templates/TEMPLATENAME/index.html definiert. Es kann zum Beispiel wie folgt ausschauen:

<ul id="topmenu">
  <li><a href="{link page='index' conn=SSL}">Start</a></li>
  <li><a href="{link page='xt_new_products' conn=SSL}">{txt key=TEXT_NEW_PRODUCTS}</a></li>
  <li><a href="{link page='xt_special_products' conn=SSL}">{txt key=TEXT_SPECIAL_PRODUCTS}</a></li>
  <li id="topmenu-last-listitem"><a href="{link page='cart'}">{txt key=TEXT_CART}</a></li>
</ul>

Im Link zum Warenkorb kann jetzt die Box durch {box name=meine_neue_box} ausgegeben werden.

Das Ganze schaut dann so aus:

<ul id="topmenu">
  <li><a href="{link page='index' conn=SSL}">Start</a></li>
  <li><a href="{link page='xt_new_products' conn=SSL}">{txt key=TEXT_NEW_PRODUCTS}</a></li>
  <li><a href="{link page='xt_special_products' conn=SSL}">{txt key=TEXT_SPECIAL_PRODUCTS}</a></li>
  <li id="topmenu-last-listitem"><a href="{link page='cart'}">{txt key=TEXT_CART}: {box name=meine_neue_box}</a></li>
</ul>

Schreibe einen Kommentar