• richardscarry scarry
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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