public function get_view() { $controller = F0FController::getTmpInstance('com_j2store', 'products', $this->get_view_config()); $view = $controller->getView('product', 'html'); return $view; }
/** * Method to list of variants * based on the ajax request */ public function getVariantListAjax() { $app = JFactory::getApplication(); $params = J2Store::config(); $json = array(); $product_id = $app->input->get('product_id'); $global_config = JFactory::getConfig(); $limit = $global_config->get('list_limit', 20); if (!empty($product_id)) { $limitstart = $app->input->get('limitstart'); $model = $this->getThisModel(); $model->setId($product_id); $item = $model->runMyBehaviorFlag(true)->getItem(); $variantModel = F0FModel::getTmpInstance('Variants', 'J2StoreModel'); $variantModel->setState('product_type', $item->product_type); $variant_list = $variantModel->product_id($product_id)->limit($limit)->limitstart($limitstart)->is_master(0)->getList(); $variant_pagination = $variantModel->getPagination(); $lengths = $variantModel->getDimesions('lengths', 'j2store_length_id', 'length_title'); $weights = $variantModel->getDimesions('weights', 'j2store_weight_id', 'weight_title'); $controller = F0FController::getTmpInstance('com_j2store', 'Products'); $view = $controller->getView('Product', 'Html', 'J2StoreView'); if ($model = $controller->getModel('Products', 'J2StoreModel')) { // Push the model into the view (as default) $view->setModel($model, true); } $view->assign('product', $item); $view->assign('weights', $weights); $view->assign('lengths', $lengths); $view->assign('variant_list', $variant_list); $view->assign('params', $params); $view->assign('form_prefix', 'jform[attribs][j2store]'); $view->assign('variant_pagination', $variant_pagination); $view->setLayout('form_ajax_avoptions'); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); $json['html'] = $html; } echo json_encode($json); $app->close(); }
/** * The main code of the Dispatcher. It spawns the necessary controller and * runs it. * * @throws Exception * * @return void|Exception */ public function dispatch() { $platform = F0FPlatform::getInstance(); if (!$platform->authorizeAdmin($this->input->getCmd('option', 'com_foobar'))) { return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } $this->transparentAuthentication(); // Merge English and local translations $platform->loadTranslations($this->component); $canDispatch = true; if ($platform->isCli()) { $canDispatch = $canDispatch && $this->onBeforeDispatchCLI(); } $canDispatch = $canDispatch && $this->onBeforeDispatch(); if (!$canDispatch) { // We can set header only if we're not in CLI if (!$platform->isCli()) { $platform->setHeader('Status', '403 Forbidden', true); } return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } // Get and execute the controller $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->input->getCmd('view', $this->defaultView); $task = $this->input->getCmd('task', null); if (empty($task)) { $task = $this->getTask($view); } // Pluralise/sungularise the view name for typical tasks if (in_array($task, array('edit', 'add', 'read'))) { $view = F0FInflector::singularize($view); } elseif (in_array($task, array('browse'))) { $view = F0FInflector::pluralize($view); } $this->input->set('view', $view); $this->input->set('task', $task); $config = $this->config; $config['input'] = $this->input; $controller = F0FController::getTmpInstance($option, $view, $config); $status = $controller->execute($task); if (!$this->onAfterDispatch()) { // We can set header only if we're not in CLI if (!$platform->isCli()) { $platform->setHeader('Status', '403 Forbidden', true); } return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } $format = $this->input->get('format', 'html', 'cmd'); $format = empty($format) ? 'html' : $format; if ($controller->hasRedirect()) { $controller->redirect(); } }
public function onUpdateProduct(&$model, &$product) { $app = JFactory::getApplication(); $params = J2Store::config(); $product_helper = J2Store::product(); $product_id = $app->input->getInt('product_id', 0); if (!$product_id) { return false; } // 1. fetch parent options (select box) and set default selected value $po_id = $app->input->getInt('po_id', 0); // echo $po_id;exit; $pov_id = $app->input->getInt('pov_id', 0); $html = ''; if ($po_id && $pov_id) { // ~ now get the children for the above two $attributes = array(); $a = array(); // 2. fetch the children $db = JFactory::getDBO(); $query = $db->getQuery(true)->select('j2store_productoption_id, option_id')->from('#__j2store_product_options')->where('j2store_productoption_id IN (' . $po_id . ')'); $db->setQuery($query); $parent_id = $db->loadObjectList('j2store_productoption_id'); $a = array(); $child_opts = ''; if ($pov_id) { $child_opts = $product_helper->getChildProductOptions($product_id, $parent_id[$po_id]->option_id, $pov_id); } if (!empty($child_opts)) { $options = array(); foreach ($child_opts as $index => $attr) { if (count($attr['optionvalue']) > 0) { array_push($options, $attr); } } $product->options = $options; $controller = F0FController::getTmpInstance('com_j2store', 'Products'); $view = $controller->getView('Product', 'Html', 'J2StoreView'); if ($model = $controller->getModel('Products', 'J2StoreModel')) { // Push the model into the view (as default) $view->setModel($model, true); } $model->setState('task', 'read'); $view->assign('product', $product); $view->assign('params', $params); $view->setLayout('item_configurableoptions'); ob_start(); $view->display(); $html = ob_get_contents(); ob_end_clean(); } } // get variant $variants = F0FModel::getTmpInstance('Variants', 'J2StoreModel')->product_id($product->j2store_product_id)->is_master(1)->getList(); $product->variants = $variants[0]; // process variant $product->variant = $product->variants; // get quantity restrictions $product_helper->getQuantityRestriction($product->variant); // now process the quantity $product->quantity = $app->input->getFloat('product_qty', 1); if ($product->variant->quantity_restriction && $product->variant->min_sale_qty > 0) { $product->quantity = $product->variant->min_sale_qty; } // process pricing. returns an object $pricing = $product_helper->getPrice($product->variant, $product->quantity); $parent_product_options = $app->input->get('product_option', array(), 'ARRAY'); // get the selected option price if (count($parent_product_options)) { $product_option_data = $product_helper->getOptionPrice($parent_product_options, $product->j2store_product_id); $base_price = $pricing->base_price + $product_option_data['option_price']; $price = $pricing->price + $product_option_data['option_price']; } else { $base_price = $pricing->base_price; $price = $pricing->price; } $return = array(); $return['pricing'] = array(); $return['pricing']['base_price'] = J2Store::product()->displayPrice($base_price, $product, $params); $return['pricing']['price'] = J2Store::product()->displayPrice($price, $product, $params); $return['optionhtml'] = $html; return $return; }