Exemple #1
0
 /**
  * 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)
 {
     Citruscart::load('CitruscartArticle', 'library.article');
     $articles = array();
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     $model = JModelLegacy::getInstance('OrderItems', 'CitruscartModel');
     $model->setState('filter_orderid', $order_id);
     $orderitems = $model->getList();
     foreach ($orderitems as $item) {
         if (!empty($item->product_article)) {
             $articles[] = CitruscartArticle::display($item->product_article);
         }
     }
     $dispatcher = JDispatcher::getInstance();
     JFactory::getApplication()->triggerEvent('onGetOrderArticles', array($order_id, &$articles));
     return $articles;
 }
 /**
  * Displays a single product
  * (non-PHPdoc)
  * @see Citruscart/site/CitruscartController#view()
  */
 function view()
 {
     $input = JFactory::getApplication()->input;
     $input->set('view', $this->get('suffix'));
     $model = $this->getModel($this->get('suffix'));
     $model->getId();
     Citruscart::load('CitruscartHelperUser', 'helpers.user');
     $user_id = JFactory::getUser()->id;
     $filter_group = CitruscartHelperUser::getUserGroup($user_id);
     $model->setState('filter_group', $filter_group);
     $row = $model->getItem(false);
     // use the state
     $filter_category = $model->getState('filter_category', $input->get('filter_category'));
     if (empty($filter_category)) {
         $categories = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getCategories($row->product_id);
         if (!empty($categories)) {
             $filter_category = $categories[0];
         }
     }
     if (empty($row->product_enabled)) {
         $redirect = "index.php?option=com_citruscart&view=products&task=display&filter_category=" . $filter_category;
         $redirect = JRoute::_($redirect, false);
         $this->message = JText::_('COM_CITRUSCART_CANNOT_VIEW_DISABLED_PRODUCT');
         $this->messagetype = 'notice';
         $this->setRedirect($redirect, $this->message, $this->messagetype);
         return;
     }
     Citruscart::load('CitruscartArticle', 'library.article');
     $product_description = CitruscartArticle::fromString($row->product_description);
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     $cmodel = JModelLegacy::getInstance('Categories', 'CitruscartModel');
     $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 = $input->getInt('Itemid', Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($filter_category, true));
     $items = Citruscart::getClass("CitruscartHelperCategory", 'helpers.category')->getPathName($filter_category, 'array');
     if (!empty($items)) {
         // add the categories to the pathway
         Citruscart::getClass("CitruscartHelperPathway", '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 = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getProductQuantities($row->product_id);
         if (!Citruscart::getInstance()->get('display_out_of_stock') && empty($inventoryList)) {
             // redirect
             $redirect = "index.php?option=com_citruscart&view=products&task=display&filter_category=" . $filter_category;
             $redirect = JRoute::_($redirect, false);
             $this->message = JText::_('COM_CITRUSCART_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 = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getLayout($row->product_id, array('category_id' => $cat->category_id));
     $view->setLayout($layout);
     ob_start();
     JFactory::getApplication()->triggerEvent('onDisplayProductAttributeOptions', array($row->product_id));
     $view->assign('onDisplayProductAttributeOptions', ob_get_contents());
     ob_end_clean();
     ob_start();
     JFactory::getApplication()->triggerEvent('onBeforeDisplayProduct', array($row->product_id));
     $view->assign('onBeforeDisplayProduct', ob_get_contents());
     ob_end_clean();
     ob_start();
     JFactory::getApplication()->triggerEvent('onAfterDisplayProduct', array($row->product_id));
     $view->assign('onAfterDisplayProduct', ob_get_contents());
     ob_end_clean();
     $view->display();
     $this->footer();
     return;
 }
Exemple #3
0
 /**
  * Displays a single product
  * (non-PHPdoc)
  * @see Citruscart/site/CitruscartController#view()
  */
 function view()
 {
     $session = JFactory::getSession();
     $app = JFactory::getApplication();
     $input = JFactory::getApplication()->input;
     $this->display_cartbutton = true;
     $input->set('view', $this->get('suffix'));
     $model = $this->getModel($this->get('suffix'));
     $model->getId();
     Citruscart::load('CitruscartHelperUser', 'helpers.user');
     $user_id = JFactory::getUser()->id;
     $filter_group = CitruscartHelperUser::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', $input->getString('filter_category'));
     if (empty($filter_category)) {
         $categories = Citruscart::getClass('CitruscartHelperProduct', '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_citruscart&view=products&task=display&filter_category=" . $filter_category;
         $redirect = JRoute::_($redirect, false);
         $this->message = JText::_('COM_CITRUSCART_CANNOT_VIEW_DISABLED_PRODUCT');
         $this->messagetype = 'notice';
         $this->setRedirect($redirect, $this->message, $this->messagetype);
         return;
     }
     Citruscart::load('CitruscartArticle', 'library.article');
     $product_description = CitruscartArticle::fromString($row->product_description);
     $product_description_short = CitruscartArticle::fromString($row->product_description_short);
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     $cmodel = JModelLegacy::getInstance('Categories', 'CitruscartModel');
     $cat = $cmodel->getTable();
     $cat->load($filter_category);
     // if product browsing enabled on detail pages, get surrounding items based on browsing state
     $ns = $app->getName() . '::' . 'com.citruscart.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
     $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 = $input->getInt('Itemid', Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($filter_category, true));
     if (!($product_itemid = $this->router->findItemid(array('view' => 'products', 'task' => 'view', 'id' => $row->product_id)))) {
         $items = Citruscart::getClass("CitruscartHelperCategory", 'helpers.category')->getPathName($filter_category, 'array');
         if (!empty($items)) {
             // add the categories to the pathway
             Citruscart::getClass("CitruscartHelperPathway", '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 = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getProductQuantities($row->product_id);
         if (!Citruscart::getInstance()->get('display_out_of_stock') && empty($inventoryList)) {
             // redirect
             $redirect = "index.php?option=com_citruscart&view=products&task=display&filter_category=" . $filter_category;
             $redirect = JRoute::_($redirect, false);
             $this->message = JText::_('COM_CITRUSCART_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->product_description_short = $product_description_short;
     $view->setModel($model, true);
     // we know the product, set the meta info
     $doc = JFactory::getDocument();
     $doc->setTitle(str_replace(array("&apos;", "&amp;"), 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(Citruscart::getPath('products_templates'));
     // but add back the template overrides folder to give it priority
     $template_overrides = JPATH_BASE . '/templates/' . $app->getTemplate() . '/html/com_citruscart/' . $view->getName();
     $view->addTemplatePath($template_overrides);
     // using a helper file, we determine the product's layout
     $layout = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getLayout($row->product_id, array('category_id' => $cat->category_id));
     $view->setLayout($layout);
     JPluginHelper::importPlugin('citruscart');
     ob_start();
     $app->triggerEvent('onBeforeDisplayProduct', array($row->product_id));
     $view->assign('onBeforeDisplayProduct', ob_get_contents());
     ob_end_clean();
     ob_start();
     $app->triggerEvent('onBeforeDisplayProductDescription', array());
     $view->assign('onBeforeDisplayProductDescription', ob_get_contents());
     ob_end_clean();
     ob_start();
     $app->triggerEvent('onAfterDisplayProduct', array($row->product_id));
     $view->assign('onAfterDisplayProduct', ob_get_contents());
     ob_end_clean();
     ob_start();
     $html = $app->triggerEvent('onAfterDisplayProductDescription', array());
     $view->assign('onAfterDisplayProductDescription', $html[0]);
     ob_end_clean();
     $view->display();
     $this->footer();
     return;
 }
 /**
  * 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
     Citruscart::load('CitruscartModelProducts', 'models.products');
     $model = JModelLegacy::getInstance('Products', 'CitruscartModel');
     $model->setId((int) $params['id']);
     $row = $model->getItem();
     // Error?
     if (!$row) {
         return;
     }
     $categories = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getCategories($row->product_id);
     if (!empty($categories)) {
         $filter_category = $categories[0];
     }
     if (empty($row->product_enabled)) {
         return;
     }
     Citruscart::load('CitruscartArticle', 'library.article');
     $product_description = CitruscartArticle::fromString($row->product_description);
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models');
     $cmodel = Citruscart::getClass('CitruscartModelCategories', '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 = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getProductQuantities($row->product_id);
         if (!Citruscart::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';
         }
     }
     ob_start();
     JFactory::getApplication()->triggerEvent('onBeforeDisplayProduct', array($row->product_id));
     $onBeforeDisplayProduct = ob_get_contents();
     ob_end_clean();
     ob_start();
     JFactory::getApplication()->triggerEvent('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 = Citruscart::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 CitruscartHelperUser::getGeoZone -- that's why this isn't working
             Citruscart::load('CitruscartHelperUser', 'helpers.user');
             $geozones = CitruscartHelperUser::getGeoZones(JFactory::getUser()->id);
             if (empty($geozones)) {
                 // use the default
                 $table = JTable::getInstance('Geozones', 'CitruscartTable');
                 $table->load(array('geozone_id' => Citruscart::getInstance()->get('default_tax_geozone')));
                 $geozones = array($table);
             }
             $taxtotal = CitruscartHelperProduct::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;
     }
 }