예제 #1
0
 /**
  * Sets up the Shop Navbar content and returns it as a string
  *
  * Note that {@see init()} must have been called before.
  * The content is created once and stored statically.
  * Repeated calls will always return the same string, unless either
  * a non-empty template is given, or $use_cache is set to false.
  * @global  array   $_ARRAYLANG
  * @global  array   $themesPages
  * @global  array   $_CONFIGURATION
  * @staticvar string    $strContent Caches created content
  * @param   type    $template   Replaces the default template
  *                              ($themesPages['shopnavbar']) and sets
  *                              $use_cache to false unless empty.
  *                              Defaults to NULL
  * @param   type    $use_cache  Does not use any cached content, but builds
  *                              it new from scratch if false.
  *                              Defaults to true.
  * @return  string              The Shop Navbar content
  * @static
  */
 static function getNavbar($template = NULL, $use_cache = true)
 {
     global $_ARRAYLANG, $themesPages;
     static $strContent = NULL;
     if (!$use_cache) {
         $strContent = NULL;
     }
     // Note: This is valid only as long as the content is the same every
     // time this method is called!
     if ($strContent) {
         return $strContent;
     }
     $objTpl = new \Cx\Core\Html\Sigma('.');
     $objTpl->setErrorHandling(PEAR_ERROR_DIE);
     $objTpl->setTemplate(empty($template) ? $themesPages['shopnavbar'] : $template);
     $objTpl->setGlobalVariable($_ARRAYLANG);
     $loginInfo = $loginStatus = $redirect = '';
     //\DBG::log("Shop::getNavbar(): Customer: ".(self::$objCustomer ? "Logged in" : "nada"));
     if (self::$objCustomer) {
         if (self::$objCustomer->company()) {
             $loginInfo = self::$objCustomer->company() . '<br />';
         } else {
             $loginInfo = $_ARRAYLANG['TXT_SHOP_' . strtoupper(self::$objCustomer->gender())] . ' ' . self::$objCustomer->lastname() . '<br />';
         }
         $loginStatus = $_ARRAYLANG['TXT_LOGGED_IN_AS'];
         // Show link to change the password
         if ($objTpl->blockExists('shop_changepass')) {
             $objTpl->touchBlock('shop_changepass');
         }
     } else {
         // Show login form if the customer is not logged in already.
         $loginStatus = $_ARRAYLANG['TXT_LOGGED_IN_AS_SHOP_GUEST'];
         // $redirect contains something like "section=Shop&cmd=details&productId=1"
         if (isset($_REQUEST['redirect'])) {
             $redirect = $_REQUEST['redirect'];
         } else {
             $queryString = $_SERVER['QUERY_STRING'];
             $redirect = base64_encode(preg_replace('/\\&?act\\=\\w*/', '', $queryString));
         }
         $objTpl->setVariable('SHOP_LOGIN_ACTION', \Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'login') . '?redirect=' . $redirect);
     }
     $objTpl->setVariable(array('SHOP_LOGIN_STATUS' => $loginStatus, 'SHOP_LOGIN_INFO' => $loginInfo));
     // Currencies
     if (self::$show_currency_navbar && $objTpl->blockExists('shopCurrencies')) {
         $curNavbar = Currency::getCurrencyNavbar();
         if (!empty($curNavbar)) {
             $objTpl->setVariable('SHOP_CURRENCIES', $curNavbar);
         }
     }
     if ($objTpl->blockExists('shopNavbar')) {
         $selectedCatId = 0;
         if (isset($_REQUEST['catId'])) {
             $selectedCatId = intval($_REQUEST['catId']);
             $objCategory = ShopCategory::getById($selectedCatId);
             if (!$objCategory) {
                 $selectedCatId = 0;
             }
         }
         if (empty($selectedCatId) && isset($_REQUEST['productId'])) {
             $product_id = intval($_REQUEST['productId']);
             if (isset($_REQUEST['referer']) && $_REQUEST['referer'] == 'cart') {
                 $product_id = Cart::get_product_id($product_id);
             }
             $objProduct = Product::getById($product_id);
             if ($objProduct) {
                 $selectedCatId = $objProduct->category_id();
                 $selectedCatId = preg_replace('/,.+$/', '', $selectedCatId);
             }
         }
         // If there is no distinct Category ID, use the previous one, if any
         if (is_numeric($selectedCatId)) {
             $_SESSION['shop']['previous_category_id'] = $selectedCatId;
         } else {
             if (isset($_SESSION['shop']['previous_category_id'])) {
                 $selectedCatId = $_SESSION['shop']['previous_category_id'];
             }
         }
         // Only the visible ShopCategories are present
         $arrShopCategoryTree = ShopCategories::getTreeArray(false, true, true, $selectedCatId, 0, 0);
         // The trail of IDs from root to the selected ShopCategory,
         // built along with the tree array when calling getTreeArray().
         $arrTrail = ShopCategories::getTrailArray($selectedCatId);
         // Display the ShopCategories
         foreach ($arrShopCategoryTree as $arrShopCategory) {
             $level = $arrShopCategory['level'];
             // Skip levels too deep: if ($level >= 2) { continue; }
             $id = $arrShopCategory['id'];
             $style = 'shopnavbar' . ($level + 1);
             if (in_array($id, $arrTrail)) {
                 $style .= '_active';
             }
             $objTpl->setVariable(array('SHOP_CATEGORY_STYLE' => $style, 'SHOP_CATEGORY_ID' => $id, 'SHOP_CATEGORY_NAME' => str_repeat('&nbsp;', 3 * $level) . str_replace('"', '&quot;', $arrShopCategory['name'])));
             $objTpl->parse("shopNavbar");
         }
     }
     // Only show the cart info when the JS cart is not active!
     if (!self::$use_js_cart) {
         $objTpl->setVariable(array('SHOP_CART_INFO' => self::cart_info()));
     }
     //        if ($objTpl->blockExists('shopJsCart')) {
     //            $objTpl->touchBlock('shopJsCart');
     //        }
     $strContent = $objTpl->get();
     return $strContent;
 }
예제 #2
0
 /**
  * Parse the category/product breadcrumb
  *
  * Parses the template block shopNavbar and shop_breadcrumb based on
  * the currently selected category and product.
  *
  * @param   \Cx\Core\Html\Sigma $objTpl The template object to be used to parse the breadcrumb on.
  * @param   integer $selectedCatId  The ID of the currently selected category.
  * @param   Product $product        The currently selected product.
  */
 static function parseBreadcrumb($objTpl, $selectedCatId = 0, $product = null)
 {
     // Only the visible ShopCategories are present
     $arrShopCategoryTree = ShopCategories::getTreeArray(false, true, true, $selectedCatId, 0, 0);
     // The trail of IDs from root to the selected ShopCategory,
     // built along with the tree array when calling getTreeArray().
     $arrTrail = ShopCategories::getTrailArray($selectedCatId);
     // Display the ShopCategories
     foreach ($arrShopCategoryTree as $arrShopCategory) {
         $level = $arrShopCategory['level'];
         // Skip levels too deep: if ($level >= 2) { continue; }
         $id = $arrShopCategory['id'];
         $style = 'shopnavbar' . ($level + 1);
         if (in_array($id, $arrTrail)) {
             $style .= '_active';
         }
         // parse shopNavbar
         if ($objTpl->blockExists('shopNavbar')) {
             $objTpl->setVariable(array('SHOP_CATEGORY_STYLE' => $style, 'SHOP_CATEGORY_ID' => $id, 'SHOP_CATEGORY_NAME' => str_repeat('&nbsp;', 3 * $level) . str_replace('"', '&quot;', $arrShopCategory['name'])));
             $objTpl->parse("shopNavbar");
         }
         // skip shop_breadcrumb parsing in case the required template blocks are missing
         if (!$objTpl->blockExists('shop_breadcrumb') || !$objTpl->blockExists('shop_breadcrumb_part')) {
             continue;
         }
         // skip shop_breadcrumb parsing in case the category is not part of the selected category tree
         if (!in_array($id, $arrTrail)) {
             continue;
         }
         // parse the category in shop_breadcrumb
         $objTpl->setVariable(array('SHOP_BREADCRUMB_PART_SRC' => \Cx\Core\Routing\URL::fromModuleAndCmd('Shop' . MODULE_INDEX, '', FRONTEND_LANG_ID, array('catId' => $id))->toString(), 'SHOP_BREADCRUMB_PART_TITLE' => contrexx_raw2xhtml($arrShopCategory['name'])));
         $objTpl->parse('shop_breadcrumb_part');
     }
     // skip shop_breadcrumb parsing in case the required template blocks are missing
     if (!$objTpl->blockExists('shop_breadcrumb') && !$objTpl->blockExists('shop_breadcrumb_part')) {
         return;
     }
     // parse Product in shop_breadcrumb if a product is being viewed
     if ($product) {
         $objTpl->setVariable(array('SHOP_BREADCRUMB_PART_SRC' => \Cx\Core\Routing\URL::fromModuleAndCmd('Shop' . MODULE_INDEX, '', FRONTEND_LANG_ID, array('productId' => $product->id()))->toString(), 'SHOP_BREADCRUMB_PART_TITLE' => contrexx_raw2xhtml($product->name())));
         $objTpl->parse('shop_breadcrumb_part');
     }
     // show or hide the shop_breadcrumb template block, depending on if a category
     // has been selected or a product is being viewed
     if (array_intersect(array_keys($arrShopCategoryTree), $arrTrail) || $product) {
         $objTpl->touchBlock('shop_breadcrumb');
     } else {
         $objTpl->hideBlock('shop_breadcrumb');
     }
 }