HomeWiki
HomeWiki
  1. Cart
  • Back to home
  • 1. Themes
  • Layout
    • New Layout
    • Legacy Layout
  • Components
    • Announcement
    • Banner Carousel
    • Banner With Products Carousel
    • Blog Category List
    • Blog List
    • Brand List
    • Brands Carousel
    • Breadcrumb
    • Call To Action
    • Cart
    • Categories List
    • Change Password
    • Checkout
    • Cookie Manager
    • Filter list
    • Footer
    • Forgot Password
    • Form
    • Hero Carousel
    • Icon Block
    • Invitation
    • Last Visited Products
    • Layout
    • Login
    • Map
    • Nav Bar
    • Offer
    • Product Attachments
    • Product Attributes
    • Product Documentation
    • Product Expected
    • Product Modal
    • Products Block
    • Products Carousel
    • Product Single
    • Profile
    • Quote
    • Register
    • Related Products
    • Search
    • Stores
    • Subscribe Newsletter
    • Text with Image
    • Top Bar
    • Video
  • Reusables
    • Getting Started
  • Assets
    • Getting Started
  • SDK
    • Products
      • _findProductsByCategory
      • _findProductsByIds
      • _findProductsByTitle
      • _findProductsByFilter
      • _findProductsByCriteria
      • _findProductsAndCalculate
      • _findProductsThenCalculate
      • _getProductAttributeSet
      • _setLastVisited
    • Categories
      • _findCategoryTreeById
      • _findCategoriesByIds
      • _findCategoryByAlias
      • _findCategoryTreeByAlias
      • _getCategoryContent
    • Collections
      • _getCollectionContent
      • _findCollectionsByIds
      • _findCollectionsByIdsThenCalculate
    • Brands
      • _getBrandContent
      • _findBrandsByIds
    • Cart
      • _addToCartMulti
      • _addToCart
      • _setCart
      • _clearCart
      • _setCartListener
      • _removeFromCart
      • _calculateCart
    • Checkout
      • _startCheckout
      • _updateCheckout
      • _completeCheckout
    • Shopping Lists
      • _getShoppingLists
      • _updateShoppingList
      • _createShoppingList
      • _deleteShoppingList
      • _getShoppingListByAlias
    • Navigation
      • _getFooterMenu
      • _getHeaderMenu
    • Users
      • _getUserById
    • Utils
      • _calculateCurrency
      • _getCurrencySymbol
      • _getCulture
      • _subscribeToNewsletter
      • _findUnitsByIds
  • Vs Code
    • Getting Started
  1. Cart

_removeFromCart

How to Use _removeFromCart Method#

The _removeFromCart method removes a specific item from the shopping cart based on its variant ID. It updates the cart on the server, synchronizes the cart state in local storage, and emits events to notify other parts of the application about the change.

Usage Steps:#

1.
Specify the Variant ID:
Pass the variantId of the item you want to remove from the cart as a parameter to the _removeFromCart method.
2.
Call the Method:
Invoke the _removeFromCart method with the variant ID to initiate the removal process.
3.
Handle the Response:
The method updates local storage with the new cart state and emits two events: "cart-changed" to update the cart UI and "remove-from-cart" to perform additional actions related to the item removal.

Example:#

In this example:
The _removeFromCart method is called with the variant ID of the item to be removed from the cart.

Common Use Cases:#

1.
Removing an Item from the Cart:
Use this method when you need to remove a specific item from the cart, such as when a user clicks a "Remove" button next to an item in the cart.
2.
Updating UI Components:
The method emits a "cart-changed" event to refresh cart-related UI components, such as updating the cart summary or icon to reflect the removal of the item.
3.
Performing Actions on Item Removal:
The method also emits a "remove-from-cart" event to handle additional actions related to the item removal, such as updating the item list or triggering a notification.

Notes:#

Local Storage Management: The method updates cartToken and cartData in local storage to ensure that the cart state is accurate and consistent across different parts of the application.
Event Emission:
"cart-changed" Event: Emitted to notify other parts of the application about the cart update, allowing for UI updates and synchronization.
"remove-from-cart" Event: Emitted with the item data to handle any specific actions related to the item removal, such as logging or additional processing.
This method provides a straightforward way to manage item removal from the cart, ensuring that the cart state is updated both on the server and in local storage, and that the UI and application state reflect the change.
Previous
_setCartListener
Next
_calculateCart
Built with