Exemple #1
0
 /**
  * @param bool $addNoindex
  * @return string
  */
 public function render($addNoindex = true)
 {
     if (!JBCart::getInstance()->canAccess($this->app->user->get())) {
         return JText::_('JBZOO_CART_UNABLE_ACCESS');
     }
     return parent::render($addNoindex);
 }
 /**
  * @param array $data
  * @return $this
  */
 public function bindData($data = array())
 {
     if (!$this->getOrder()->id) {
         JBCart::getInstance()->setModifier($this->identifier, $data);
     }
     return parent::bindData($data);
 }
Exemple #3
0
 /**
  * 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);
 }
Exemple #4
0
 /**
  * @param $code
  */
 public function ajaxSetCode($code = null)
 {
     $this->bindData(array('code' => $code));
     $inList = $this->_isInList();
     $result = array('cart' => JBCart::getInstance()->recount());
     if (!$inList) {
         $result['message'] = JText::_('JBZOO_ELEMENT_MODIFIERORDERPRICE_DISCOUNTCODE_NOTFOUND');
         $this->bindData(array('code' => ''));
     }
     $this->app->jbajax->send($result, $inList);
 }
Exemple #5
0
 /**
  * Action for robot from payment system
  * Validate and check order as success
  * @throws AppException
  */
 public function paymentCallback()
 {
     $this->_init();
     $this->app->jbevent->fire($this->order, 'basket:paymentCallback');
     $this->app->jbdoc->rawOutput();
     $cart = JBCart::getInstance();
     /** @type JBCartElementPayment $payment */
     $payment = $this->order->getPayment();
     // check payment element
     if (empty($payment)) {
         $this->_error('Saved without payment element');
     }
     // payment is exists
     if (!$this->_orderInfo->get('type')) {
         $this->_error('Undefined payment system');
     }
     // check payment type
     if ($payment->getType() != $this->_orderInfo->get('type')) {
         $this->_error('Payment type is not correct');
     }
     // current status is not completed
     if ($payment->getStatus() == $cart->getPaymentSuccess()) {
         $this->_error('Payment status is "' . $payment->getStatus()->getCode() . '" already');
     }
     // check sum
     $realSum = $payment->getOrderSumm();
     $requestSum = $payment->getRequestOrderSum();
     if ($realSum->compare($requestSum, '!=', 5)) {
         $this->_error('Not correct amount');
     }
     // check if sum was empty
     if ($realSum->compare(0, '<=')) {
         $this->_error('Amount less or equal zero');
     }
     // checking of payment element
     if ($payment->isValid()) {
         $payment->setSuccess();
         $this->app->event->dispatcher->notify($this->app->event->create($this->order, 'basket:paymentSuccess'));
         $payment->renderResponse();
     } else {
         $this->_error('No valid request');
     }
 }
 /**
  * @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);
 }
Exemple #8
0
 /**
  * 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;
 }
Exemple #9
0
 /**
  * @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;
 }
Exemple #10
0
 /**
  * @param $identifier
  * @return JBCartElementShipping
  */
 protected function _getElement($identifier)
 {
     $shippingList = JBCart::getInstance()->getShippingList();
     if ($shipping = $this->_order->getShippingElement($identifier)) {
         if (isset($shippingList[$identifier])) {
             $shipping->bindData($shippingList[$identifier]);
         }
     }
     return $shipping;
 }
Exemple #11
0
 /**
  * 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>';
 }
Exemple #12
0
 /**
  * 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;
 }
Exemple #13
0
 /**
  * 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;
 }
Exemple #14
0
<?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       Sergey Kalistratov <*****@*****.**>
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
$this->app->jbassets->less('jbassets:less/cart/mobile-tools.less');
$order = JBCart::getInstance()->newOrder();
?>

<div class="jbcart-mobile-tools">
    <div class="jbtool-total-price">
        <span class="jbtool-label"><?php 
echo JText::_('JBZOO_CART_TOTAL_SUM');
?>
:</span>
        <span class="jbtool-value jsTotal"><?php 
echo $order->getTotalSum()->html();
?>
</span>
    </div>

    <?php 
echo $this->partial('basket', 'mobile_buttons');
Exemple #15
0
 /**
  * Set success payment status to order
  */
 public function setSuccess()
 {
     $order = $this->getOrder();
     $payment = $order->getPayment();
     $cart = JBCart::getInstance();
     if ($payment) {
         $successStatus = $cart->getPaymentSuccess();
         $payment->setStatus($successStatus);
         JBModelOrder::model()->save($order);
     }
 }
Exemple #16
0
 /**
  * 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;
 }
Exemple #17
0
 /**
  * Remove from cart method
  * @param string $key - Session key
  * @return mixed
  */
 public function ajaxRemoveFromCart($key = null)
 {
     if (!(int) $this->config->get('remove_variant', 0)) {
         $key = null;
     }
     $item_id = $this->getItem()->id;
     $result = JBCart::getInstance()->remove($item_id, $this->identifier);
     $this->app->jbajax->send(array('removed' => $result));
 }
 /**
  * @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);
 }
Exemple #19
0
 /**
  * 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;
 }
Exemple #20
0
 /**
  * Include JBZoo Tools script
  */
 public function tools()
 {
     static $isAdded = false;
     if (!$isAdded) {
         $isAdded = true;
         $this->jQuery();
         $this->addScript(implode("\n\t", array('JBZoo.DEBUG = ' . (int) JDEBUG . ';', 'jQuery.migrateMute = false;')), false);
         $this->js(array('jbassets:js/libs/browser.min.js', 'jbassets:js/libs/cookie.min.js', 'jbassets:js/libs/sweet-alert.min.js', 'jbassets:js/helper.js', 'jbassets:js/widget.js', 'jbassets:js/jbzoo.js'), self::GROUP_LIBRARY);
         $this->js(array('jbassets:js/widget/goto.js', 'jbassets:js/widget/select.js', 'jbassets:js/widget/money.js', 'jbassets:js/widget/heightfix.js'));
         $this->css(array('jbassets:css/libs/sweet-alert.css'), self::GROUP_LIBRARY);
         if ($this->app->jbenv->isSite()) {
             $cartItems = JBCart::getInstance()->getItems();
             $this->addVar('currencyList', $this->app->jbmoney->getData());
             $this->addVar('cartItems', $this->app->jbarray->map($cartItems, 'element_id', 'element_id', 'item_id'));
         }
         $this->addVar('JBZOO_DIALOGBOX_OK', JText::_('JBZOO_DIALOGBOX_OK'));
         $this->addVar('JBZOO_DIALOGBOX_CANCEL', JText::_('JBZOO_DIALOGBOX_CANCEL'));
         $this->widget('.jbzoo .jsGoto', 'JBZoo.Goto');
         $this->widget('.jbzoo select', 'JBZoo.Select');
     }
 }
Exemple #21
0
 /**
  * @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;
 }
Exemple #22
0
/**
 * 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');
$this->app->jbassets->less('jbassets:less/cart/table.less');
$string = $this->app->jbstring;
$jbhtml = $this->app->jbhtml;
$cart = JBCart::getInstance();
$order = $cart->newOrder();
$config = $cart->getConfig();
$bootstrap = $this->app->jbbootstrap;
echo $this->partial('basket', 'table.styles');
?>

<table class="jbcart-table jsJBZooCartTable">
    <thead>
    <tr>
        <th class="jbcart-col jbcart-col-image"></th>
        <th class="jbcart-col jbcart-col-name"><?php 
echo JText::_('JBZOO_CART_ITEM_NAME');
?>
</th>
        <th class="jbcart-col jbcart-col-price"><?php 
Exemple #23
0
 /**
  * Default params to Call Service.
  * @return array
  */
 public function _getDefaultParams()
 {
     $prop = $this->getCartProperties();
     $params = array('city' => $this->_getDefaultCity(), 'weight' => JBCart::getInstance()->getWeight(), 'height' => $prop['height'], 'width' => $prop['width'], 'depth' => $prop['length'], 'date' => date('Y-m-d H:i:s'));
     return $params;
 }
Exemple #24
0
 /**
  * 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();
 }
Exemple #25
0
 /**
  * @param       $value
  * @return mixed
  */
 public function format($value)
 {
     $this->init();
     return JBCart::val($value)->text();
 }
Exemple #26
0
 /**
  * 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');
 }
Exemple #27
0
 /**
  * Method using to take data from element with ajax
  */
 public function callElement()
 {
     // get request
     $group = $this->app->request->getCmd('group', '');
     $elementId = $this->app->request->getCmd('element', '');
     $orderId = $this->app->request->getInt('order_id', '');
     $method = $this->app->request->getCmd('method', '');
     $args = $this->app->request->getVar('args', array(), 'default', 'array');
     if ($orderId > 0) {
         $order = JBModelOrder::model()->getById($orderId);
     } else {
         $order = JBCart::getInstance()->newOrder();
     }
     if (empty($order)) {
         return $this->app->error->raiseError(404, JText::_('Order not found'));
     }
     // get element
     if ($group == JBCart::CONFIG_SHIPPINGS) {
         // custom init with session data
         $element = $order->getShippingElement($elementId);
     } elseif ($group == JBCart::CONFIG_MODIFIER_ORDER_PRICE) {
         // custom init with session data
         $element = $order->getModifierOrderPriceElement($elementId);
     } else {
         $element = $order->getElement($elementId, $group);
     }
     if (empty($element)) {
         return $this->app->error->raiseError(404, JText::_('Element not forund'));
     }
     if (!$element->canAccess($this->app->user->get())) {
         return $this->app->error->raiseError(403, JText::_('Unable to access item'));
     }
     $element->callback($method, $args);
 }
Exemple #28
0
 /**
  * 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);
 }
Exemple #29
0
 /**
  * @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;
 }
Exemple #30
0
 /**
  * Get session key and check if variant is in cart
  * @param AppData|array $params
  * @return array
  */
 protected function _interfaceParams($params = array())
 {
     $cart = JBCart::getInstance();
     $key = $this->getJBPrice()->getList()->getSessionKey();
     return array('key' => $key, 'item_id' => $this->item_id, 'element_id' => $this->element_id, 'isModal' => $this->_isModal(), 'basket' => $this->_getBasketUrl(), 'isInCart' => (int) $cart->inCart($this->item_id, $this->element_id));
 }