Back to PhocacartRenderMedia class

Method __construct

public
__construct
(mixed $name = 'main')

Method __construct - Source code

public function __construct($name = 'main')
{
    $this->name = $name;
    $app = Factory::getApplication();
    $this->wa = $app->getDocument()->getWebAssetManager();
    //$params = $app->getParams();// We call media from modules too
    $params = PhocacartUtils::getComponentParameters();
    $this->p['load_bootstrap'] = $params->get('load_bootstrap', 1);
    $this->p['load_chosen'] = $params->get('load_chosen', 0);
    $this->p['load_main_css'] = $params->get('load_main_css', 1);
    $this->p['load_spec_css'] = $params->get('load_spec_css', '');
    $this->p['load_rtl_css'] = $params->get('load_rtl_css', 0);
    $this->p['equal_height'] = $params->get('equal_height', 1);
    $this->p['display_compare'] = $params->get('display_compare', 0);
    $this->p['display_wishlist'] = $params->get('display_wishlist', 0);
    $this->p['display_quickview'] = $params->get('display_quickview', 0);
    $this->p['display_addtocart_icon'] = $params->get('display_addtocart_icon', 0);
    $this->p['fade_in_action_icons'] = $params->get('fade_in_action_icons', 0);
    $this->p['dynamic_change_image'] = $params->get('dynamic_change_image', 0);
    $this->p['dynamic_change_price'] = $params->get('dynamic_change_price', 0);
    $this->p['dynamic_change_stock'] = $params->get('dynamic_change_stock', 0);
    $this->p['dynamic_change_id'] = $params->get('dynamic_change_id', 0);
    $this->p['dynamic_change_url_attributes'] = $params->get('dynamic_change_url_attributes', 0);
    $this->p['quantity_input_spinner'] = $params->get('quantity_input_spinner', 0);
    $this->p['icon_type'] = $params->get('icon_type', 'bs');
    $this->p['ajax_pagination_category'] = $params->get('ajax_pagination_category', 0);
    $this->p['ajax_searching_filtering_items'] = $params->get('ajax_searching_filtering_items', 0);
    $this->p['theme'] = $params->get('theme', 'bs5');
    $this->p['pos_focus_input_fields'] = $params->get('pos_focus_input_fields', 0);
    $this->p['pos_filter_category'] = $params->get('pos_filter_category', 1);
    // reload equal height
    $this->p['lazy_load_category_items'] = $params->get('lazy_load_category_items', 0);
    $this->p['lazy_load_categories'] = $params->get('lazy_load_categories', 0);
    $this->p['pos_server_print'] = $params->get('pos_server_print', 0);
    $this->p['load_min_js'] = $params->get('load_min_js', 1);
    $this->t['min'] = $this->p['load_min_js'] == 0 ? '' : '.min';
    $this->format = $app->input->get('format', '', 'string');
    $this->view = $app->input->get('view', '', 'string');
    $this->document = Factory::getDocument();
    if ($this->format == 'raw' || $this->format == 'json') {
        $this->load == false;
    }
    $this->scriptAtribute = array('defer' => true, 'async' => true);
    $this->scriptAtributeInline = array();
    $this->document = Factory::getDocument();
    $uri = Uri::getInstance();
    $action = $uri->toString();
    // =================
    // Render Page
    // =================
    $oVars = array();
    $oLang = array();
    $oParams = array();
    $oLang = array('COM_PHOCACART_CLOSE' => Text::_('COM_PHOCACART_CLOSE'), 'COM_PHOCACART_ERROR_TITLE_NOT_SET' => Text::_('COM_PHOCACART_ERROR_TITLE_NOT_SET'));
    $oVars['renderPageUrl'] = $action;
    $oVars['token'] = Session::getFormToken();
    $oVars['basePath'] = Uri::base(true);
    if ($this->view == 'category' || $this->view == 'items' || $this->view == 'pos') {
        if ($this->view == 'pos') {
            $oVars['renderPageOutput'] = 'phPosContentBox';
        } else {
            $oVars['renderPageOutput'] = 'phItemsBox';
        }
    }
    $oVars['isPOS'] = (int) PhocacartUtils::isView('pos');
    $oParams['loadChosen'] = (int) $this->p['load_chosen'];
    $oParams['ajaxPaginationCategory'] = (int) $this->p['ajax_pagination_category'];
    $oParams['ajaxSearchingFilteringItems'] = (int) $this->p['ajax_searching_filtering_items'];
    $oParams['theme'] = $this->p['theme'];
    if ($oVars['isPOS']) {
        $oParams['theme'] = 'bs5';
        // media\com_phocacart\js\phoca\jquery.phocaattribute.js line 319
    }
    $oVars['view'] = $this->view;
    // Change Attribute data
    $oVars['urlCheckoutChangeData'] = Uri::base(true) . '/index.php?option=com_phocacart&task=checkout.changedatabox&format=json&' . Session::getFormToken() . '=1';
    /*
             * typeview
             * if($oVars['isPOS']) {
                // We need to identify POS in AJAX URL Request (when using common controller like checkout, checkout controller is used in POS too)
                // For example: displaying group price depends on logged in user
                // Logged in user in online shop is logged in user
                // Logged in user in POS is vendor, not logged in user so in POS displaying the group price is different
                // Displaying interactive price does not have any effect on real price in checkout
                $oVars['urlCheckoutChangeData'] = Uri::base(true) . '/index.php?option=com_phocacart&task=checkout.changedatabox&format=json&' . Session::getFormToken() . '=1';
            }*/
    $oParams['dynamicChangePrice'] = (int) $this->p['dynamic_change_price'];
    $oParams['dynamicChangeStock'] = (int) $this->p['dynamic_change_stock'];
    $oParams['dynamicChangeId'] = (int) $this->p['dynamic_change_id'];
    $oParams['dynamicChangeImage'] = (int) $this->p['dynamic_change_image'];
    $oParams['dynamicChangeUrlAttributes'] = (int) $this->p['dynamic_change_url_attributes'];
    HTMLHelper::_('jquery.framework', false);
    if ($this->p['theme'] != 'uikit') {
        $this->wa->useScript('bootstrap.modal');
    }
    //$this->document->addScript(JUri::root(true).'/media/com_phocacart/js/phoca/phocacart'.$this->t['min'].'.js');
    //$this->document->addScript(JUri::root(true).'/media/com_phocacart/js/phoca/phocarequest'.$this->t['min'].'.js');
    //$this->document->addScript(JUri::root(true).'/media/com_phocacart/js/filter/jquery.ba-bbq.min.js');
    //HTMLHelper::_('script', 'media/com_phocacart/js/phoca/phocacart' . $this->t['min'] . '.js', array('version' => 'auto'), $this->scriptAtributeInline);
    //HTMLHelper::_('script', 'media/com_phocacart/js/phoca/phocarequest' . $this->t['min'] . '.js', array('version' => 'auto'), $this->scriptAtributeInline);
    // HTMLHelper::_('script', 'media/com_phocacart/js/filter/jquery.ba-bbq.min.js', array('version' => 'auto'), $this->scriptAtributeInline);
    $this->wa->registerAndUseScript('com_phocacart.phocacart', 'media/com_phocacart/js/phoca/phocacart' . $this->t['min'] . '.js', array('version' => 'auto'), $this->scriptAtributeInline);
    $this->wa->registerAndUseScript('com_phocacart.phocacartrequest', 'media/com_phocacart/js/phoca/phocarequest' . $this->t['min'] . '.js', array('version' => 'auto'), $this->scriptAtributeInline);
    $this->wa->registerAndUseScript('com_phocacart.ba-bbq', 'media/com_phocacart/js/filter/jquery.ba-bbq.min.js', array('version' => 'auto'), $this->scriptAtributeInline);
    // phocacartfilter.js can work without loaded jquery-ui.slder.min.js - it tests if the function exist - no error
    // if set in phoca cart filter moduler - the slider range can be displayed in filter module
    // in such case the following libraries are loaded:
    // $this->document->addScript(JUri::root(true) . '/media/com_phocacart/js/ui/jquery-ui.slider.min.js');
    // JHtml::stylesheet('media/com_phocacart/js/ui/jquery-ui.slider.min.css');
    // if there will be problem when loading the libraries, possible solution is to get module parameters here
    // and load before phocafilter.js library
    /*
    $module			= ModuleHelper::getModule('mod_phocacart_filter');
    $paramsM		= new Registry($module->params);
    $filter_price	= $paramsM->get( 'filter_price', 1 );
    if ($filter_price == 2 || $filter_price == 3) {
        $this->document->addScript(Uri::root(true) . '/media/com_phocacart/js/ui/jquery-ui.slider.min.js');
         HTMLHelper::stylesheet('media/com_phocacart/js/ui/jquery-ui.slider.min.css');
    }
    */
    // Are filter and search modules enabled - needed because of phocacart.js
    $modPhocaCartFilter = ModuleHelper::getModule('mod_phocacart_filter');
    // Get info if modules are enabled and installed
    $modPhocaCartSearch = ModuleHelper::getModule('mod_phocacart_search');
    $oVars['mod_phocacart_filter'] = 1;
    if (!$modPhocaCartFilter || isset($modPhocaCartFilter->id) && (int) $modPhocaCartFilter->id < 1) {
        $oVars['mod_phocacart_filter'] = 0;
    }
    $oVars['mod_phocacart_search'] = 1;
    if (!$modPhocaCartSearch || isset($modPhocaCartSearch->id) && (int) $modPhocaCartSearch->id < 1) {
        $oVars['mod_phocacart_search'] = 0;
    }
    $currency = PhocacartCurrency::getCurrency();
    PhocacartRenderJs::getPriceFormatJavascript($currency->price_decimals, $currency->price_dec_symbol, $currency->price_thousands_sep, $currency->price_currency_symbol, $currency->price_prefix, $currency->price_suffix, $currency->price_format);
    // $this->document->addScript(JUri::root(true).'/media/com_phocacart/js/phoca/phocafilter'.$this->t['min'].'.js');
    //HTMLHelper::_('script', 'media/com_phocacart/js/phoca/phocafilter' . $this->t['min'] . '.js', array('version' => 'auto'), $this->scriptAtributeInline);
    $this->wa->registerAndUseScript('com_phocacart.phocafilter', 'media/com_phocacart/js/phoca/phocafilter' . $this->t['min'] . '.js', array('version' => 'auto'), $this->scriptAtributeInline);
    if ($this->view == 'pos') {
        $oLang['COM_PHOCACART_WARNING_BOOTSTRAP_JS_LOADED_MORE_THAN_ONCE'] = Text::_('COM_PHOCACART_WARNING_BOOTSTRAP_JS_LOADED_MORE_THAN_ONCE');
        $oLang['COM_PHOCACART_OK'] = Text::_('COM_PHOCACART_OK');
        $oLang['COM_PHOCACART_CANCEL'] = Text::_('COM_PHOCACART_CANCEL');
        $oParams['posFocusInputFields'] = (int) $this->p['pos_focus_input_fields'];
        $oParams['posFilterCategory'] = (int) $this->p['pos_filter_category'];
        $oParams['posServerPrint'] = (int) $this->p['pos_server_print'];
        $oVars['urlOrder'] = Route::_('index.php?option=com_phocacart&view=order&tmpl=component&format=raw');
        //$this->document->addScript(JUri::root(true).'/media/com_phocacart/js/base64/base64'.$this->t['min'].'.js');
        //$this->document->addScript(JUri::root(true).'/media/com_phocacart/js/phoca/phocapos'.$this->t['min'].'.js');
        //HTMLHelper::_('script', 'media/com_phocacart/js/base64/base64' . $this->t['min'] . '.js', array('version' => 'auto'), $this->scriptAtribute);
        // HTMLHelper::_('script', 'media/com_phocacart/js/phoca/phocapos' . $this->t['min'] . '.js', array('version' => 'auto'), $this->scriptAtributeInline);
        $this->wa->registerAndUseScript('com_phocacart.base64', 'media/com_phocacart/js/base64/base64' . $this->t['min'] . '.js', array('version' => 'auto'), $this->scriptAtributeInline);
        $this->wa->registerAndUseScript('com_phocacart.phocapos', 'media/com_phocacart/js/phoca/phocapos' . $this->t['min'] . '.js', array('version' => 'auto'), $this->scriptAtributeInline);
    }
    $this->document->addScriptOptions('phLangPC', $oLang);
    $this->document->addScriptOptions('phVarsPC', $oVars);
    $this->document->addScriptOptions('phParamsPC', $oParams);
    // Bootstrap 3 Modal transition
    /*if ($this->p['theme'] == 'bs3') {
          //JHtml::stylesheet( 'media/com_phocacart/bootstrap/css/bs_modal_transition.css');
          //HTMLHelper::_('stylesheet', 'media/com_phocacart/bootstrap/css/bs_modal_transition.css', array('version' => 'auto'));
          $this->wa->registerAndUseStyle('com_phocacart.bs_modal_transition', 'media/com_phocacart/bootstrap/css/bs_modal_transition.css' . $this->t['min'] . '.js', array('version' => 'auto'));
      }*/
}