Esempio n. 1
0
 /**
  * Sets up the JavsScript cart
  *
  * Searches all $themesPages elements for the first occurrence of the
  * "shopJsCart" template block.
  * Generates the structure of the Javascript cart, puts it in the template,
  * and registers all required JS code.
  * Note that this is only ever called when the JS cart is enabled in the
  * extended settings!
  * @access  public
  * @global  array   $_ARRAYLANG   Language array
  * @global  array   $themesPages  Theme template array
  * @return  void
  * @static
  */
 static function setJsCart()
 {
     global $_ARRAYLANG, $themesPages;
     if (!\Cx\Core\Setting\Controller\Setting::getValue('use_js_cart', 'Shop')) {
         return;
     }
     $objTemplate = new \Cx\Core\Html\Sigma('.');
     $objTemplate->setErrorHandling(PEAR_ERROR_DIE);
     $match = null;
     $div_cart = $div_product = '';
     foreach ($themesPages as $index => $content) {
         //\DBG::log("Shop::setJsCart(): Section $index");
         $objTemplate->setTemplate($content, false, false);
         if (!$objTemplate->blockExists('shopJsCart')) {
             continue;
         }
         //\DBG::log("Shop::setJsCart(): In themespage $index: {$themesPages[$index]}");
         $objTemplate->setCurrentBlock('shopJsCart');
         // Set all language entries and replace formats
         $objTemplate->setGlobalVariable($_ARRAYLANG);
         if ($objTemplate->blockExists('shopJsCartProducts')) {
             $objTemplate->parse('shopJsCartProducts');
             $div_product = $objTemplate->get('shopJsCartProducts');
             //\DBG::log("Shop::setJsCart(): Got Product: $div_product");
             $objTemplate->replaceBlock('shopJsCartProducts', '[[SHOP_JS_CART_PRODUCTS]]');
         }
         $objTemplate->touchBlock('shopJsCart');
         $objTemplate->parse('shopJsCart');
         $div_cart = $objTemplate->get('shopJsCart');
         //\DBG::log("Shop::setJsCart(): Got Cart: $div_cart");
         if (preg_match('#^([\\n\\r]?[^<]*<.*id=["\']shopJsCart["\'][^>]*>)(([\\n\\r].*)*)(</[^>]*>[^<]*[\\n\\r]?)$#', $div_cart, $match)) {
             //\DBG::log("Shop::setJsCart(): Matched DIV {$match[1]}, content: {$match[2]}");
             $themesPages[$index] = preg_replace('@(<!--\\s*BEGIN\\s+(shopJsCart)\\s*-->.*?<!--\\s*END\\s+\\2\\s*-->)@s', $match[1] . $_ARRAYLANG['TXT_SHOP_CART_IS_LOADING'] . $match[4], $content);
             /*
             // Template use won't work, because it kills the remaining <!-- blocks -->!
                             $objTemplate->setTemplate($content, false, false);
                             $objTemplate->replaceBlock('shopJsCart',
                                 $match[1].
                                 $_ARRAYLANG['TXT_SHOP_CART_IS_LOADING'].
                                 $match[4]);
                             $themesPages[$index] = $objTemplate->get();
             */
             //\DBG::log("Shop::setJsCart(): Out themespage $index: {$themesPages[$index]}");
         }
         // One instance only (mind that there's a unique id attribute)
         self::$use_js_cart = true;
         break;
     }
     if (!self::$use_js_cart) {
         return;
     }
     self::registerJavascriptCode();
     \ContrexxJavascript::getInstance()->setVariable('TXT_SHOP_CART_IS_LOADING', $_ARRAYLANG['TXT_SHOP_CART_IS_LOADING'], 'shop/cart');
     \ContrexxJavascript::getInstance()->setVariable('TXT_SHOP_COULD_NOT_LOAD_CART', $_ARRAYLANG['TXT_SHOP_COULD_NOT_LOAD_CART'], 'shop/cart');
     \ContrexxJavascript::getInstance()->setVariable('TXT_EMPTY_SHOPPING_CART', $_ARRAYLANG['TXT_EMPTY_SHOPPING_CART'], 'shop/cart');
     \ContrexxJavascript::getInstance()->setVariable("url", (string) \Cx\Core\Routing\URL::fromModuleAndCMd('Shop' . MODULE_INDEX, 'cart', FRONTEND_LANG_ID, array('remoteJs' => 'addProduct')), 'shop/cart');
     \JS::registerJS(substr(\Cx\Core\Core\Controller\Cx::instanciate()->getModuleFolderName() . '/Shop/View/Script/cart.js', 1));
     \JS::registerCode("cartTpl = '" . preg_replace(array('/\'/', '/[\\n\\r]/', '/\\//'), array('\\\'', '\\n', '\\/'), $div_cart) . "';\n" . "cartProductsTpl = '" . preg_replace(array('/\'/', '/[\\n\\r]/', '/\\//'), array('\\\'', '\\n', '\\/'), $div_product) . "';\n");
 }