function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Suraj_BahaleSuraj_Bahale 

How to refresh shopping cart on page reload?

Shopping cart is not getting refresh on page reload.

i have written one custom fucntionality on shopping cart on storefront where i have added the one clear cart button on shopping cart.

Vf component:
<button class="btn btn-default btn-sm" id="DeleteAll" name="" type="button" onclick="deleteall(event);">{{pageLabelMap 'CartInc_DeleteAll'}}</button>


function deleteall(e){
        var cart_id =  CCRZ.cartDetailModel.attributes.sfid;
        // var cart_id = CCRZ.pagevars.currentCartID;
        console.log(cart_id); 
        
        var Eff_account_ID = CCRZ.pagevars.queryParams.effectiveAccount;
        console.log(Eff_account_ID);
        
       if(cart_id != undefined){
        console.log("i am in if loop");
        var remoteCall = _.extend(CCRZ.RemoteInvocation, { className: 'FIL_FGP_ProductListCtrl' });
        remoteCall.invokeCtx(
            'clearCart',cart_id , Eff_account_ID,
            function(response,event){
                if(response.success){
                    console.log("clearCart remote action called successfully");
                    //do something with the response
                    console.log(response);
                    location.reload();
                    
                }else{
                    CCRZ.pubSub.trigger('pageMessage', { messages: [{ type: 'CUSTOM', severity: 'ERROR', message:'You have no items in the Cart', classToAppend: 'messagingSection-Error'}] });
                    console.log("clearCart remote action called, but something went wrong");
                }
            },
            {
                buffer:false, //this call will be executed by itself
                nmsp : false //defines that this is a call to a subscriber class
            }
        );
        }else{
        console.log("do nothing");
        }
        
    }

Controller :
@RemoteAction
    global static ccrz.cc_RemoteActionResult clearCart( final ccrz.cc_RemoteActionContext ctx, String cart_id , string Ef_Account_ID){
        ccrz.cc_RemoteActionResult res = ccrz.cc_CallContext.init(ctx);
  
        system.debug('ControllerBegin');                       
        system.debug(ctx);
        //system.debug(sfids);
        system.debug(cart_id);
        

        List<ccrz__E_CartItem__c> item=[Select Id, Name, ccrz__Cart__c, ccrz__CartItemId__c, ccrz__ItemLabel__c, ccrz__Product__c FROM ccrz__E_CartItem__c WHERE ccrz__Cart__c = :cart_id];
        if(item.size()> 0){
            system.debug(item.size());
            system.debug(item);
            delete item;
            res.success = true;
        }else{
            system.debug('Empty Cart');
           res.success = false; 
        } 
        return res;
	}

The remote is going sucessfully and the cart items are getting deleted from the object at backend side .but on page reload the cart is not getting refreshed .It shows the previous quantity.

Thanks & Regards,
Suraj Bahale
richardscarry scarryrichardscarry scarry
QuickBooks is an excellent technical suite of features essential for accounting. Dial QuickBooks Helpline Number @ + 1-888-744-6OO5 if the user seeks elaborated knowledge of the software. The functioning advantages of this software are endless. Since the primary aim behind this invention was to simplify complex calculations and other tasks involved in the management of various businesses. Read more: QuickBooks Helpline Number 
QuickBooks Helpline Number 
QuickBooks Helpline Number 
QuickBooks Helpline Number