async addAllItemsToCart(event) {
    // check if is the special item category
    const isSpecialItemCategory = this.isSpecialItemCategory();
    // message to pass to the modal element after item is added to cart.
    const message = 'your item has been added to the cart successfully.';

    if (isSpecialItemCategory) {
      const categoryPage = $('.body');

      // append the button to the page
      categoryPage.prepend(`
      <form id="form-action" >
				<input id="form-action-addToCart" data-wait-message="adding to cart..." value="Add All To Cart"  type="submit" class="button button--primary add-btn" />
      </form>`);

      // grab the add all items button
      const $addBtn = $('.add-btn');

      // set event listener to the button
      $addBtn.on('click', async (event) => {
        event.preventDefault();
        // get products to add to the cart.
        const addToCartProducts = this.findProductID();

        // get the cart object.
        let isCartEmpty = await this.getCart();
        // check if cart is empty.
        isCartEmpty = isCartEmpty.length ? true : false;
        // grab the add button text.
        const originalBtn = $addBtn.val();
        // set message for the button to display when submitting.
        const waitingMessage = $addBtn.data('wait-message');

        // if cart is empty create cart
        if (!isCartEmpty) {
          $addBtn.val(waitingMessage).prop('disabled', true);
          fetch('/api/storefront/cart', {
            method: 'POST', // or 'PUT'
            credentials: 'include',
            body: JSON.stringify(addToCartProducts),
          })
            .then((response) => response.json())
            .then((data) => {
              $addBtn.val(originalBtn).prop('disabled', false);
              // show modal when products are added to the cart.
              this.modal(message, 'add').show();
              console.log('Success:', data);
            })
            .catch((error) => {
              $addBtn.val(originalBtn).prop('disabled', false);
              console.error('Error:', error);
            });
          // if cart is not empty, get cart id and add products to cart.
        } else {
          let cart = await this.getCart();
          fetch(`/api/storefront/cart/${cart[0].id}/items`, {
            method: 'POST', // or 'PUT'
            credentials: 'include',
            body: JSON.stringify(addToCartProducts),
          })
            .then((response) => response.json())
            .then((data) => {
              $addBtn.val(originalBtn).prop('disabled', false);
              // show modal when products are added to the cart.
              this.modal(message, 'add').show();
              console.log('Success:', data);
            })
            .catch((error) => {
              console.error('Error:', error);
            });
        }
      });
    } //if statement
  }
// add items to the cart.
add items to the cart.
add items to the cart .
async addAllItemsToCart(event) {
    const isSpecialItemCategory = this.isSpecialItemCategory();
    const message = 'your item has been added to the cart successfully.';
    if (isSpecialItemCategory) {
      const categoryPage = $('.body');
      categoryPage.prepend(`
      <form id="form-action" >
				<input id="form-action-addToCart" data-wait-message="adding to cart..." value="Add All To Cart"  type="submit" class="button button--primary add-btn" />
      </form>`);
      const $addBtn = $('.add-btn');
      $addBtn.on('click', async (event) => {
        event.preventDefault();
        const addToCartProducts = this.findProductID();
        let isCartEmpty = await this.getCart();
        isCartEmpty = isCartEmpty.length ? true : false;
        const originalBtn = $addBtn.val();
        const waitingMessage = $addBtn.data('wait-message');
        if (!isCartEmpty) {
          $addBtn.val(waitingMessage).prop('disabled', true);
          fetch('/api/storefront/cart', {
            method: 'POST', 
            credentials: 'include',
            body: JSON.stringify(addToCartProducts),
          })
            .then((response) => response.json())
            .then((data) => {
              $addBtn.val(originalBtn).prop('disabled', false);
              this.modal(message, 'add').show();
              console.log('Success:', data);
            })
            .catch((error) => {
              $addBtn.val(originalBtn).prop('disabled', false);
              console.error('Error:', error);
            });
        } else {
          let cart = await this.getCart();
          fetch(`/api/storefront/cart/${cart[0].id}/items`, {
            method: 'POST', 
            credentials: 'include',
            body: JSON.stringify(addToCartProducts),
          })
            .then((response) => response.json())
            .then((data) => {
              $addBtn.val(originalBtn).prop('disabled', false);
              this.modal(message, 'add').show();
              console.log('Success:', data);
            })
            .catch((error) => {
              console.error('Error:', error);
            });
        }
      });
    } 
  }
async addAllItemsToCart ( event ) { const isSpecialItemCategory = this . isSpecialItemCategory ( ) ; const message = 'your item has been added to the cart successfully.' ; if ( isSpecialItemCategory ) { const categoryPage = $ ( '.body' ) ; categoryPage . prepend ( ` ` ) ; const $addBtn = $ ( '.add-btn' ) ; $addBtn . on ( 'click' , async ( event ) => { event . preventDefault ( ) ; const addToCartProducts = this . findProductID ( ) ; let isCartEmpty = await this . getCart ( ) ; isCartEmpty = isCartEmpty . length ? true : false ; const originalBtn = $addBtn . val ( ) ; const waitingMessage = $addBtn . data ( 'wait-message' ) ; if ( ! isCartEmpty ) { $addBtn . val ( waitingMessage ) . prop ( 'disabled' , true ) ; fetch ( '/api/storefront/cart' , { method : 'POST' , credentials : 'include' , body : JSON . stringify ( addToCartProducts ) , } ) . then ( ( response ) => response . json ( ) ) . then ( ( data ) => { $addBtn . val ( originalBtn ) . prop ( 'disabled' , false ) ; this . modal ( message , 'add' ) . show ( ) ; console . log ( 'Success:' , data ) ; } ) . catch ( ( error ) => { $addBtn . val ( originalBtn ) . prop ( 'disabled' , false ) ; console . error ( 'Error:' , error ) ; } ) ; } else { let cart = await this . getCart ( ) ; fetch ( ` ${ cart [ 0 ] . id } ` , { method : 'POST' , credentials : 'include' , body : JSON . stringify ( addToCartProducts ) , } ) . then ( ( response ) => response . json ( ) ) . then ( ( data ) => { $addBtn . val ( originalBtn ) . prop ( 'disabled' , false ) ; this . modal ( message , 'add' ) . show ( ) ; console . log ( 'Success:' , data ) ; } ) . catch ( ( error ) => { console . error ( 'Error:' , error ) ; } ) ; } } ) ; } }
add items to the cart.
add items to the cart .
// check if is the special item category // message to pass to the modal element after item is added to cart. // append the button to the page // grab the add all items button // set event listener to the button // get products to add to the cart. // get the cart object. // check if cart is empty. // grab the add button text. // set message for the button to display when submitting. // if cart is empty create cart // or 'PUT' // show modal when products are added to the cart. // if cart is not empty, get cart id and add products to cart. // or 'PUT' // show modal when products are added to the cart. //if statement