Back to PhocacartRenderJs class

Method renderAjaxRemoveFromWishList

public static
renderAjaxRemoveFromWishList
()

Method renderAjaxRemoveFromWishList - Source code

public static function renderAjaxRemoveFromWishList()
{
    $paramsC = PhocacartUtils::getComponentParameters();
    $add_wishlist_method = $paramsC->get('add_wishlist_method', 0);
    // We need to refresh wishlist site when AJAX used for removing or adding products to wishlist list
    $app = Factory::getApplication();
    $view = $app->input->get('view', '');
    $option = $app->input->get('option', '');
    $wView = $option == 'com_phocacart' && $view == 'wishlist' ? 1 : 0;
    if ($add_wishlist_method == 0) {
        return false;
    }
    if ($add_wishlist_method > 0) {
        $urlAjax = Uri::base(true) . '/index.php?option=com_phocacart&task=wishlist.remove&format=json&' . Session::getFormToken() . '=1&wishlistview=' . (int) $wView;
        $s = array();
        $s[] = ' ';
        $s[] = 'function phItemRemoveWishListFormAjax(phItemId) {';
        $s[] = '	var phUrl 	= "' . $urlAjax . '";';
        $s[] = '	var phItem = \'#\' + phItemId;';
        $s[] = '	var phOptions = [];';
        $s[] = '	phOptions["view"] = ' . (int) $wView . ';';
        $s[] = '	phOptions["method"]  = ' . (int) $add_wishlist_method . ';';
        $s[] = '	phOptions["task"]  = "remove";';
        $s[] = '	phOptions["type"]  = "wishlist";';
        $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(".phItemWishListBox").html(data.item);';
                                $s[] = '				jQuery(".phItemWishListBoxCount").html(data.count);';
                                if ($add_wishlist_method == 2) {
                                    // Display the popup
                                    $s[] = ' 				jQuery("#phContainerModuleWishList").html(data.popup);';
                                    $s[] = ' 				jQuery("#phRemoveFromWishListPopup").modal();';
                                }
                                if ($add_wishlist_method == 1) {
                                    // If no popup is displayed we can relaod the page when we are in wishlist page
                                    // If popup, this will be done when clicking continue or wishlist list
                                    $s[] = '					if (phWishListView == 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;';*/
    }
}