Product.fromJson constructor
Product.fromJson(
- Map<String, dynamic> json
)
Implementation
factory Product.fromJson(Map<String, dynamic> json) {
// print('dlk$json');
List<Download> download = [];
for (var i = 0; i < json['downloads'].length; i++) {
download.add(Download.fromJson(json['downloads'][i]));
}
// List<Categories> categoriesList = [];
// if (json['categories'] != null) {
// if (json['categories'] is List) {
// categoriesList = (json['categories'] as List)
// .map((i) => Categories.fromJson(i))
// .toList();
// } else if (json['categories'] is int) {
// categoriesList.add(Categories(id: json['categories']));
// }
// }
return Product(
// duration: durationn['value'],
// timeList: timeListt,
id: json['id'],
name: json['name'],
slug: json['slug'],
permalink: json['permalink'],
type: json['type'],
status: json['status'],
featured: json['featured'],
catalogVisibility: json['catalog_visibility'],
description: json['description'],
shortDescription: json['short_description'],
sku: json['sku'],
Productprice: json['price'],
Price: json['regular_price'],
salePrice: (json['sale_price'] is String
? json['sale_price']
: json['sale_price'].toString()),
priceHtml: json['price_html'],
onSale: json['on_sale'],
purchasable: json['purchasable'],
totalSales: json['total_sales'],
virtual: json['virtual'],
downloadable: json['downloadable'],
downloads: download,
downloadLimit: json['download_limit'],
downloadExpiry: json['download_expiry'],
externalUrl: json['external_url'],
buttonText: json['button_text'],
taxStatus: json['tax_status'],
taxClass: json['tax_class'],
manageStock: json['manage_stock'],
stockQuantity: json['stock_quantity'],
stockStatus: json['stock_status'],
backorders: json['backorders'],
backordersAllowed: json['backorders_allowed'],
backordered: json['backordered'],
soldIndividually: json['sold_individually'],
weight: json['weight'].toString(),
dimensions: json['dimensions'],
shippingRequired: json['shipping_required'],
shippingTaxable: json['shipping_taxable'],
shippingClass: json['shipping_class'],
shippingClassId: json['shipping_class_id'],
reviewsAllowed: json['reviews_allowed'],
averageRating: json['average_rating'],
ratingCount: json['rating_count'],
relatedIds: json['related_ids'],
upsellIds: json['upsell_ids'],
crossSellIds: json['cross_sell_ids'],
parentId: json['parent_id'],
purchaseNote: json['purchase_note'],
categories: (json['categories'] as List)
.map((i) => Categories.fromJson(i))
.toList(),
// categories: json['categories'].cast<int>(),
tags: (json['tags'] as List).map((i) => Tags.fromJson(i)).toList(),
images: (json['images'] as List)
.map((i) => ImageModel.fromJson(i))
.toList(),
attributes: (json['attributes'] as List)
.map((i) => Attribute.fromJson(i))
.toList(),
defaultAttributes: (json['default_attributes'] as List)
.map((i) => Attribute.fromJson(i))
.toList(),
variations: json['variations'],
groupedProducts: json['grouped_products'],
menuOrder: json['menu_order'],
dateCreated: json['date_created'],
dateCreatedGMT: json['date_created_gmt'],
metaData: json['meta_data']);
}