articleSaveInCache function
Implementation
articleSaveInCache(ProductData _product) async {
int _stock = 0;
for (var _group in _product.group)
for (var _var in _group.price)
_stock += _var.stock;
var _cache = ProductDataCache(
id: _product.id,
timeModify: _product.timeModify,
name: _product.name,
visible: _product.visible,
price: _product.priceProduct,
category: _product.category,
providers: _product.providers,
rating: _product.getRating(),
image: _product.gallery.isNotEmpty ? _product.gallery[0].serverPath : "",
discPrice: _product.discPriceProduct,
stock: _stock,
delete: _product.delete,
);
await FirebaseFirestore.instance.collection("cache").doc("article")
.set({
_product.id: _cache.toJson(),
}, SetOptions(merge:true));
var index = 0;
for (var item in productDataCache)
if (item.id == _product.id){
index = productDataCache.indexOf(item);
productDataCache.remove(item);
break;
}
if (!_cache.delete)
productDataCache.insert(index, _cache);
}