Back to PhocacartRenderJs class

Method renderAjaxUpdateCart

public static
renderAjaxUpdateCart
()

Method renderAjaxUpdateCart - Source code

public static function renderAjaxUpdateCart()
{
    $paramsC = PhocacartUtils::getComponentParameters();
    $add_cart_method = $paramsC->get('add_cart_method', 0);
    // We need to refresh checkout site when AJAX used for removing or adding products to cart
    $task = 'checkout.update';
    $class = '.phCheckoutCartBox';
    $cView = PhocacartUtils::isView('checkout') ? 1 : 0;
    // POS
    $isPOS = false;
    if (PhocacartUtils::isView('pos')) {
        $task = 'pos.update';
        $add_cart_method = 1;
        // POS has always 1 (ajax and no popup)
        $cView = 0;
        $class = '.phPosCartBox';
        $isPOS = true;
    }
    $urlAjax = Uri::base(true) . '/index.php?option=com_phocacart&task=' . $task . '&format=json&' . Session::getFormToken() . '=1&checkoutview=' . (int) $cView;
    $s = array();
    $s[] = 'function phDoSubmitFormUpdateCart(sFormData) {';
    $s[] = '	var phUrl 	= "' . $urlAjax . '";';
    $s[] = '	var phOptions = [];';
    $s[] = '	phOptions["view"] = ' . (int) $cView . ';';
    $s[] = '	phOptions["method"]  = ' . (int) $add_cart_method . ';';
    $s[] = '	phOptions["task"]  = "update";';
    $s[] = '	phOptions["type"]  = "cart";';
    $s[] = '	phOptions["class"]  = "' . $class . '";';
    $s[] = $isPOS === true ? '	phOptions["pos"]  = 1;' : '	phOptions["pos"]  = 0;';
    $s[] = '	phDoRequestMethods(phUrl, sFormData, 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: sFormData,';
                    $s[] = '      dataType:"JSON",';
                    $s[] = '      success: function(data){';
                    $s[] = '         if (data.status == 1){';
                    $s[] = '            jQuery("'.$class.'").html(data.item);';
                    $s[] = '            jQuery("'.$class.'Count").html(data.count);';
                    $s[] = '            jQuery("'.$class.'Total").html(data.total); ';
    
                    // POS update message box (clean) and input box (when product added or changed - shipping and payment method must be cleaned)
                    if (PhocacartUtils::isView('pos')) {
                        $s[] = '    		var phUrlPos 	= phAddSuffixToUrl(window.location.href, \'format=raw\');';
                        $s[] = '			var phDataInput = phPosCurrentData("main.input");';
                        $s[] = '			phDoSubmitFormUpdateInputBox(phDataInput, phUrlPos);';// refresh input box
                        $s[] = '			jQuery(".ph-pos-message-box").html(data.message);';// clear message box
                        $s[] = '			phPosManagePage();';
                    }
    
                    // 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 (phCheckoutView == 1) {';
                    //$s[] = '               setTimeout(function() {location.reload();}, 0001);';
                    //$s[] = '            }';
    
                    $s[] = '         } else if (data.status == 0){';
    
                    // 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 (phCheckoutView == 1) {';
                    //$s[] = '               setTimeout(function() {location.reload();}, 0001);';
                    //$s[] = '            }';
    
                    $s[] = ' 				jQuery("body").append(jQuery("#phContainer"));';
                    $s[] = ' 				jQuery("#phContainer").html(data.popup);';
                    $s[] = ' 				jQuery("#phAddToCartPopup").modal();';
    
                    $s[] = '         } else {';
                    //$s[] = '					// Don\'t change the price box';
                    $s[] = '         }';
                    $s[] = '      },';
                    //$s[] = '      error: function(data){}';
                    $s[] = '   })';
                    $s[] = '   return false;';
                    $s[] = '}';
    
                    $s[] = ' ';
    
                    // ::EVENT (CLICK) Change Layout Type Clicking on Grid, Gridlist, List
                    $s[] = 'jQuery(document).ready(function(){';
                    $s[] = '	jQuery(document).on("click", "form.phItemCartUpdateBoxForm button", function (e) {';
                    $s[] = '		e.preventDefault();';
                    $s[] = '	    var sForm 	= jQuery(this).closest("form");';// Find in which form the right button was clicked
                    $s[] = '		var phAction= jQuery(this).val()';
                    $s[] = '	    var sFormData = sForm.serialize() + "&action=" + phAction;';
                    $s[] = '	    phDoSubmitFormUpdateCart(sFormData);';
                    $s[] = '	})';
                    $s[] = '})';
                    $s[] = ' ';*/
    //$s[] = '}';
}