public static function cart_total(&$total_data = array()) { $models = oc::model('setting_extension')->getExtensions('total'); $sort_order = array(); foreach ($models as $key => $value) { $sort_order[$key] = oc::$config->get($value['code'] . '_sort_order'); } array_multisort($sort_order, SORT_ASC, $models); $total = 0; $taxes = oc::cart()->getTaxes(); foreach ($models as $m) { if (oc::$config->get($m['code'] . '_status')) { oc::model('total_' . $m['code'])->getTotal($total_data, $total, $taxes); } } return $total; }
public static function display($tpl, &$params = array()) { $loader = new Twig_Loader_Filesystem(); $paths = scandir(self::$twig); foreach ($paths as $path) { if ($path != '.' && $path != '..' && is_dir(self::$twig . "/{$path}")) { $loader->addPath(self::$twig . "/{$path}", $path); } } $twig = new Twig_Environment($loader, array('cache' => $_SERVER['DOCUMENT_ROOT'] . '/twig_cache', 'autoescape' => false, 'debug' => true, 'auto_reload' => true)); $twig->addExtension(new Twig_Extension_Debug()); $thumb = new Twig_SimpleFunction('thumb', function ($img, $w, $h) { return oc::model('tool_image')->resize($img, $w, $h); }); $twig->addFunction($thumb); $watermark = new Twig_SimpleFilter('watermark', function ($img, $type = 'tiles', $hide = 100) { return oc::image_watermark($img, $type, $hide); }); $twig->addFilter($watermark); $image_url = new Twig_SimpleFilter('image_url', function ($path) { return oc::image_url($path); }); $twig->addFilter($image_url); $showPrice = new Twig_SimpleFilter('price', function ($n, $decimals = 0, $dec_point = '.', $thousands_sep = ' ') { return number_format($n, $decimals, $dec_point, $thousands_sep); }); $twig->addFilter($showPrice); $showdate = new Twig_SimpleFunction('show_date', function ($dt, $to = 'full', $from = 'mysql') { static $months = array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'); $parts = array(); if ($from == 'mysql') { //2011-09-30 01:06:53 preg_match("/^(\\d{4})-(\\d{2})-(\\d{2})/", $dt, $parts); } if ($to == 'full') { return $parts[3] . ' ' . $months[$parts[2] - 1] . ' ' . $parts[1] . ' г.'; } else { if ($to == 'short') { return $parts[3] . '.' . $parts[2] . '.' . $parts[1]; } } }); $twig->addFunction($showdate); $repeat = new Twig_SimpleFilter('repeat', function ($s, $n) { return str_repeat($s, $n); }); $twig->addFilter($repeat); $firstp = new Twig_SimpleFilter('firstp', function ($s) { return substr($s, 0, strpos($s, "</p>") + 4); }); $twig->addFilter($firstp); $replaceURI = new Twig_SimpleFilter('replaceURI', function ($url, $nm, $val) { return preg_match("/[?&]{1}{$nm}=/", $url) ? preg_replace("/([?&]{1}{$nm})=[^&]*/", "\$1={$val}", $url) : $url . (strpos($url, '?') === false ? '?' : '&') . "{$nm}={$val}"; }); $twig->addFilter($replaceURI); $findAttribute = new Twig_SimpleFilter('attribute', function ($allAttributes, $name) { list($groupName, $attrName) = explode(':', $name); foreach ($allAttributes as $group) { if (mb_strtolower($group['name'], 'UTF-8') == mb_strtolower($groupName, 'UTF-8')) { foreach ($group['attribute'] as $attribute) { if (mb_strtolower($attribute['name'], 'UTF-8') == mb_strtolower($attrName, 'UTF-8')) { return $attribute['text']; } } } } return ''; }); $twig->addFilter($findAttribute); self::$params['path'] = self::$root; self::$params['server'] = array('request_uri' => html_entity_decode($_SERVER['REQUEST_URI'])); self::$params['cart'] = array('total_products' => oc::cart()->countProducts(), 'total_sum' => oc::cart()->getTotal()); self::$params['uname'] = oc::customer()->isLogged() ? oc::customer()->getLastName() . ' ' . oc::customer()->getFirstName() : null; $twig->display("@{$tpl}.html", self::$params); }