/** * Class constructor * @param App $app * @param null $path */ public function __construct($app, $path = null) { parent::__construct($app, $path); $this->_position = $app->jbcartposition; $this->_element = $app->jbcartelement; $this->_config = JBModelConfig::model(); }
/** * @param array $app * @param array $config * @throws AppException */ public function __construct($app, $config = array()) { parent::__construct($app, $config); $this->_jbrequest = $this->app->jbrequest; $task = $this->_jbrequest->getWord('task'); $ctrl = $this->_jbrequest->getCtrl(); if (!method_exists($this, $task)) { throw new AppException('Action method not found! ' . $ctrl . ' :: ' . $task . '()'); } // internal vars $this->application = $this->app->zoo->getApplication(); $this->_params = $this->application->getParams('frontpage'); $this->joomla = $this->app->system->application; $isSite = $this->app->jbenv->isSite(); if (!$isSite) { $this->app->document->addStylesheet("root:administrator/templates/system/css/system.css"); $this->app->jbassets->uikit(true, true); $this->_setToolbarTitle(); } else { $this->params = $this->joomla->getParams(); $this->pathway = $this->joomla->getPathway(); $this->app->jbassets->setAppCSS(); $this->app->jbassets->setAppJS(); } $this->_config = JBModelConfig::model(); }
/** * Constructor * @param Element|String $element * @param Item $item * @param array $options */ function __construct($element, Item $item = null, $options = array()) { // get Zoo app $this->app = App::getInstance('zoo'); // set inner vars if (isset($options['elementId'])) { $this->_identifier = $options['elementId']; $this->_item = $item; $this->_element = $this->_item->getElement($this->_identifier); } else { if (is_object($element)) { $this->_element = $element; $this->_item = $element->getItem(); $this->_identifier = $element->identifier; } else { $this->_identifier = $element; } } // set repeatable flag if (is_object($this->_element) && is_subclass_of($this->_element, 'ElementRepeatable')) { $this->_isRepeatable = true; } // set Item object if (!$this->_item && $item) { $this->_item = $item; } // get current value for export) if ($this->_item && $this->_identifier && isset($this->_item->elements[$this->_identifier])) { $this->_value = $this->_item->elements[$this->_identifier]; } $this->_config = JBModelConfig::model(); $this->_exportParams = $this->_config->getGroup('export.items', array()); $this->_importParams = $this->_config->getGroup('import.items', array()); $this->_lastImportParams = $this->_config->getGroup('import.last.items', array()); }
/** * Init JBTemplate * @param $event */ public function init($event) { $application = $event->getSubject(); $isSite = $this->app->jbenv->isSite(); $appGroup = $application->application_group; $template = $application->params->get('template'); $controller = $this->app->jbrequest->get('controller'); $task = $this->app->jbrequest->get('task'); $application->cartConfig = JBModelConfig::model()->getGroup('cart.config'); if ($controller == 'basket' && $task == 'index') { $application->basketTmpl = $template = $application->cartConfig->get('tmpl_name', 'uikit'); } if ($isSite && $appGroup == JBZOO_APP_GROUP) { $classPath = $this->_getClassPath(); $tmplClassPath = $this->_getTmplClassPath($template); require_once "{$classPath}"; $this->_initMethod($event, $this->_classPrefix, 'init'); $template = $this->camelize($template); if (file_exists($tmplClassPath)) { require_once "{$tmplClassPath}"; $this->_initMethod($event, $this->_getClassName($template)); } else { $this->_initMethod($event, $this->_classPrefix); } } if ($appGroup == JBZOO_APP_GROUP) { JFactory::getLanguage()->load('jbzoo_' . $template, $this->app->path->path('jbtmpl:' . $template)); } }
/** * @param Element $element * @param int $applicationId * @param string $itemType */ public function __construct(Element $element, $applicationId, $itemType) { parent::__construct($element, $applicationId, $itemType); $this->money = $this->app->jbmoney; $this->helper = $this->app->jbprice; $this->_currency = JBModelConfig::model()->getCurrency(); }
/** * Compatibility list of params were saved in config files * @param string|null $group * @return array|object */ public function getList($group = null) { $ymlConfig = $this->app->path->path('jbapp:config') . '/yml_config.php'; if (JFile::exists($ymlConfig)) { require_once $ymlConfig; } $config = $this->app->path->path('jbapp:config') . '/config.php'; if (JFile::exists($config)) { require_once $config; } $result = array(); foreach ($this->_oldVersionMap as $key => $value) { if (!defined($key)) { continue; } if (in_array($key, array('JBZOO_CONFIG_YML_TYPE', 'JBZOO_CONFIG_YML_APP_LIST'))) { $result[$value] = explode(':', constant($key)); } else { $result[$value] = constant($key); } } if (!empty($group)) { $result = JBModelConfig::model()->getGroup($group, $result); } return $this->app->data->create($result); }
/** * @return array */ public function toCSV() { $params = JBModelConfig::model()->getGroup('export.items'); if ((int) $params->merge_repeatable) { return implode(JBCSVItem::SEP_ROWS, $this->_item->getTags()); } else { return $this->_item->getTags(); } }
/** * @param App $app */ public function __construct($app) { parent::__construct($app); $this->_lessFull = JPath::clean($this->app->path->path('jbapp:assets/less')); $this->_lessRel = JUri::root() . $this->app->path->relative($this->_lessFull); $this->_minFull = JPath::clean($this->app->path->path('root:') . '/cache/jbzoo_assets'); $this->_minRel = $this->app->path->relative($this->_minFull); $this->_force = (int) JBModelConfig::model()->get('less_mode', '0', 'config.assets'); $this->_jbcache = $this->app->jbcache; }
/** * Joomla Event onAfterInitialise */ public function onBeforeCompileHead() { // fix Zoo SEF problems $sefConfig = $this->_config->getGroup('config.sef'); $isSite = $this->app->jbenv->isSite(); if ($sefConfig->get('enabled') && $sefConfig->get('fix_canonical') && $isSite) { $this->app->jbsef->canonicalFix(); } // load all assets $this->app->jbassets->loadAll(); }
/** * @param string $layout * @return JSONData */ public function getLayoutParams($layout = 'default') { $positions = $this->_jbconfig->getGroup('cart.' . JBCart::CONFIG_FIELDS_TMPL . '.' . $layout); $elementsConfig = array(); foreach ($positions as $position) { foreach ($position as $element) { $elementsConfig[$element['identifier']] = $element; } } return $elementsConfig; }
/** * Class Constructor */ public function __construct() { // get app instance $this->app = App::getInstance('zoo'); $this->_config = JBModelConfig::model()->getGroup('cart'); // decorate data as object $this->params = $this->app->parameter->create(array(JBCart::CONFIG_MODIFIER_ORDER_PRICE => $this->_config->find(JBCart::ELEMENT_TYPE_MODIFIER_ORDER_PRICE . '.' . JBCart::DEFAULT_POSITION, array()), JBCart::CONFIG_MODIFIER_ITEM_PRICE => $this->_config->find(JBCart::ELEMENT_TYPE_MODIFIER_ITEM_PRICE . '.' . JBCart::DEFAULT_POSITION, array()))); // decorate data as object $this->_elements = $this->app->data->create(array()); $this->_items = $this->app->data->create($this->_items); }
/** * @param App $app */ public function __construct($app) { parent::__construct($app); $this->_config = JBModelConfig::model(); $this->_defaultCur = $this->_config->getCurrency(); $this->_currencyMode = $this->_config->get('undefined_currency', 'default', 'cart.config'); if (empty($this->_currencyMode)) { $this->_currencyMode = 'default'; } $this->_jbcache = $this->app->jbcache; }
/** * @param $params * @return mixed */ protected function _buildFeedUrl($params) { if (isset($params['segments'][0]) && $params['segments'][0] == 'feed') { if ($this->_config->get('fix_feed', 0)) { unset($params['segments'][0]); } if (isset($params['query']['format']) && $params['query']['format'] == 'feed') { // TODO remove bug with "Class 'JFeedItem' not found" // unset($params['query']['format']); } } return $params; }
/** * @param string $eventType * @param JBCartOrder $order * @return array */ public function getByEvent($eventType = null, $order) { $result = array(); $eventType = 'list'; // TODO add new evenet types $params = JBModelConfig::model()->get($eventType, array(), 'cart.validator'); if (!empty($params)) { $result = array(); foreach ($params as $elementParams) { $result[$elementParams['identifier']] = $order->getValidatorElement($elementParams['identifier']); } } return $result; }
/** * @param App $app */ public function __construct($app) { parent::__construct($app); $this->_cachePath = JPath::clean($this->app->path->path('root:') . '/cache/jbzoo_assets'); $this->_config = JBModelConfig::model()->getGroup('config.assets'); $this->_jbfile = $this->app->jbfile; $this->_jbcache = $this->app->jbcache; // for developers if ($this->_repoPath = realpath($this->app->path->path('jbapp:') . '/../../../')) { foreach ($this->_simlinks as $locPath => $repoPath) { $this->_simlinks[$locPath] = JPath::clean($this->_repoPath . '/' . $repoPath); } } else { $this->_simlinks = array(); } }
/** * On type deleted * @param AppEvent $event */ public static function deleted($event) { $app = self::app(); $type = $event->getSubject(); $config = JBModelConfig::model(); $elements = $app->jbprice->getTypePrices($type); $tableName = $app->jbtables->getIndexTable($type->id); $app->jbtables->dropTable($tableName); if (!empty($elements)) { foreach ($elements as $id => $element) { $config->removeGroup('cart.' . JBCart::ELEMENT_TYPE_PRICE . '.' . $id); $config->removeGroup('cart.' . JBCart::CONFIG_PRICE_TMPL . '.' . $id); $config->removeGroup('cart.' . JBCart::CONFIG_PRICE_TMPL_FILTER . '.' . $id); } } }
/** * @return string */ public function toCSV() { $settings = JBModelConfig::model()->getGroup('export.categories'); if ($settings->config_category_settings) { $arrayParams = array(); $params = $this->_category->getParams()->get('config.'); foreach ($params as $key => $value) { if ($key == 'show_feed_link') { $arrayParams[$key] = $value; } } $result = $this->_packToLine($arrayParams); return $result; } else { return parent::toCSV(); } }
/** * @return string */ public function toCSV() { $settings = JBModelConfig::model()->getGroup('export.categories'); if ($settings->category_settings) { $arrayParams = array(); $params = $this->_category->getParams()->get('template.'); foreach ($params as $key => $value) { if (preg_match('/^category*/', $key) && $key !== 'lastmodified') { $arrayParams[$key] = $value; } } $result = $this->_packToLine($arrayParams); return $result; } else { return parent::toCSV(); } }
/** * @return string */ public function toCSV() { $settings = JBModelConfig::model()->getGroup('export.categories'); if ($settings->config_items_order_settings) { $result = ''; $arrayParams = array(); $params = $this->_category->getParams()->get('config.'); foreach ($params as $key => $value) { if ($key == 'item_order') { $arrayParams = $value; } } $result = $this->_packToLine($arrayParams, true); return $result; } else { return parent::toCSV(); } }
/** * @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; }
/** * @param JBCartOrder $order * @param bool|false $silentMode * @return int|mixed */ public function save(JBCartOrder $order, $silentMode = false) { $this->app->jbtables->checkOrder(); $currencies = $order->getCurrencyList(); $params = $order->getParams(); $params->set(JBCart::CONFIG_CURRENCIES, $currencies); $cartConfig = $order->params->find('config'); if (!$cartConfig) { $cartConfig = JBModelConfig::model()->getGroup('cart.config'); } $params->set('config', (array) $cartConfig); $total = $order->getTotalSum()->data(); $data = array('id' => $order->id, 'status' => $order->getStatus()->getCode(), 'status_payment' => $order->getPaymentStatus(), 'status_shipping' => $order->getShippingStatus(), 'created' => $order->created, 'created_by' => $order->created_by, 'total' => $total[0], 'items' => $order->getItems(false), 'fields' => $order->getFields(), 'shippingfields' => $order->getShippingFields(), 'modifiers' => $order->getModifiersData(), 'params' => $params, 'comment' => $order->comment); if ($shipping = $order->getShipping()) { $data['shipping'] = $shipping->data(); } if ($payment = $order->getPayment()) { $data['payment'] = $payment->data(); } if (!$silentMode) { $this->app->jbevent->fire($order, 'basket:beforeSave'); } if ($data['id'] <= 0) { unset($data['id']); $order->id = $this->_insert($data, ZOO_TABLE_JBZOO_ORDER); //TODO hardcoded $order->setItemsData((string) $data['items']); if (!$silentMode) { $this->app->jbevent->fire($order, 'basket:saved'); } } else { $data['modified'] = $this->app->jbdate->toMySql(); $this->_update($data, ZOO_TABLE_JBZOO_ORDER); if (!$silentMode) { $this->app->jbevent->fire($order, 'basket:updated'); } } if ($order->id && !$silentMode) { $this->app->jbevent->fire($order, 'basket:afterSave'); } return $order->id; }
/** * @return string */ public function toCSV() { $settings = JBModelConfig::model()->getGroup('export.categories'); if ($settings->config_others_settings) { $arrayParams = array(); $paramsConfig = $this->_category->getParams()->get('config.'); $paramsTemplate = $this->_category->getParams()->get('template.'); $params = array_merge($paramsConfig, $paramsTemplate); $others = array('alpha_index', 'alpha_chars', 'show_alpha_index'); foreach ($params as $key => $value) { if (in_array($key, $others)) { $arrayParams[$key] = $value; } } $result = $this->_packToLine($arrayParams); return $result; } else { return parent::toCSV(); } }
/** * Create CSV file from $data * @param $data * @param $filename * @return string * @throws AppException */ protected function _createFile($data, $filename) { $file = $this->app->jbpath->sysPath('tmp', "/jbzoo-export/{$filename}.csv"); $config = $this->_config->getGroup('export'); $dirName = dirname($file); if (!JFolder::exists($dirName)) { JFolder::create($dirName); } if (!JFile::exists($file)) { $data = $this->_addHeader($data); } if (($handle = fopen($file, "a")) !== false) { foreach ($data as $row) { fputcsv($handle, $this->app->data->create($row)->flattenRecursive(), $config->get('separator', ','), $config->get('enclosure', '"')); } fclose($handle); } else { throw new AppException(sprintf('Unable to write to file %s.', $file)); } return $file; }
/** * 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); }
/** * Get elements search data * @return mixed */ public function getSearchData() { $prices = $this->getPrices(); return $prices['total']->val(JBModelConfig::model()->getCurrency()); }
/** * @param string $key * @param mixed $default * @return mixed */ public function getFilters($key, $default = null) { $key = strtolower(trim($key)); if (!isset($this->filter[$key])) { $parameters = array(); $storage = (array) JBModelConfig::model()->getGroup('cart.' . $key, array()); $parts = explode('.', $key); foreach ($storage as $position => $elements) { $_index = 0; foreach ($elements as $index => $params) { // Backward Compatibility. Delete later. if (!is_numeric($index)) { $index = $_index++; } $params['_position'] = $position; $params['_index'] = $index; $params['_template'] = end($parts); $parameters[] = $params; } } $this->filter->set($key, $parameters); } return $this->filter->get($key, $default); }
/** * @param string $layout * @return JSONData */ public function getLayoutParams($layout = 'default') { return $this->_jbconfig->get(JBCart::DEFAULT_POSITION, array(), 'cart.' . JBCart::CONFIG_SHIPPINGFIELDS); }
/** * Create form fields */ public function formFields() { $configModel = JBModelConfig::model(); $application = $this->_migrate->getCartApp(); $templatePath = null; $orderFields = null; if ($application) { $templatePath = $application->getTemplate()->getPath(); $orderFields = $this->_migrate->getOrderFields(); } if ($templatePath && $orderFields) { $posFile = $templatePath . '/renderer/item/positions.config'; $renderParams = array(); if (JFile::exists($posFile)) { $posFile = $this->app->data->create(json_decode(file_get_contents($posFile), true)); foreach ($posFile->get('jbuniversal.order.order', array()) as $position) { foreach ($position as $element) { $renderParams[$element['element']] = $element; } } } foreach ($renderParams as $elemId => $renderParam) { if (!isset($orderFields[$elemId])) { continue; } /** * @var AppData $config * @var AppData $renderParam */ $config = $this->app->data->create($orderFields[$elemId]); $renderParam = $this->app->data->create($renderParam); $elemType = isset($this->_elementMap[$config['type']]) ? $this->_elementMap[$config['type']] : 'text'; $orderElement = $this->_element->create($elemType, JBCart::ELEMENT_TYPE_ORDER, array('name' => $config->get('name'), 'description' => $config->get('description'), 'access' => $config->get('access'), 'default' => $config->get('default'), 'option' => $config->get('option'), 'multiple' => $config->get('multiple'))); $list = $configModel->getGroup('cart.field'); $list[JBCart::DEFAULT_POSITION][$orderElement->identifier] = (array) $orderElement->config; $configModel->setGroup('cart.field', $list); $renderElement = array('user_field' => '', 'showlabel' => '0', 'altlabel' => $renderParam->get('altlabel'), 'required' => $renderParam->get('required', 0), 'type' => $orderElement->getElementType(), 'group' => $orderElement->getElementGroup(), 'identifier' => $orderElement->identifier); $list = $configModel->getGroup('cart.field_tmpl.default'); $list[JBCart::DEFAULT_POSITION][] = $renderElement; $configModel->setGroup('cart.field_tmpl.default', $list); } } }
/** * Filter action */ function index() { $this->formRenderer = $this->app->jbrenderer->create('Order'); $this->shippingRenderer = $this->app->jbrenderer->create('Shipping'); $this->paymentRenderer = $this->app->jbrenderer->create('Payment'); $this->validatorRenderer = $this->app->jbrenderer->create('Validator'); $this->shippingFieldRenderer = $this->app->jbrenderer->create('ShippingFields'); $this->modifierOrderPriceRenderer = $this->app->jbrenderer->create('ModifierOrderPrice'); $this->shipping = $this->app->jbshipping->getEnabled(); $this->shippingFields = $this->app->jbshipping->getFields(); $this->payment = $this->app->jbpayment->getEnabled(); $this->modifierPrice = $this->app->jbmodifierprice->getEnabled(); $this->config = $this->_config; $this->Itemid = $this->_jbrequest->get('Itemid'); $this->order = $this->cart->newOrder(); $this->items = $this->order->getItems(true); $this->itemsHtml = $this->order->renderItems(array('image_width' => $this->_config->get('tmpl_image_width', 75), 'image_height' => $this->_config->get('tmpl_image_height', 75), 'image_link' => $this->_config->get('tmpl_image_link', 1), 'item_link' => $this->_config->get('tmpl_item_link', 1), 'edit' => true)); $jbnotify = $this->app->jbnotify; $errors = 0; $orderSaved = false; $isPaymentBtn = $this->app->jbrequest->get('create-pay'); if ($this->_jbrequest->isPost()) { $formData = $this->_getRequest(); try { $errors += $this->order->bind($formData); $errorMessages = $this->order->isValid(); $errors += count($errorMessages); if ($errors) { $this->app->system->application->setUserState('JBZOO_ORDDER_SUBMISSION_FORM', serialize($formData)); // show custom error messages $jbnotify->warning('JBZOO_CART_ORDER_SOME_ERROR'); $jbnotify->warning($errorMessages); } else { // saving order JBModelOrder::model()->save($this->order); $orderSaved = true; // empty cart items $this->cart->removeItems(); // go to payment page $payment = $this->order->getPayment(); $totalSum = $this->order->getTotalSum(); if ($totalSum->isPositive() && $isPaymentBtn && $payment && ($paymentUrl = $payment->getRedirectUrl())) { $message = $payment->getSuccessMessage(); if (empty($message)) { $message = 'JBZOO_CART_PAYMENT_REDIRECT'; } $this->setRedirect($paymentUrl, JText::_($message)); } else { $jbnotify->notice('JBZOO_CART_ORDER_SUCCESS_CREATED'); } } } catch (JBCartOrderException $e) { $jbnotify->warning(JText::_($e->getMessage())); } catch (AppException $e) { $jbnotify->warning(JText::_($e->getMessage())); } } $this->isError = $errors; $templatedName = 'basket'; if ($orderSaved) { $templatedName = 'basket-success'; } $this->getView($templatedName)->addTemplatePath($this->template->getPath())->setLayout($templatedName)->display(); }
/** * @return \JBModelConfig */ protected function _setupConfigure() { $configModel = \JBModelConfig::model(); $configModel->setGroup('config.yml', array('site_url' => rtrim(\JUri::root(), '/'), 'file_path' => $this->_getFilePath(), 'file_name' => $this->_getProfFileName(), 'site_name' => $this->_config->find('params.site_name', 'My site name'), 'company_name' => $this->_config->find('params.company_name', 'My company name'), 'currency_rate' => $this->_config->find('params.currency_rate', 'default'))); $configModel->set('app_list', $this->_config->find('params.app_list', array(1))); $configModel->set('type_list', $this->_config->find('params.type_list', array('product'))); return $configModel; }