<?php
/*
* Copyright Bekanntmacher
*
* @author Simon Wohler <s.wohler@bekanntmacher.ch>
* @license commercial
*/
namespace Bekanntmacher\BoxmakerBundle\Module;
use Bekanntmacher\BoxmakerBundle\Classes\Config;
use Bekanntmacher\BoxmakerBundle\Model\FarbeModel;
use Bekanntmacher\BoxmakerBundle\Model\TypeModel;
use Bekanntmacher\BoxmakerBundle\Model\ConfigModel;
use Bekanntmacher\BoxmakerBundle\Model\WelleModel;
use Bekanntmacher\BoxmakerBundle\Model\TypeOptionModel;
use Bekanntmacher\BoxmakerBundle\Module\CartUtil;
/**
* Boxmaker Typelist
*/
class Cart extends TypeUtil
{
/**
* @var string Template
*/
protected $strTemplate = 'mod_boxmaker_cart';
/**
* The Configuration object
* @var object
*/
protected $objConfig;
/**
* Display a wildcard in the back end
* @return string
*/
public function generate()
{
// Display a wildcard in the back end
if (TL_MODE === 'BE')
{
$template =new \BackendTemplate('be_wildcard');
$template->wildcard = '### BOXMAKER TYPE DETAIL ###';
$template->title = $this->name;
$template->id = $this->id;
$template->link = $this->name;
$template->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
}
return parent::generate();
}
/**
* Generate the module
*/
public function compile()
{
// Instantiate session
$objSession = \System::getContainer()->get('session');
// check if a cart exists
if($objSession->has('mybox_cart') && $objSession->get('mybox_cart') !== null)
{
$arrCart = $objSession->get('mybox_cart');
} else {
$arrCart = array();
$this->Template->empty = true;
}
// Instantiate config
$this->objConfig = new Config(ConfigModel::findByPk($this->boxmaker_config)->row());
$this->Template->boxmaker_config = $this->boxmaker_config;
// Instantiate cart util
$objCartUtil = new CartUtil($this->objConfig);
// Generate cart items
$cart_items = array();
foreach ($arrCart as $pos => $arrType)
{
$cart_items[] = $objCartUtil->renderType($pos, $arrType, 'cart_item');
}
$this->Template->cart_items = $cart_items;
// Cart Footer
$this->Template->show_total = (count($arrCart) == 1) ? true : false;
$this->Template->boxmaker_currency = $this->objConfig->boxmaker_currency;
$this->Template->zwischensumme = $objCartUtil->getAmount($objCartUtil->zwischensumme, false);
// VEK
$vek = $objCartUtil->zwischensumme * ($this->objConfig->boxmaker_vek/100);
$this->Template->vek = $objCartUtil->getAmount($vek, false);
$this->Template->vek_prozent = $this->objConfig->boxmaker_vek . ' % ' . $GLOBALS['TL_LANG']['MSC']['boxmaker_vek_label'];
$mwst = ($objCartUtil->zwischensumme + $vek) * ($this->objConfig->boxmaker_mwst/100);
$this->Template->mwst = $objCartUtil->getAmount($mwst, false);
$this->Template->mwst_satz = $this->objConfig->boxmaker_mwst . '%';
$this->Template->total = $objCartUtil->getAmount($objCartUtil->zwischensumme + $vek + $mwst, false);
$this->Template->message_plus = $objCartUtil->getMessagePlus();
}
}