isUpdatingFrom method

void isUpdatingFrom(
  1. Cart cart,
  2. {bool forceUpdate = false}
)

Implementation

void isUpdatingFrom(Cart cart, {bool forceUpdate = false}) {
  this.allItems.forEach((cartItem) {
    // Check if this cart item exists on the already saved cart
    // The same sku can exist in two cart items IF one of them is promotional or gift,
    //   so we also compare if the flags are equal
    var previousCartItem = cart.allItems.firstWhere(
        (i) =>
            i.sku.id == cartItem.sku.id &&
            i.isPromotional == cartItem.isPromotional &&
            i.isGift == cartItem.isGift,
        orElse: () => null);

    if (previousCartItem != null) {
      // If it exists, call the update handler
      cartItem.isUpdatingFrom(previousCartItem, forceUpdate: forceUpdate);
    }
  });

  if (this.giftsQuantityAllowed != cart.giftsQuantityAllowed) {
    changesFromLastUpdate['giftsQuantityAllowed'] = cart.giftsQuantityAllowed;
  }
}