async emptyCart(event) {
    const deleteBtnEle = `
    <input id="empty-cart" data-wait-message="adding to cart..." value="Empty Cart"  type="submit" class="button button--secondary delete-btn" />`;
    // get container where add all button element is located.
    const $categoryPage = $('#form-action');

    // message for the modal after clearing the cart.
    const message = 'Your cart was cleared successfully';

    // check if cart is empty.
    let isCartEmpty = await this.isCartEmpty();

    // if cart is not empty add the button.
    if (isCartEmpty) {
      $categoryPage.append(deleteBtnEle);
    }
    // grab the delete button
    const $deleteBtn = $('#empty-cart');

    // set event listerner for the delete button.
    $deleteBtn.on('click', async (event) => {
      event.preventDefault();
      // get the cart object
      let data = await this.getCart();

      // settings for the ajax request
      var settings = {
        url: `/api/storefront/carts/${data[0].id}`,
        async: true,
        method: 'DELETE',
        success: (response) => console.log(response),
        complete: () => {
          this.modal(message, 'delete').show();
        },
      };

      $.ajax(settings);
    });
  }
// method to add delete button if cart is not empty.
method to add delete button if cart is not empty.
method to add delete button if cart is not empty .
async emptyCart(event) {
    const deleteBtnEle = `
    <input id="empty-cart" data-wait-message="adding to cart..." value="Empty Cart"  type="submit" class="button button--secondary delete-btn" />`;
    const $categoryPage = $('#form-action');
    const message = 'Your cart was cleared successfully';
    let isCartEmpty = await this.isCartEmpty();
    if (isCartEmpty) {
      $categoryPage.append(deleteBtnEle);
    }
    const $deleteBtn = $('#empty-cart');
    $deleteBtn.on('click', async (event) => {
      event.preventDefault();
      let data = await this.getCart();
      var settings = {
        url: `/api/storefront/carts/${data[0].id}`,
        async: true,
        method: 'DELETE',
        success: (response) => console.log(response),
        complete: () => {
          this.modal(message, 'delete').show();
        },
      };
      $.ajax(settings);
    });
  }
async emptyCart ( event ) { const deleteBtnEle = ` ` ; const $categoryPage = $ ( '#form-action' ) ; const message = 'Your cart was cleared successfully' ; let isCartEmpty = await this . isCartEmpty ( ) ; if ( isCartEmpty ) { $categoryPage . append ( deleteBtnEle ) ; } const $deleteBtn = $ ( '#empty-cart' ) ; $deleteBtn . on ( 'click' , async ( event ) => { event . preventDefault ( ) ; let data = await this . getCart ( ) ; var settings = { url : ` ${ data [ 0 ] . id } ` , async : true , method : 'DELETE' , success : ( response ) => console . log ( response ) , complete : ( ) => { this . modal ( message , 'delete' ) . show ( ) ; } , } ; $ . ajax ( settings ) ; } ) ; }
method to add delete button if cart is not empty.
method to add delete button if cart is not empty .
// get container where add all button element is located. // message for the modal after clearing the cart. // check if cart is empty. // if cart is not empty add the button. // grab the delete button // set event listerner for the delete button. // get the cart object // settings for the ajax request