/** * Displays a single product * (non-PHPdoc) * @see tienda/site/TiendaController#view() */ function view() { JRequest::setVar('view', $this->get('suffix')); $model = $this->getModel($this->get('suffix')); $model->getId(); Tienda::load('TiendaHelperUser', 'helpers.user'); $user_id = JFactory::getUser()->id; $filter_group = TiendaHelperUser::getUserGroup($user_id); $model->setState('filter_group', $filter_group); $row = $model->getItem(false); // use the state $filter_category = $model->getState('filter_category', JRequest::getVar('filter_category')); if (empty($filter_category)) { $categories = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getCategories($row->product_id); if (!empty($categories)) { $filter_category = $categories[0]; } } if (empty($row->product_enabled)) { $redirect = "index.php?option=com_tienda&view=products&task=display&filter_category=" . $filter_category; $redirect = JRoute::_($redirect, false); $this->message = JText::_('COM_TIENDA_CANNOT_VIEW_DISABLED_PRODUCT'); $this->messagetype = 'notice'; $this->setRedirect($redirect, $this->message, $this->messagetype); return; } Tienda::load('TiendaArticle', 'library.article'); $product_description = TiendaArticle::fromString($row->product_description); JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $cmodel = JModel::getInstance('Categories', 'TiendaModel'); $cat = $cmodel->getTable(); $cat->load($filter_category); $view = $this->getView($this->get('suffix'), JFactory::getDocument()->getType()); $view->set('_doTask', true); $view->assign('row', $row); $view->assign('cat', $cat); // breadcrumb support $app = JFactory::getApplication(); $pathway = $app->getPathway(); $category_itemid = JRequest::getInt('Itemid', Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($filter_category, true)); $items = Tienda::getClass("TiendaHelperCategory", 'helpers.category')->getPathName($filter_category, 'array'); if (!empty($items)) { // add the categories to the pathway Tienda::getClass("TiendaHelperPathway", 'helpers.pathway')->insertCategories($items, $category_itemid); } // add the item being viewed to the pathway $pathway->addItem($row->product_name); // Check If the inventroy is set then it will go for the inventory product quantities if ($row->product_check_inventory) { $inventoryList = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getProductQuantities($row->product_id); if (!Tienda::getInstance()->get('display_out_of_stock') && empty($inventoryList)) { // redirect $redirect = "index.php?option=com_tienda&view=products&task=display&filter_category=" . $filter_category; $redirect = JRoute::_($redirect, false); $this->message = JText::_('COM_TIENDA_CANNOT_VIEW_PRODUCT'); $this->messagetype = 'notice'; $this->setRedirect($redirect, $this->message, $this->messagetype); return; } // if there is no entry of product in the productquantities if (count($inventoryList) == 0) { $inventoryList[''] = '0'; } $view->assign('inventoryList', $inventoryList); } $view->assign('product_comments', $this->getComments($row->product_id)); $view->assign('product_description', $product_description); $view->assign('files', $this->getFiles($row->product_id)); $view->assign('product_buy', $this->getAddToCart($row->product_id)); $view->assign('product_relations', $this->getRelationshipsHtml($row->product_id, 'relates')); $view->assign('product_children', $this->getRelationshipsHtml($row->product_id, 'parent')); $view->assign('product_requirements', $this->getRelationshipsHtml($row->product_id, 'requires')); $view->setModel($model, true); // using a helper file, we determine the product's layout $layout = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getLayout($row->product_id, array('category_id' => $cat->category_id)); $view->setLayout($layout); $dispatcher = JDispatcher::getInstance(); ob_start(); $dispatcher->trigger('onDisplayProductAttributeOptions', array($row->product_id)); $view->assign('onDisplayProductAttributeOptions', ob_get_contents()); ob_end_clean(); ob_start(); $dispatcher->trigger('onBeforeDisplayProduct', array($row->product_id)); $view->assign('onBeforeDisplayProduct', ob_get_contents()); ob_end_clean(); ob_start(); $dispatcher->trigger('onAfterDisplayProduct', array($row->product_id)); $view->assign('onAfterDisplayProduct', ob_get_contents()); ob_end_clean(); $view->display(); $this->footer(); return; }
/** * Displays a single product * (non-PHPdoc) * @see tienda/site/TiendaController#view() */ function view() { $this->display_cartbutton = true; JRequest::setVar('view', $this->get('suffix')); $model = $this->getModel($this->get('suffix')); $model->getId(); Tienda::load('TiendaHelperUser', 'helpers.user'); $user_id = JFactory::getUser()->id; $filter_group = TiendaHelperUser::getUserGroup($user_id, $model->getId()); $model->setState('filter_group', $filter_group); $model->setState('product.qty', 1); $model->setState('user.id', $user_id); $row = $model->getItem(false, false, false); // use the state $filter_category = $model->getState('filter_category', JRequest::getVar('filter_category')); if (empty($filter_category)) { $categories = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getCategories($row->product_id); if (!empty($categories)) { $filter_category = $categories[0]; } } $unpublished = false; if ($row->unpublish_date != JFactory::getDbo()->getNullDate()) { $unpublished = strtotime($row->unpublish_date) < time(); } if (!$unpublished && $row->publish_date != JFactory::getDbo()->getNullDate()) { $unpublished = strtotime($row->publish_date) > time(); } if (empty($row->product_enabled) || $unpublished) { $redirect = "index.php?option=com_tienda&view=products&task=display&filter_category=" . $filter_category; $redirect = JRoute::_($redirect, false); $this->message = JText::_('COM_TIENDA_CANNOT_VIEW_DISABLED_PRODUCT'); $this->messagetype = 'notice'; $this->setRedirect($redirect, $this->message, $this->messagetype); return; } Tienda::load('TiendaArticle', 'library.article'); $product_description = TiendaArticle::fromString($row->product_description); JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $cmodel = JModel::getInstance('Categories', 'TiendaModel'); $cat = $cmodel->getTable(); $cat->load($filter_category); // if product browsing enabled on detail pages, get surrounding items based on browsing state $session = JFactory::getSession(); $app = JFactory::getApplication(); $ns = $app->getName() . '::' . 'com.tienda.products.state'; $session_state = $session->get($ns); $surrounding = array(); // Only do this if product browsing is enabled on product detail pages if ($this->defines->get('enable_product_detail_nav') && $session_state) { $products_model = $this->getModel($this->get('suffix')); $products_model->emptyState(); foreach ((array) $session_state as $key => $value) { $products_model->setState($key, $value); } $surrounding = $products_model->getSurrounding($model->getId()); } $view = $this->getView($this->get('suffix'), JFactory::getDocument()->getType()); $view->set('_doTask', true); $view->assign('row', $row); $view->assign('surrounding', $surrounding); // breadcrumb support $app = JFactory::getApplication(); $pathway = $app->getPathway(); // does this item have its own itemid? if so, let joomla handle the breadcrumb, // otherwise, help it out a little bit $category_itemid = JRequest::getInt('Itemid', Tienda::getClass("TiendaHelperRoute", 'helpers.route')->category($filter_category, true)); if (!($product_itemid = $this->router->findItemid(array('view' => 'products', 'task' => 'view', 'id' => $row->product_id)))) { $items = Tienda::getClass("TiendaHelperCategory", 'helpers.category')->getPathName($filter_category, 'array'); if (!empty($items)) { // add the categories to the pathway Tienda::getClass("TiendaHelperPathway", 'helpers.pathway')->insertCategories($items, $category_itemid); } // add the item being viewed to the pathway $pathway->addItem($row->product_name); } $cat->itemid = $category_itemid; $view->assign('cat', $cat); // Check If the inventroy is set then it will go for the inventory product quantities if ($row->product_check_inventory) { $inventoryList = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getProductQuantities($row->product_id); if (!Tienda::getInstance()->get('display_out_of_stock') && empty($inventoryList)) { // redirect $redirect = "index.php?option=com_tienda&view=products&task=display&filter_category=" . $filter_category; $redirect = JRoute::_($redirect, false); $this->message = JText::_('COM_TIENDA_CANNOT_VIEW_PRODUCT'); $this->messagetype = 'notice'; $this->setRedirect($redirect, $this->message, $this->messagetype); return; } // if there is no entry of product in the productquantities if (count($inventoryList) == 0) { $inventoryList[''] = '0'; } $view->assign('inventoryList', $inventoryList); } $view->product_comments = $this->getComments($view, $row->product_id); $view->files = $this->getFiles($view, $row->product_id); $view->product_relations = $this->getRelationshipsHtml($view, $row->product_id, 'relates'); $view->product_children = $this->getRelationshipsHtml($view, $row->product_id, 'parent'); $view->product_requirements = $this->getRelationshipsHtml($view, $row->product_id, 'requires'); $view->product_description = $product_description; $view->setModel($model, true); // we know the product, set the meta info $doc = JFactory::getDocument(); $doc->setTitle(str_replace(array("'", "&"), array("'", "&"), htmlspecialchars_decode($row->product_name))); $doc->setDescription(htmlspecialchars_decode($product_description)); // add the media/templates folder as a valid path for templates $view->addTemplatePath(Tienda::getPath('products_templates')); // but add back the template overrides folder to give it priority $template_overrides = JPATH_BASE . '/templates/' . $app->getTemplate() . '/html/com_tienda/' . $view->getName(); $view->addTemplatePath($template_overrides); // using a helper file, we determine the product's layout $layout = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getLayout($row->product_id, array('category_id' => $cat->category_id)); $view->setLayout($layout); $dispatcher = JDispatcher::getInstance(); ob_start(); $dispatcher->trigger('onBeforeDisplayProduct', array($row->product_id)); $view->assign('onBeforeDisplayProduct', ob_get_contents()); ob_end_clean(); ob_start(); $dispatcher->trigger('onAfterDisplayProduct', array($row->product_id)); $view->assign('onAfterDisplayProduct', ob_get_contents()); ob_end_clean(); $view->display(); $this->footer(); return; }
/** * Returns an array of objects, * each containing the parsed html of all articles that should be displayed * after an order is completed, * based on the defined global article and any product-, shippingmethod-, and paymentmethod-specific articles * * @param $order_id * @return array */ function getOrderArticles($order_id) { Tienda::load('TiendaArticle', 'library.article'); $articles = array(); JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = JModel::getInstance('OrderItems', 'TiendaModel'); $model->setState('filter_orderid', $order_id); $orderitems = $model->getList(); foreach ($orderitems as $item) { if (!empty($item->product_article)) { $articles[] = TiendaArticle::display($item->product_article); } } $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onGetOrderArticles', array($order_id, &$articles)); return $articles; }
/** * Loads an individual product * and displays it * * @param $load * @return unknown_type */ private function showProduct($load) { $inline_params = explode(" ", $load); $params = $this->get('params'); $params = $params->toArray(); $params['attributes'] = array(); // Merge plugin parameters with tag parameters, overwriting wherever necessary foreach ($inline_params as $p) { $data = explode("=", $p); $k = $data[0]; $v = $data[1]; // Merge the attribute options in one subarray if (substr($k, 0, 10) == 'attribute_') { $params['attributes'][$k] = $v; } else { $params[$k] = $v; } } // No id set, return if (!array_key_exists('id', $params)) { return; } // Load Product Tienda::load('TiendaModelProducts', 'models.products'); $model = JModel::getInstance('Products', 'TiendaModel'); $model->setId((int) $params['id']); $row = $model->getItem(); // Error? if (!$row) { return; } $categories = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getCategories($row->product_id); if (!empty($categories)) { $filter_category = $categories[0]; } if (empty($row->product_enabled)) { return; } Tienda::load('TiendaArticle', 'library.article'); $product_description = TiendaArticle::fromString($row->product_description); JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $cmodel = Tienda::getClass('TiendaModelCategories', 'models.categories'); $cat = $cmodel->getTable(); $cat->load($filter_category); // Check If the inventroy is set then it will go for the inventory product quantities if ($row->product_check_inventory) { $inventoryList = Tienda::getClass('TiendaHelperProduct', 'helpers.product')->getProductQuantities($row->product_id); if (!Tienda::getInstance()->get('display_out_of_stock') && empty($inventoryList)) { return; } // if there is no entry of product in the productquantities if (count($inventoryList) == 0) { $inventoryList[''] = '0'; } } $dispatcher = JDispatcher::getInstance(); ob_start(); $dispatcher->trigger('onBeforeDisplayProduct', array($row->product_id)); $onBeforeDisplayProduct = ob_get_contents(); ob_end_clean(); ob_start(); $dispatcher->trigger('onAfterDisplayProduct', array($row->product_id)); $onAfterDisplayProduct = ob_get_contents(); ob_end_clean(); $files = $this->getFiles($row->product_id); $product_buy = $this->getAddToCart($row->product_id, $params['attributes'], $params); $product_relations = $this->getRelationshipsHtml($row->product_id, 'relates'); $product_children = $this->getRelationshipsHtml($row->product_id, 'parent'); $product_requirements = $this->getRelationshipsHtml($row->product_id, 'requires'); // In this case, we need to add some variables to show the price in the normal view if (@$params['show_price'] == '1' && @$params['show_buy'] == '0') { $vars = new JObject(); $config = Tienda::getInstance(); $show_tax = $config->get('display_prices_with_tax'); $vars->show_tax = $show_tax; $vars->tax = 0; $vars->taxtotal = ''; $vars->shipping_cost_link = ''; if ($show_tax) { // finish TiendaHelperUser::getGeoZone -- that's why this isn't working Tienda::load('TiendaHelperUser', 'helpers.user'); $geozones = TiendaHelperUser::getGeoZones(JFactory::getUser()->id); if (empty($geozones)) { // use the default $table = JTable::getInstance('Geozones', 'TiendaTable'); $table->load(array('geozone_id' => Tienda::getInstance()->get('default_tax_geozone'))); $geozones = array($table); } $taxtotal = TiendaHelperProduct::getTaxTotal($product_id, $geozones); $tax = $taxtotal->tax_total; $vars->taxtotal = $taxtotal; $vars->tax = $tax; } // TODO What about this?? $show_shipping = $config->get('display_prices_with_shipping'); if ($show_shipping) { $article_link = $config->get('article_shipping', ''); $shipping_cost_link = JRoute::_('index.php?option=com_content&view=article&id=' . $article_link); $vars->shipping_cost_link = $shipping_cost_link; } } ob_start(); $layout_file = $this->_getLayoutPath($this->_element, 'content', 'view'); include $layout_file; $return = ob_get_contents(); ob_end_clean(); switch ($params['layout']) { case 'product_buy': return $product_buy; case 'product_children': return $product_children; case 'product_files': return $product_files; case 'product_relations': return $product_relations; case 'product_requirements': return $product_requirements; case 'view': default: return $return; } }