/** * Get elements value * @param string $key Array key. * @param mixed $default Default value if data is empty. * @param bool $toString A string representation of the value. * @return mixed|string */ public function getValue($toString = false, $key = 'value', $default = null) { $value = parent::getValue($toString, $key, $default); $value = $this->clearSymbols($value, array('-', '+')); if ($toString) { return $value; } return JBCart::val($value); }
/** * @return array */ protected function _getSliderParams() { $categoryId = $min = $max = null; $to = $this->_getCurrency(); $params = array('auto' => (int) $this->_params->get('jbzoo_filter_slider_auto', 0), 'min' => $this->_params->get('jbzoo_filter_slider_min', 0), 'max' => $this->_params->get('jbzoo_filter_slider_max', 10000), 'step' => $this->_params->get('jbzoo_filter_slider_step', 100)); if ($params['auto']) { $applicationId = (int) $this->_params->get('item_application_id', 0); $isCatDepend = (int) $this->_params->moduleParams->get('depend_category'); $itemType = $this->_params->get('item_type', null); if ($isCatDepend) { $categoryId = $this->app->jbrequest->getSystem('category'); } $rangesData = (array) JBModelValues::model()->getRangeByPrice($this->_jbprice->identifier, $itemType, $applicationId, $categoryId); $cur = JBModelConfig::model()->getCurrency(); $params['min'] = JBCart::val($rangesData['total_min'], $cur)->val($to); $params['max'] = JBCart::val($rangesData['total_max'], $cur)->val($to); } return $params; }
/** * Render HTML * @return string */ public function html() { $html = array(); $value = $this->_prepareValues(); $categoryId = $min = $max = null; $params = array('auto' => (int) $this->_params->get('jbzoo_filter_slider_auto', 0), 'min' => $this->_params->get('jbzoo_filter_slider_min', 0), 'max' => $this->_params->get('jbzoo_filter_slider_max', 10000), 'step' => $this->_params->get('jbzoo_filter_slider_step', 100)); $to = $this->_params->get('jbzoo_filter_currency_default', 'default_cur'); if ($params['auto']) { $applicationId = (int) $this->_params->get('item_application_id', 0); $isCatDepend = (int) $this->_params->moduleParams->get('depend_category'); $itemType = $this->_params->get('item_type', null); if ($isCatDepend) { $categoryId = $this->app->jbrequest->getSystem('category'); } $rangesData = (array) JBModelValues::model()->getRangeByPrice($this->_jbprice->identifier, $itemType, $applicationId, $categoryId); $cur = JBModelConfig::model()->getCurrency(); $params['min'] = JBCart::val($rangesData['total_min'] ? $rangesData['total_min'] . $cur : $params['min'])->val($to); $params['max'] = JBCart::val($rangesData['total_max'] ? $rangesData['total_max'] . $cur : $params['max'])->val($to); } $html[] = $this->_html->sliderInput($params, $value['range'], $this->_getName('range'), $this->app->jbstring->getId('jsSlider-'), $to); $html[] = $this->renderCurrency(); return implode(PHP_EOL, $html); }
/** * Check if string has plus|minus|percent at the start or end * @param string|int $value * @return bool|string */ public function isModifier($value) { if (!empty($value) && ($value[0] === '-' || $value[0] === '+' || $value[0] === '%')) { return $value[0]; } $value = JBCart::val($value); if ($value->isCur('%')) { return true; } return false; }
/** * @return array() */ public function getTotalSum() { $select = $this->_getSelect()->select('SUM(tOrder.total) AS total')->from(ZOO_TABLE_JBZOO_ORDER, 'tOrder'); $result = $this->fetchRow($select); $value = JBCart::val($result->total); return $value; }
/** * Recount all basket * @return array */ public function recount() { $this->app->jbevent->fire($this, 'basket:recount'); $cookieCur = $this->app->jbrequest->getCurrency(); $this->updateItems(); $this->checkItems(); $order = $this->newOrder(); $session = $this->_getSession(); // items $items = $order->getTotalForItems(true); $itemsRes = array(); foreach ($items as $key => $itemSumm) { $itemsRes['Price-' . $key] = $itemSumm->convert($cookieCur)->data(); } $items = $this->getItems(); foreach ($items as $key => $data) { $itemsRes['Price4One-' . $key] = $this->val($data['total'])->convert($cookieCur)->data(); } // shipping $shippingRes = array(); if (isset($session['shipping'])) { foreach ($session['shipping'] as $elemId => $shipping) { if ($elemId == '_shipping_id') { continue; } if ($element = $order->getShippingElement($elemId)) { $element->bindData($shipping); $modRate = JBCart::val(); try { $modRate = $element->getRate(); } catch (JBCartElementShippingException $e) { $shippingRes[$elemId . '-exception'] = $e->getMessage(); } if (!$modRate->isCur('%')) { $modRate->convert($cookieCur); } $shippingRes['Price-' . $elemId] = $modRate->data(); $shippingRes[$elemId . '-ajax'] = $element->getAjaxData(); } } } // modifiers $modiferRes = array(); $elements = $order->getModifiersOrderPrice(); if (!empty($elements)) { foreach ($elements as $identifier => $modifier) { $modRate = $modifier->getRate(); if (!$modRate->isCur('%')) { $modRate->convert($cookieCur); } $modiferRes['Modifier-' . $identifier] = array('MoneyWrap' => $modRate->data()); } } $totalPrice = $order->getTotalForItems(); if (!$totalPrice->isCur('%')) { $totalPrice->convert($cookieCur); } $shippingPrice = $order->getShippingPrice(false); if (!$shippingPrice->isCur('%')) { $shippingPrice->convert($cookieCur); } $total = $order->getTotalSum(false); if (!$total->isCur('%')) { $total->convert($cookieCur); } // result $result = array('Modifier' => $modiferRes, 'CartTableRow' => $itemsRes, 'Shipping' => $shippingRes, 'TotalCount' => $order->getTotalCount(), 'TotalPrice' => $totalPrice->data(), 'ShippingPrice' => $shippingPrice->data(), 'Total' => $total->data()); return $result; }
/** * @param bool $addDefault * @return array */ public function getCurrencyList($addDefault = false) { $result = array('orig' => null, 'list' => array()); if (!empty($this->_curList)) { $defaultCur = $this->_params->get('currency_default', 'eur'); $multiply = $this->app->jbvars->number($this->_params->get('list_multiply', 1)); $moneyVal = JBCart::val(1, $defaultCur)->multiply($multiply); foreach ($this->_curList as $code => $currency) { if ($moneyVal->isCur($code)) { continue; } if (!($addDefault && $code == JBCartValue::DEFAULT_CODE)) { //continue; } $result['list'][$code] = array('from' => $moneyVal->html(), 'to' => $moneyVal->html($code), 'name' => $currency['name']); } $result['orig'] = $moneyVal; } return $result; }
/** * @param string $data * @param string $currency * @return JBCartValue */ public function val($data = '0', $currency = null) { $rates = (array) $this->getCurrencyList(); if ($currency === null) { $currency = $this->params->find('config.migration_currency', null); } return JBCart::val($data, $currency, $rates); }
/** * Adds modifier value of each option * @param array $options * @return array */ public function addModifiers($options = array()) { if (empty($options)) { return $options; } $result = array(); foreach ($options as $key => $option) { $total = JBCart::val(); $parts = explode('__', $key); if ($value = $this->getData($parts[1] . '._value.value')) { $total->set($value); } $result[$option] = $option . ' <em>' . $total->html($this->currency()) . '</em>'; } return $result; }
/** * Get default currency. * @return string */ public function currency() { $default = JBCart::val()->cur(); $params = $this->getParameter('_currency'); $currencyList = $params->get('currency_list', array()); if (count($currencyList) == 1 && !in_array('all', $currencyList)) { reset($currencyList); $key = current($currencyList); return $key; } if ((array) $params) { return $params->get('currency_default', $default); } $variant = $this->getList()->current(); if ($variant->has('_value')) { return $variant->getValue(false, '_value')->cur(); } return $default; }
/** * Render jQueryUI slider * @param array $params * @param string|array $value * @param string $name * @param string $idTag * @param string $currency * @return string */ public function sliderInput($params, $value = '', $name = '', $idTag = '', $currency = '') { $value = $value !== '' && is_string($value) ? explode('/', $value) : array($params['min'], $params['max']); // prepare vars $idTag = $idTag !== '' && $idTag !== null ? $idTag : $this->_jbstring->getId('jsSlider-'); $params['min'] = $this->_vars->number($params['min']); $params['max'] = $this->_vars->number($params['max']); $params['step'] = $this->_vars->number($params['step']); $paramMin = $this->_vars->money($params['min'] ?: 0, 2); $paramMax = $this->_vars->money($params['max'] ?: 10000, 2); $valueMin = JBCart::val($value[0], $currency)->setFormat(array('round_type' => 'floor', 'round_value' => '0'), $currency); $valueMax = JBCart::val($value[1], $currency)->setFormat(array('round_type' => 'ceil', 'round_value' => '0'), $currency); $html = array(); $html[] = '<div class="jbslider-ui jsUI"></div>'; // min box $html[] = '<div class="jbslider-input-box">'; $html[] = $valueMin->htmlInput($currency, array('class' => 'jsInput jsNoSubmit jsInput-min jbslider-input jbslider-input-min')); $html[] = '</div>'; // max box $html[] = '<div class="jbslider-input-box">'; $html[] = $valueMax->htmlInput($currency, array('class' => 'jsInput jsNoSubmit jsInput-max jbslider-input jbslider-input-max')); $html[] = '</div>'; $html[] = $this->hidden($name, $valueMin->val() . '/' . $valueMax->val(), array('class' => 'jsValue')); $html[] = $this->_assets->slider($idTag, array('min' => $paramMin, 'max' => $paramMax, 'step' => $params['step'], 'values' => array($valueMin->val(), $valueMax->val())), true); $html[] = JBZOO_CLR; return '<div id="' . $idTag . '" class="jbslider jsSlider jsNoCurrencyToggle">' . implode(PHP_EOL, $html) . '</div>'; }
/** * Render element id * @param string $name * @param string|array $value * @param string $controlName * @param SimpleXMLElement $node * @param SimpleXMLElement $parent * @return mixed */ public function currentRate($name, $value, $controlName, SimpleXMLElement $node, $parent) { /** @type JBCartElementCurrency $element */ $element = @$parent->element; if ($element) { $code = $element->getCode(); try { $value = $element->getValue($code); } catch (JBCartElementCurrencyException $e) { $value = $element->getFallbackValue(); } if ($value == 0 || $code == '%') { return '<em>' . JText::_('JBZOO_UNDEFINED') . '</em>'; } $value = JBCart::val($value . ' ' . $code); return $value->html() . ' (' . $value->noStyle() . ')'; } return JText::_('JBZOO_UNDEFINED'); }
/** * @param array $values * @param string $currency * @return array */ protected function _value($values, $currency = null) { $range = array(); if (isset($values['min'])) { $min = JBCart::val($values['min'], $currency)->val($this->_currency); $range[] = 'tSku.value_n >= ' . $this->_quote($min); } if (isset($values['max'])) { $max = JBCart::val($values['max'], $currency)->val($this->_currency); $range[] = ' tSku.value_n <= ' . $this->_quote($max); } return implode(' AND ', $range); }
/** * Get elements value * @param string $key Array key. * @param mixed $default Default value if data is empty. * @param bool $toString A string representation of the value. * @return mixed|string */ public function getValue($toString = false, $key = 'value', $default = null) { return JBCart::val()->cur(); }
<?php /** * JBZoo App is universal Joomla CCK, application for YooTheme Zoo component * @package jbzoo * @version 2.x Pro * @author JBZoo App http://jbzoo.com * @copyright Copyright (C) JBZoo.com, All rights reserved. * @license http://jbzoo.com/license-pro.php JBZoo Licence * @coder Alexander Oganov <*****@*****.**> */ // no direct access defined('_JEXEC') or die('Restricted access'); $elemId = $this->app->jbstring->getId('jbadvert'); $toggleList = array(0 => JText::_('JBZOO_NO'), 1 => JText::_('JBZOO_YES'), 2 => JText::_('JBZOO_JBADVERT_EDIT_IS_MODIFIED_EXEC')); $mode = $this->_getMode(); if ($mode == ElementJBAdvert::MODE_CATEGORY) { unset($toggleList[2]); } $toggler = $this->app->jbhtml->radio($toggleList, $this->getControlName('is_modified'), array(), $this->get('is_modified', 0)); echo '<div class="jbzoo"><div id="' . $elemId . '" class="jbadvert-edit">'; echo $this->app->jbhtml->dataList(array('JBZOO_JBADVERT_EDIT_IS_MODIFIED' => $toggler, 'JBZOO_JBADVERT_EDIT_PRICE' => JBCart::val($this->get('price', 0)), 'JBZOO_JBADVERT_EDIT_ORDER' => $this->_getRelatedOrder(true), 'JBZOO_JBADVERT_EDIT_MODIFIED' => $this->_getLastModified(), 'JBZOO_JBADVERT_EDIT_MODE' => JText::_('JBZOO_JBADVERT_MODE_' . $this->_getMode()), 'JBZOO_JBADVERT_EDIT_PARAMS' => $this->_renderModifierParams())); echo '</div></div>'; $this->loadAssets(); $this->app->jbassets->widget('#' . $elemId, 'JBZoo.JBAdvert', array('text_exec_alert' => JText::_('JBZOO_JBADVERT_EXEC_ALERT')));
/** * Get total sum * @return JBCartValue */ protected function _getPrice() { $price = $this->config->get('price', 0); $order = $this->_getRelatedOrder(); $result = JBCart::val($price); if ($order && $order->id) { $result = $order->val($price); } return $result; }
/** * @param $value * @return mixed */ public function format($value) { $this->init(); return JBCart::val($value)->text(); }
/** * Get the total price for the variant element - ElementJBPriceCalc * @return JBCartValue */ protected function _calcTotal() { $first = $this->first(); $price = clone $this->_calcPrice()->minus($first->getValue(false, '_discount', JBCart::val())->positive()); return $this->addModifiers($price, true); }
/** * @param mixed $value * @param string $action * @param bool $getClone * @return $this */ protected function _modifer($value, $action, $getClone = false) { $logMess = $newValue = null; if (self::ACT_PLUS == $action || self::ACT_MINUS == $action) { if ($value instanceof JBCartValue) { $logMess = ucfirst($action) . ' "' . $value->dump() . '"'; $addValue = 0; if ($this->_currency == self::PERCENT) { if ($value->cur() == self::PERCENT) { $addValue = $value->val(); } else { $this->_error('Impossible add "' . $value->text() . '" to "' . $this->text() . '"'); } } else { if ($value->cur() != self::PERCENT) { $addValue = $value->val($this->_currency); } else { $addValue = $this->_value * $value->val() / 100; } } if (self::ACT_MINUS == $action) { $addValue *= -1; } $newValue = $this->_value + $addValue; } else { $parsedValue = JBCart::val($value); // we work only with objects! return $this->_modifer($parsedValue, $action, $getClone); } } else { if (self::ACT_CONVERT == $action) { $newCurrency = $this->_checkCur($value); $obj = $getClone ? clone $this : $this; if ($newCurrency !== $obj->_currency) { $obj->_value = $obj->_convert($newCurrency, true); $obj->_currency = $newCurrency; } return $obj; } else { if (self::ACT_MULTIPLY == $action) { $value = (double) $value; $newValue = $value * $this->_value; $logMess = 'Multiply with "' . $value . '"'; } else { if (self::ACT_INVERT == $action) { $logMess = 'Invert sign'; if ($this->_value > 0) { $newValue = -1 * $this->_value; } else { if ($this->_value < 0) { $newValue = abs($this->_value); } else { $newValue = $this->_value; } } } else { if (self::ACT_POSITIVE == $action) { $newValue = abs($this->_value); $logMess = 'Set positive'; } else { if (self::ACT_NEGATIVE == $action) { $newValue = -1 * abs($this->_value); $logMess = 'Set negative'; } else { if (self::ACT_ABS == $action) { $newValue = abs($this->_value); $logMess = 'Set absolute value'; } else { if (self::ACT_CLEAN == $action) { $newValue = 0.0; $logMess = 'Set empty'; } else { if (self::ACT_MODIFY == $action) { if (method_exists($value, 'modify')) { $this->_log('Modyfied by elementId "' . $value->identifier . '"; ' . $value->getElementGroup() . '/' . $value->getElementType()); if ($getClone) { $clone = clone $this; $value->modify($clone); return $clone; } return $value->modify($this); } else { $this->_error('Value doesn\'t have modyfy action!'); } } else { if (self::ACT_PERCENT == $action) { $percent = 0.0; if (!$this->isEmpty() && !$value->isEmpty()) { $percent = $this->_value / $value->val($this->_currency) * 100; } return JBCart::val($percent, self::PERCENT); } else { $this->_error('Undefined action: "' . $action . '"'); } } } } } } } } } } if (is_null($newValue)) { $this->_error('Undefined new value for action=' . $action); } // create new object or return self if ($getClone) { $clone = clone $this; $clone->_value = $newValue; $clone->_log($logMess . '; New value = "' . $clone->dump() . '"'); return $clone; } $this->_value = $newValue; $this->_log($logMess . '; New value = "' . $this->dump() . '"'); return $this; }
/** * Get price for variant * @return JBCartValue */ public function getPrice() { if ($this->price === null) { $price = JBCart::val(); if ($element = $this->get('_value')) { $price->set($element->getValue(true)); if ($this->list->isOverlay === false && $element->isModifier() && !$this->isBasic()) { $price = $this->list->first()->getValue(false, '_value')->add($price); } } $this->price = $price; if ($this->list->isOverlay === false) { $this->price = $price->add($this->getValue(true, '_margin'), true); if ($this->list instanceof JBCartVariantList) { $this->price = $this->list->addModifiers($this->price, false); } } } return $this->price->getClone(); }