WooProductCategory class
WooCommerce Product Category Model
This class represents a product category in WooCommerce with comprehensive information about the category, its hierarchy, display settings, and metadata. Categories help organize products and can be arranged in hierarchical structures.
Key Features
- Hierarchical Structure: Support for parent-child category relationships
- Display Control: Configure how categories display products and subcategories
- Rich Metadata: Support for descriptions, images, and custom ordering
- Product Association: Track product counts and relationships
- SEO Support: Slug-based URLs and structured data
- Menu Integration: Custom ordering for navigation menus
Usage Examples
Creating a Category
final category = WooProductCategory(
name: 'Electronics',
description: 'Electronic products and gadgets',
slug: 'electronics',
display: WooCategoryDisplay.products,
);
Working with Category Data
// Check if category has products
if (category.count! > 0) {
print('Category ${category.name} has ${category.count} products');
}
// Check if category is a subcategory
if (category.parent != null) {
print('This is a subcategory of parent ID: ${category.parent}');
}
JSON Serialization
The class supports full JSON serialization for API communication:
// Convert to JSON for API requests
final json = category.toJson();
// Create from JSON response
final category = WooProductCategory.fromJson(jsonData);
Constructors
- WooProductCategory({int? id, String? name, String? slug, int? parent, String? description, WooCategoryDisplay? display, WooProductCategoryImage? image, int? count, WooProductCategoryLinks? links})
- Creates a new WooProductCategory instance
- WooProductCategory.fake()
-
Creates a fake WooProductCategory instance for testing purposes
factory
-
WooProductCategory.fromJson(Map<
String, dynamic> json) - Creates a WooProductCategory instance from JSON data
Properties
- count ↔ int?
-
Product count
getter/setter pair
- description ↔ String?
-
Category description
getter/setter pair
- display ↔ WooCategoryDisplay?
-
Category display type
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- id ↔ int?
-
Unique identifier for the category
getter/setter pair
- image ↔ WooProductCategoryImage?
-
Category image
getter/setter pair
- links ↔ WooProductCategoryLinks?
-
Category links
getter/setter pair
-
Menu order
getter/setter pair
- name ↔ String?
-
Category name
getter/setter pair
- parent ↔ int?
-
Parent category ID
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- slug ↔ String?
-
Category slug
getter/setter pair
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, dynamic> - Converts the WooProductCategory instance to JSON format
-
toString(
) → String -
Returns a string representation of the WooProductCategory instance
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited