You've already forked wc-composable-product
Implement comprehensive stock management integration (v1.1.0)
Added complete inventory tracking system for composable products: - Stock validation during product selection and add-to-cart - Automatic stock deduction on order completion/processing - Automatic stock restoration on order cancellation/refund - Stock status indicators with visual feedback (In stock, Low stock, Out of stock) - Prevention of out-of-stock item selection - Low stock warnings when 5 or fewer items remain - Order notes documenting all stock changes New files: - includes/Stock_Manager.php: Core stock management logic Modified files: - includes/Cart_Handler.php: Integrated stock validation - includes/Product_Selector.php: Added stock info to product data - includes/Plugin.php: Added Stock_Manager to includes - templates/product-selector.twig: Stock status display - assets/css/frontend.css: Stock indicator styling - languages/*.pot/*.po: 8 new translatable strings Version bumped to 1.1.0 with updated CHANGELOG. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ This document provides a technical overview of the WooCommerce Composable Produc
|
||||
|
||||
### Plugin Structure
|
||||
|
||||
```
|
||||
```txt
|
||||
wc-composable-product/
|
||||
├── assets/ # Frontend assets
|
||||
│ ├── css/
|
||||
@@ -42,6 +42,7 @@ wc-composable-product/
|
||||
### 1. Main Plugin Class (`Plugin.php`)
|
||||
|
||||
**Responsibilities:**
|
||||
|
||||
- Singleton pattern implementation
|
||||
- Twig template engine initialization
|
||||
- Hook registration
|
||||
@@ -49,6 +50,7 @@ wc-composable-product/
|
||||
- Asset enqueuing
|
||||
|
||||
**Key Methods:**
|
||||
|
||||
- `instance()`: Get singleton instance
|
||||
- `init_twig()`: Initialize Twig with WordPress functions
|
||||
- `render_template()`: Render Twig templates
|
||||
@@ -59,6 +61,7 @@ wc-composable-product/
|
||||
**Extends:** `WC_Product`
|
||||
|
||||
**Key Features:**
|
||||
|
||||
- Custom product type: `composable`
|
||||
- Selection limit management (per-product or global)
|
||||
- Pricing mode (fixed or sum)
|
||||
@@ -67,6 +70,7 @@ wc-composable-product/
|
||||
- Price calculation
|
||||
|
||||
**Key Methods:**
|
||||
|
||||
- `get_selection_limit()`: Get max selectable items
|
||||
- `get_pricing_mode()`: Get pricing calculation mode
|
||||
- `get_available_products()`: Query available products
|
||||
@@ -77,6 +81,7 @@ wc-composable-product/
|
||||
**Extends:** `WC_Settings_Page`
|
||||
|
||||
**Global Settings:**
|
||||
|
||||
- Default selection limit
|
||||
- Default pricing mode
|
||||
- Display options (images, prices, total)
|
||||
@@ -86,12 +91,14 @@ wc-composable-product/
|
||||
### 4. Product Data Tab (`Admin/Product_Data.php`)
|
||||
|
||||
**Responsibilities:**
|
||||
|
||||
- Add "Composable Options" tab to product edit page
|
||||
- Render selection criteria fields
|
||||
- Save product meta data
|
||||
- Dynamic field visibility based on criteria type
|
||||
|
||||
**Saved Meta:**
|
||||
|
||||
- `_composable_selection_limit`: Item limit
|
||||
- `_composable_pricing_mode`: Pricing calculation
|
||||
- `_composable_criteria_type`: Selection method
|
||||
@@ -102,11 +109,13 @@ wc-composable-product/
|
||||
### 5. Product Selector (`Product_Selector.php`)
|
||||
|
||||
**Responsibilities:**
|
||||
|
||||
- Render frontend product selection interface
|
||||
- Prepare data for Twig template
|
||||
- Apply display settings
|
||||
|
||||
**Template Variables:**
|
||||
|
||||
- `products`: Available products array
|
||||
- `selection_limit`: Max selections
|
||||
- `pricing_mode`: Pricing calculation
|
||||
@@ -115,12 +124,14 @@ wc-composable-product/
|
||||
### 6. Cart Handler (`Cart_Handler.php`)
|
||||
|
||||
**Responsibilities:**
|
||||
|
||||
- Validate product selection
|
||||
- Add selected products to cart data
|
||||
- Calculate dynamic pricing
|
||||
- Display selected products in cart
|
||||
|
||||
**Hooks:**
|
||||
|
||||
- `woocommerce_add_to_cart_validation`: Validate selections
|
||||
- `woocommerce_add_cart_item_data`: Store selections
|
||||
- `woocommerce_before_calculate_totals`: Update prices
|
||||
@@ -131,6 +142,7 @@ wc-composable-product/
|
||||
### Product Selector Template (`product-selector.twig`)
|
||||
|
||||
**Features:**
|
||||
|
||||
- Responsive grid layout
|
||||
- Checkbox-based selection
|
||||
- Product images and prices
|
||||
@@ -138,6 +150,7 @@ wc-composable-product/
|
||||
- AJAX add-to-cart
|
||||
|
||||
**Data Attributes:**
|
||||
|
||||
- `data-product-id`: Composable product ID
|
||||
- `data-selection-limit`: Max selections
|
||||
- `data-pricing-mode`: Pricing mode
|
||||
@@ -146,6 +159,7 @@ wc-composable-product/
|
||||
### JavaScript (`frontend.js`)
|
||||
|
||||
**Functionality:**
|
||||
|
||||
- Selection limit enforcement
|
||||
- Visual feedback on selection
|
||||
- Real-time price updates (sum mode)
|
||||
@@ -153,6 +167,7 @@ wc-composable-product/
|
||||
- Error/success messages
|
||||
|
||||
**Key Functions:**
|
||||
|
||||
- `handleCheckboxChange()`: Selection logic
|
||||
- `updateTotalPrice()`: Calculate total
|
||||
- `addToCart()`: AJAX add-to-cart
|
||||
@@ -161,6 +176,7 @@ wc-composable-product/
|
||||
### CSS Styling
|
||||
|
||||
**Approach:**
|
||||
|
||||
- Grid-based layout (responsive)
|
||||
- Card-style product items
|
||||
- Visual selection states
|
||||
@@ -242,6 +258,7 @@ wc-composable-product/
|
||||
Generated template: `languages/wc-composable-product.pot`
|
||||
|
||||
**Supported Locales (per CLAUDE.md):**
|
||||
|
||||
- en_US (English)
|
||||
- de_DE, de_DE_informal (German - Germany)
|
||||
- de_CH, de_CH_informal (German - Switzerland)
|
||||
@@ -273,11 +290,13 @@ Generated template: `languages/wc-composable-product.pot`
|
||||
### Hooks & Filters
|
||||
|
||||
**Available Filters:**
|
||||
|
||||
- `wc_composable_settings`: Modify settings array
|
||||
- `woocommerce_product_class`: Custom product class
|
||||
- `product_type_selector`: Product type registration
|
||||
|
||||
**Customization Points:**
|
||||
|
||||
- Twig templates (override in theme)
|
||||
- CSS styling (enqueue custom styles)
|
||||
- JavaScript behavior (extend object)
|
||||
@@ -304,6 +323,7 @@ if ($product->get_type() === 'composable') {
|
||||
## Testing Checklist
|
||||
|
||||
### Admin Testing
|
||||
|
||||
- [ ] Product type appears in dropdown
|
||||
- [ ] Composable Options tab displays
|
||||
- [ ] Selection criteria toggle works
|
||||
@@ -312,6 +332,7 @@ if ($product->get_type() === 'composable') {
|
||||
- [ ] Global defaults apply
|
||||
|
||||
### Frontend Testing
|
||||
|
||||
- [ ] Product selector renders
|
||||
- [ ] Selection limit enforced
|
||||
- [ ] Price calculation accurate (both modes)
|
||||
@@ -320,6 +341,7 @@ if ($product->get_type() === 'composable') {
|
||||
- [ ] Checkout processes correctly
|
||||
|
||||
### Edge Cases
|
||||
|
||||
- [ ] Empty criteria (no products)
|
||||
- [ ] Out of stock products excluded
|
||||
- [ ] Invalid product selections rejected
|
||||
@@ -349,12 +371,14 @@ Potential features for future versions:
|
||||
## Dependencies
|
||||
|
||||
### Runtime
|
||||
|
||||
- PHP 8.3+
|
||||
- WordPress 6.0+
|
||||
- WooCommerce 8.0+
|
||||
- Twig 3.0 (via Composer)
|
||||
|
||||
### Development
|
||||
|
||||
- Composer for dependency management
|
||||
- WP-CLI for i18n operations (optional)
|
||||
|
||||
@@ -372,6 +396,7 @@ Potential features for future versions:
|
||||
### Release Package
|
||||
|
||||
Must include:
|
||||
|
||||
- All PHP files
|
||||
- `vendor/` directory
|
||||
- Assets (CSS, JS)
|
||||
@@ -380,6 +405,7 @@ Must include:
|
||||
- Documentation
|
||||
|
||||
Must exclude:
|
||||
|
||||
- `.git/` directory
|
||||
- `composer.lock`
|
||||
- Development files
|
||||
@@ -388,12 +414,14 @@ Must exclude:
|
||||
## Support & Maintenance
|
||||
|
||||
### Code Standards
|
||||
|
||||
- WordPress Coding Standards
|
||||
- WooCommerce best practices
|
||||
- PSR-4 autoloading
|
||||
- Inline documentation
|
||||
|
||||
### Version Control
|
||||
|
||||
- Semantic versioning (MAJOR.MINOR.PATCH)
|
||||
- Changelog maintained
|
||||
- Annotated git tags
|
||||
|
||||
Reference in New Issue
Block a user