public static function renderAjaxRemoveFromCompare()
{
$paramsC = PhocacartUtils::getComponentParameters();
$add_compare_method = $paramsC->get('add_compare_method', 0);
// We need to refresh comparison site when AJAX used for removing or adding products to comparison list
$app = Factory::getApplication();
$view = $app->input->get('view', '');
$option = $app->input->get('option', '');
$cView = $option == 'com_phocacart' && $view == 'comparison' ? 1 : 0;
if ($add_compare_method == 0) {
return false;
}
if ($add_compare_method > 0) {
$urlAjax = Uri::base(true) . '/index.php?option=com_phocacart&task=comparison.remove&format=json&' . Session::getFormToken() . '=1&comparisonview=' . (int) $cView;
$s = array();
$s[] = ' ';
$s[] = 'function phItemRemoveCompareFormAjax(phItemId) {';
$s[] = ' var phUrl = "' . $urlAjax . '";';
$s[] = ' var phItem = \'#\' + phItemId;';
$s[] = ' var phOptions = [];';
$s[] = ' phOptions["view"] = ' . (int) $cView . ';';
$s[] = ' phOptions["method"] = ' . (int) $add_compare_method . ';';
$s[] = ' phOptions["task"] = "remove";';
$s[] = ' phOptions["type"] = "compare";';
$s[] = ' var phData = jQuery(phItem).serialize();';
$s[] = ' phDoRequestMethods(phUrl, phData, phOptions);';
$s[] = '}';
$s[] = ' ';
Factory::getDocument()->addScriptDeclaration(implode("\n", $s));
/*$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(".phItemCompareBoxCount").html(data.count);';
if ($add_compare_method == 2) {
// Display the popup
$s[] = ' jQuery("#phContainerModuleCompare").html(data.popup);';
$s[] = ' jQuery("#phRemoveFromComparePopup").modal();';
}
if ($add_compare_method == 1) {
// If no popup is displayed we can relaod the page when we are in comparison page
// If popup, this will be done when clicking continue or comparison list
$s[] = ' if (phComparisonView == 1) {';
$s[] = self::renderOverlay();
$s[] = ' setTimeout(function() {location.reload();}, 0001);';
$s[] = ' }';
}
$s[] = ' } else {';
//$s[] = ' // Don\'t change the price box';
$s[] = ' }';
$s[] = ' }';
$s[] = ' })';
//$s[] = ' e.preventDefault();';
//$s[] = ' return false;';*/
}
}