You've already forked wc-composable-product
Refactor to PSR-4: rename files and switch namespace
- Rename files to PascalCase: Product_Type → ProductType, Cart_Handler → CartHandler, Product_Selector → ProductSelector, Stock_Manager → StockManager, Admin/Product_Data → Admin/ProductData - Switch namespace from WC_Composable_Product to Magdev\WcComposableProduct - Update all cross-references in PHP, CSS, JS, translations, and docs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
24
CLAUDE.md
24
CLAUDE.md
@@ -36,13 +36,13 @@ wc-composable-product/
|
||||
├── cache/ # Twig template cache (writable, gitignored)
|
||||
├── includes/
|
||||
│ ├── Admin/
|
||||
│ │ ├── Product_Data.php # Product data tab & meta boxes
|
||||
│ │ ├── ProductData.php # Product data tab & meta boxes
|
||||
│ │ └── Settings.php # WooCommerce settings integration
|
||||
│ ├── Cart_Handler.php # Add-to-cart & cart display logic (with stock validation)
|
||||
│ ├── CartHandler.php # Add-to-cart & cart display logic (with stock validation)
|
||||
│ ├── Plugin.php # Main plugin class (Singleton)
|
||||
│ ├── Product_Selector.php # Frontend product selector renderer (with stock info)
|
||||
│ ├── Product_Type.php # Custom WC_Product extension
|
||||
│ └── Stock_Manager.php # Stock management & inventory tracking
|
||||
│ ├── ProductSelector.php # Frontend product selector renderer (with stock info)
|
||||
│ ├── ProductType.php # Custom WC_Product extension
|
||||
│ └── StockManager.php # Stock management & inventory tracking
|
||||
├── languages/ # Translation files (.pot, .po, .mo)
|
||||
├── releases/ # Release packages (gitignored)
|
||||
├── templates/
|
||||
@@ -61,29 +61,29 @@ wc-composable-product/
|
||||
- Registers hooks, manages asset enqueuing, provides template rendering API
|
||||
- Settings.php is lazy-loaded via `woocommerce_get_settings_pages` filter (not in `includes()`) to avoid "Class WC_Settings_Page not found" errors
|
||||
|
||||
2. **Product_Type.php** — Custom WooCommerce product type (`composable`)
|
||||
2. **ProductType.php** — Custom WooCommerce product type (`composable`)
|
||||
- Extends `WC_Product`
|
||||
- Queries available products via `get_available_products()` using `WP_Query`
|
||||
- **Critical**: Uses `tax_query` with `product_type` taxonomy to exclude composable products (NOT `meta_query` — WooCommerce stores product types as taxonomy terms)
|
||||
- Handles variable products by expanding them into individual variations via `get_children()`
|
||||
- Products are filtered by `is_purchasable()` only (not `is_in_stock()` — stock is shown visually and validated at add-to-cart)
|
||||
|
||||
3. **Cart_Handler.php** — Cart integration
|
||||
3. **CartHandler.php** — Cart integration
|
||||
- Validates selections, stores selected products in cart meta, calculates pricing
|
||||
- Uses `woocommerce_is_purchasable` filter to hide default add-to-cart button for composable products
|
||||
- Price recalculation uses a static `$already_calculated` flag per request (no persistent session flags — `set_price()` is in-memory only)
|
||||
|
||||
4. **Product_Selector.php** — Frontend renderer
|
||||
4. **ProductSelector.php** — Frontend renderer
|
||||
- Renders Twig template with product data, stock info, and pre-formatted price HTML via `wc_price()`
|
||||
|
||||
5. **Admin/Product_Data.php** — Product edit interface
|
||||
5. **Admin/ProductData.php** — Product edit interface
|
||||
- Adds "Composable Options" tab with category/tag/SKU selection fields
|
||||
- Saved meta: `_composable_selection_limit`, `_composable_pricing_mode`, `_composable_criteria_type`, `_composable_categories`, `_composable_tags`, `_composable_skus`
|
||||
|
||||
6. **Admin/Settings.php** — Global settings (extends `WC_Settings_Page`)
|
||||
- Default selection limit, pricing mode, display preferences
|
||||
|
||||
7. **Stock_Manager.php** — Inventory management
|
||||
7. **StockManager.php** — Inventory management
|
||||
- Stock validation, automatic deduction on order completion, restoration on cancellation
|
||||
- Prevents WooCommerce double-deduction via `woocommerce_can_reduce_order_stock`
|
||||
|
||||
@@ -91,11 +91,11 @@ wc-composable-product/
|
||||
|
||||
**Product Creation:** Admin selects "Composable product" type → configures criteria/limits/pricing → metadata saved as `_composable_*` fields
|
||||
|
||||
**Frontend Display:** `Cart_Handler::render_product_selector()` → `Product_Type::get_available_products()` queries products via taxonomy/SKU → `Product_Selector::render()` passes data to Twig template → JavaScript handles selection UI
|
||||
**Frontend Display:** `CartHandler::render_product_selector()` → `ProductType::get_available_products()` queries products via taxonomy/SKU → `ProductSelector::render()` passes data to Twig template → JavaScript handles selection UI
|
||||
|
||||
**Add to Cart:** Customer selects products → JS validates limit → AJAX request with `composable_products[]` → server-side validation (selection + stock) → selections stored in cart item data → price calculated per pricing mode
|
||||
|
||||
**Order Processing:** Order completed → `Stock_Manager` deducts inventory → order notes added for audit → on cancellation/refund: stock restored
|
||||
**Order Processing:** Order completed → `StockManager` deducts inventory → order notes added for audit → on cancellation/refund: stock restored
|
||||
|
||||
### Key Hooks
|
||||
|
||||
|
||||
Reference in New Issue
Block a user