Back to PhocacartRenderJs class

Method renderAjaxQuickViewBox

public static
renderAjaxQuickViewBox
(mixed $options = array())

Method renderAjaxQuickViewBox - Source code

public static function renderAjaxQuickViewBox($options = array())
{
    $style = PhocacartRenderStyle::getStyles();
    $paramsC = PhocacartUtils::getComponentParameters();
    $dynamic_change_price = $paramsC->get('dynamic_change_price', 1);
    $load_chosen = $paramsC->get('load_chosen', 0);
    $quantity_input_spinner = $paramsC->get('quantity_input_spinner', 0);
    // needed because of phChangeAttributeType() - is included
    //$document = JFactory::getDocument();
    //$document->addScript(JUri::root(true) . '/media/com_phocacart/js/phoca/jquery.phocaattribute.min.js');
    $media = PhocacartRenderMedia::getInstance('main');
    $media->loadPhocaAttribute(1);
    // We need to refresh comparison site when AJAX used for removing or adding products to comparison list
    $urlAjax = Uri::base(true) . '/index.php?option=com_phocacart&view=item&format=json&tmpl=component&' . Session::getFormToken() . '=1';
    $s = array();
    $s[] = 'function phItemQuickViewBoxFormAjax(phItemId) {';
    $s[] = '	var phUrl 	= "' . $urlAjax . '";';
    $s[] = '	var phItem = \'#\' + phItemId;';
    $s[] = '	var phOptions = [];';
    $s[] = '	phOptions["view"] = "";';
    $s[] = '	phOptions["method"]  = "";';
    $s[] = '	phOptions["task"]  = "";';
    $s[] = '	phOptions["type"]  = "quickview";';
    $s[] = '	phOptions["load_chosen"]  = ' . (int) $load_chosen . ';';
    $s[] = '	phOptions["quantity_input_spinner"]  = ' . (int) $quantity_input_spinner . ';';
    if ((int) $quantity_input_spinner == 2) {
        $s[] = '	phOptions["icon_spinner_verticalup"] =  \'<span class="' . $style['i']['chevron-up'] . '"></span>\';';
        $s[] = '	phOptions["icon_spinner_verticaldown"] =  \'<span class="' . $style['i']['chevron-down'] . '"></span>\';';
    } else {
        $s[] = '	phOptions["icon_spinner_verticalup"] =  \'<span class="' . $style['i']['plus'] . '"></span>\';';
        $s[] = '	phOptions["icon_spinner_verticaldown"] =  \'<span class="' . $style['i']['minus'] . '"></span>\';';
    }
    $s[] = '	var phData = jQuery(phItem).serialize();';
    $s[] = '	phDoRequestMethods(phUrl, phData, phOptions);';
    $s[] = '}';
    $s[] = ' ';
    Factory::getDocument()->addScriptDeclaration(implode("\n", $s));
    /*$s[] = '	phRequest = jQuery.ajax({';
            $s[] = '		type: "POST",';
            $s[] = '		url: phUrl,';
            $s[] = '		async: "false",';
            $s[] = '		cache: "false",';
            $s[] = '		data: phData,';
            $s[] = '		dataType:"JSON",';
            $s[] = '		success: function(data){';
            $s[] = '			if (data.status == 1){';
            //$s[] = '				jQuery("#phItemCompareBox").html(data.item);';
            //$s[] = ' 				jQuery("#phQuickViewPopupBody").html(data.popup);'; added in ajax
            //- $s[] = ' 			jQuery("#phContainer").html(data.popup); ';
            $s[] = ' 				jQuery(".phjItemQuick.phjProductAttribute").remove(); ';// Clear attributes from dom when ajax reload
            $s[] = ' 				jQuery("body").append(jQuery("#phContainer"));';
            $s[] = ' 				jQuery("#phContainer").html(data.popup); ';
            //- $s[] = ' 			jQuery("#phQuickViewPopup").modal();';
            $s[] = ' 				jQuery("body").append(jQuery("#phQuickViewPopup"));';
            $s[] = ' 				jQuery("#phQuickViewPopup").modal();';
            if ($load_chosen > 0) {
    
                // TO DO
                // Chosen cannot be dynamically recreated in case
                // we want to add support for mobiles and have support for html required forms (browser checks for html required forms)
                // Now choosen is disables on mobile devices so when we reload choosen for standard devices
                // we lost the select boxes on mobiles
                //$s[] = '	  				jQuery(\'select\').chosen({disable_search_threshold : 10,allow_single_deselect : true});';//Reload Chosen
                // This seems to work
                //$s[] = '	 jQuery(\'select\').chosen({disable_search_threshold : 10,allow_single_deselect : true});';
                $s[] = '	 jQuery(\'select\').chosen(\'destroy\').chosen({disable_search_threshold : 10,allow_single_deselect : true});';
            }
    
            if ($dynamic_change_price == 1) {
                //$s[] = '					phAjaxChangePrice();';
            }
    
            $s[] = 'phChangeAttributeType(\'ItemQuick\');';// Recreate the select attribute (color, image) after AJAX
    
            $s[] = '		'. $options['touchspin'];// Touch spin for input
    
            $s[] = '			  } else {';
            //$s[] = '					// Don\'t change the price box';
            $s[] = '			  }';
            $s[] = '		}';
            $s[] = '	})';
            //$s[] = '		e.preventDefault();';
            //$s[] = '       return false;';*/
    //$s[] = '}';
    //$s[] = '})';
    //$s[] = ' ';
}