Skip to content

Commit 760444c

Browse files
author
Soare Robert-Daniel
committed
dev: extend tests
1 parent 46d250c commit 760444c

11 files changed

Lines changed: 926 additions & 43 deletions

AGENTS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ You can read more about it on `./ARCHITECTURE.md`, but here’s a high-level ove
5959

6060
`woocommerce-product-addon.php` — defines constants, loads Composer autoload, manually `require_once`s all class/include files (no PSR-4 autoloading for plugin code), then hooks `PPOM()` on `woocommerce_init`.
6161

62-
### Core Classes (all singleton pattern via `get_instance()`)
62+
### Core Classes
6363

6464
| Class | File | Role |
6565
|---|---|---|
6666
| `NM_PersonalizedProduct` | `classes/plugin.class.php` | Main plugin — registers all WooCommerce hooks, loads input types |
67-
| `NM_PersonalizedProduct_Admin` | `classes/admin.class.php` | Admin-only — loaded only in `is_admin()` |
68-
| `PPOM_Meta` | `classes/ppom.class.php` | Field group CRUD against custom DB table |
67+
| `NM_PersonalizedProduct_Admin` | `classes/admin.class.php` | Admin-only coordinator for menus, settings, attach flows, and admin AJAX |
68+
| `PPOM_Meta` | `classes/ppom.class.php` | Product-side field-group resolver that reads attached groups and loads settings/fields from the custom DB table |
6969
| `PPOM_Form` | `classes/form.class.php` | Frontend form rendering |
70-
| `PPOM_Fields_Meta` | `classes/fields.class.php` | Field type registry and metadata |
70+
| `PPOM_Fields_Meta` | `classes/fields.class.php` | Admin field-builder UI, modals, and builder asset loading |
7171
| `PPOM_Inputs` | `classes/input.class.php` | Input type manager |
7272

7373
### Input Type System

architecture.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ The plugin is not PSR-4 for its runtime code. The main file manually includes th
6464
| --- | --- | --- |
6565
| Bootstrap | [`woocommerce-product-addon.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/woocommerce-product-addon.php) | Defines constants, loads the plugin, registers top-level hooks |
6666
| Main runtime | [`classes/plugin.class.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/classes/plugin.class.php) | Registers WooCommerce hooks for rendering, validation, pricing, cart, orders, admin AJAX, cron, and loop behavior |
67-
| Product field resolver | [`classes/ppom.class.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/classes/ppom.class.php) | Resolves applicable PPOM field groups for a product and loads settings and fields from the custom DB table |
67+
| Product field resolver | [`classes/ppom.class.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/classes/ppom.class.php) | Resolves applicable PPOM field groups for a product, merges their fields, and derives the runtime settings row from the custom DB table |
6868
| Frontend form renderer | [`classes/form.class.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/classes/form.class.php) | Renders modern template-based product fields and hidden runtime state |
6969
| Input registry | [`classes/input.class.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/classes/input.class.php) | Loads input-type classes and add-on input classes |
7070
| Admin field UI | [`classes/fields.class.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/classes/fields.class.php) | Powers the field-group builder UI and admin-side assets |
71+
| Admin coordinator | [`classes/admin.class.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/classes/admin.class.php) | Registers PPOM admin menus, settings integration, attach flows, and admin initialization hooks |
7172
| Frontend asset loader | [`classes/frontend-scripts.class.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/classes/frontend-scripts.class.php) | Registers and localizes frontend JS and CSS for pricing, uploads, validation, conditions, and field widgets |
73+
| Script registry | [`classes/scripts.class.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/classes/scripts.class.php) | Shared wrapper for registering, enqueuing, localizing, and inlining PPOM frontend assets |
7274
| WooCommerce flow functions | [`inc/woocommerce.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/inc/woocommerce.php) | Product-page rendering, validation, cart item payloads, order item metadata, file finalization |
7375
| Pricing engine | [`inc/prices.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/inc/prices.php) | Server-side option pricing, matrix pricing, cart fee calculation, line-item price updates |
7476
| Upload subsystem | [`inc/files.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/inc/files.php) | AJAX upload and delete handlers, thumbnails, cropped files, confirmed-file storage, cleanup cron |
@@ -88,7 +90,7 @@ Each row contains both group-level settings and the full field definition payloa
8890
- `productmeta_style`
8991
- `productmeta_js`
9092
- `productmeta_categories`
91-
- `productmeta_tags`
93+
- `productmeta_tags` when extensions or add-ons use tag-aware assignment
9294
- `the_meta` as JSON
9395

9496
Products are linked to PPOM groups through the normal post meta key:
@@ -97,14 +99,14 @@ Products are linked to PPOM groups through the normal post meta key:
9799

98100
That value may contain one or more field-group IDs.
99101

100-
`PPOM_Meta` is the resolution layer. For a given product, it:
102+
`PPOM_Meta` is the read-side resolution layer. For a given product, it:
101103

102104
1. reads `_product_meta_id`
103105
2. checks category-linked groups
104106
3. merges or overrides group IDs through filters
105107
4. loads the matching row or rows from the custom table
106-
5. decodes `the_meta` into the active field list
107-
6. exposes group settings such as inline CSS, inline JS, price-display mode, and group title
108+
5. merges field definitions from all matched groups
109+
6. derives one active settings row for runtime values such as inline CSS, inline JS, price-display mode, and group title
108110

109111
```mermaid
110112
flowchart TD
@@ -116,8 +118,8 @@ flowchart TD
116118
E --> F["Apply merge / override filters"]
117119
F --> G["Load rows from {prefix}_nm_personalized"]
118120
G --> H["Decode the_meta JSON"]
119-
H --> I["Active PPOM fields"]
120-
H --> J["Group settings"]
121+
H --> I["Merged active PPOM fields"]
122+
H --> J["Derived runtime settings row"]
121123
I --> K["Frontend rendering"]
122124
I --> L["Validation and pricing lookup"]
123125
J --> M["Inline CSS / JS / display mode"]
@@ -220,7 +222,7 @@ The modern path renders:
220222

221223
- the active field groups
222224
- a price-table container
223-
- hidden inputs for group IDs, current product ID, option-price state, conditional-hide state, and cart-edit state
225+
- hidden inputs and wrapper state through `PPOM_Form::form_contents()`
224226

225227
That hidden form state is what keeps the frontend JS and backend PHP in sync.
226228

@@ -361,12 +363,14 @@ The admin side has two main responsibilities:
361363
- field-group CRUD
362364
- settings and permissions
363365

364-
Field-group management is provided by `NM_PersonalizedProduct_Admin`, `PPOM_Fields_Meta`, and the AJAX CRUD handlers in [`inc/admin.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/inc/admin.php). That layer lets admins:
366+
Field-group management is split across `NM_PersonalizedProduct_Admin`, `PPOM_Fields_Meta`, and the AJAX CRUD handlers in [`inc/admin.php`](/Users/robert/Desktop/sites/plugins-dev/web/app/plugins/woocommerce-product-addon/inc/admin.php):
365367

366368
- create, edit, clone, and delete field groups
367369
- bulk-attach field groups to products
368370
- choose which group is attached on the product edit screen
369371

372+
`PPOM_Meta` is not the CRUD layer. It resolves product-side field groups and reads their settings/fields at runtime.
373+
370374
Settings use two storage models:
371375

372376
- legacy WooCommerce settings-tab storage
@@ -435,7 +439,7 @@ The API supports:
435439
- updating order PPOM metadata
436440
- deleting order PPOM metadata
437441

438-
The important implementation detail is that the routes use open permission callbacks, but write operations validate a PPOM secret key inside the handler. That makes the API optional and configuration-gated, but still part of the plugin's public integration surface.
442+
The important implementation detail is that the routes use open permission callbacks, while write operations validate a PPOM secret key inside the handler. That makes the API optional and configuration-gated, but still part of the plugin's public integration surface.
439443

440444
## Extension and Compatibility Model
441445

@@ -473,7 +477,7 @@ PPOM stores data in several WordPress and WooCommerce persistence layers.
473477
### Custom database table
474478

475479
- `{prefix}_nm_personalized`
476-
Stores PPOM field-group definitions and group-level settings such as `productmeta_name`, `dynamic_price_display`, `productmeta_style`, `productmeta_js`, category/tag assignment, and `the_meta` JSON.
480+
Stores PPOM field-group definitions and group-level settings such as `productmeta_name`, `dynamic_price_display`, `productmeta_style`, `productmeta_js`, category assignment, optional tag data for extensions/add-ons, and `the_meta` JSON.
477481

478482
### WordPress post meta
479483

classes/admin.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717

1818
/**
19-
* Coordinates the PPOM admin UI and field-group attachment workflows.
19+
* Coordinates the PPOM admin UI, settings flows, and field-group attachment workflows.
2020
*
2121
* Registers the PPOM menu pages, AJAX attach handlers, legacy WooCommerce
2222
* settings tab, and admin initialization hooks that prepare the PPOM schema.

classes/form.class.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,31 @@
1717
*/
1818
class PPOM_Form {
1919

20-
private static $ins = null;
21-
2220
/**
23-
* Return all ppom attach meta data
21+
* Resolved PPOM metadata for the current product render.
2422
*
25-
* @var array
23+
* @var PPOM_Meta
2624
*/
2725
public static $ppom;
2826

2927
/**
30-
* Return the product ID
28+
* Current product ID.
3129
*
32-
* @var number
30+
* @var int
3331
*/
3432
public $product_id;
3533

3634
/**
37-
* Return wc product object
35+
* Current WooCommerce product object.
3836
*
39-
* @var object
37+
* @var WC_Product
4038
*/
4139
public $product;
4240

4341
/**
44-
* Return templates args
42+
* Rendering arguments passed to the form template.
4543
*
46-
* @var array
44+
* @var array|null
4745
*/
4846
public static $args;
4947

@@ -58,14 +56,6 @@ function __construct( $product, $args ) {
5856
self::$args = $args;
5957
}
6058

61-
public static function get_instance() {
62-
63-
// create a new object if it doesn't exist.
64-
is_null( self::$ins ) && self::$ins = new self();
65-
66-
return self::$ins;
67-
}
68-
6959
/**
7060
* PPOM main wrapper 2 classes
7161
*

classes/input.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Loads PPOM input classes and frontend asset dependencies.
3+
* Loads PPOM input classes and optional add-on input classes.
44
*
55
* @package PPOM
66
* @subpackage Inputs
@@ -9,7 +9,7 @@
99
*/
1010

1111
/**
12-
* Loads PPOM input classes and their script registrations.
12+
* Loads PPOM input classes and related add-on integrations.
1313
*/
1414
class PPOM_Inputs {
1515

classes/ppom.class.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
/**
10-
* Resolves product-level PPOM metadata.
10+
* Resolves product-level PPOM metadata for frontend and cart/order flows.
1111
*
1212
* @since version 15.0
1313
*/
@@ -18,23 +18,26 @@ class PPOM_Meta {
1818
public static $product_id;
1919

2020
/**
21-
* Plugin category data.
21+
* Resolved category-based PPOM group IDs for the current product.
2222
*
2323
* @var array $category_meta
2424
*/
2525
public $category_meta = array();
2626

2727
/**
28-
* Plugin category array.
28+
* Candidate group rows that include category or tag assignments.
29+
*
30+
* Tags are fetched here as stored data, but core resolution matches
31+
* categories directly and leaves tag-based behavior to extension filters.
2932
*
3033
* @var array $ppom_categories_and_tags_row
3134
*/
3235
public $ppom_categories_and_tags_row = array();
3336

3437
/**
35-
* Plugin settings.
38+
* Runtime settings row selected from the resolved PPOM groups.
3639
*
37-
* @var array $ppom_settings
40+
* @var object|array $ppom_settings
3841
*/
3942
public $ppom_settings = array();
4043

0 commit comments

Comments
 (0)