fix: correct category-page size and brand/category source of truth

Two fixes bundled together:

1. Shrink CATEGORY_PAGE_SIZE from 100 to 25. Each item in a category page
   can trigger several sequential BC calls (location stock, price lists,
   brand/category lookup) beyond the page fetch itself - at 100 items/page
   this measured 150-250+ seconds on live data, exceeding PHP's execution
   limit and leaving the Action Scheduler action stuck "in-progress"
   forever instead of completing or failing visibly.

2. BC's Item Category table has no parent-category field - confirmed via
   the actual published CategProd endpoint (Code, Description only) and
   the standard itemCategories entity (id, code, displayName only). The
   original ItemCategoryHierarchy AL snippet assumed a Parent Category
   field that doesn't exist. Switched to the standard /itemCategories API
   for the brand display name (no custom endpoint needed for that part),
   and replaced the BC-side parent-category walk with a WordPress-side
   manual map (wbc_category_parent_map: "CODE=Parent Name" per line) for
   the WooCommerce product category grouping, since BC has nothing to
   offer there.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-09 14:41:59 +02:00
parent 0a08086272
commit 8f45ccbee4
4 changed files with 83 additions and 29 deletions

View File

@@ -86,6 +86,9 @@ class WBC_Admin {
register_setting( 'wbc_sync', 'wbc_enable_brand_sync', array(
'sanitize_callback' => array( $this, 'sanitize_checkbox' ),
) );
register_setting( 'wbc_sync', 'wbc_category_parent_map', array(
'sanitize_callback' => 'sanitize_textarea_field',
) );
// Order settings (own group)
register_setting( 'wbc_orders', 'wbc_enable_order_sync', array(

View File

@@ -233,10 +233,23 @@ $tabs = array(
<label>
<input type="checkbox" name="wbc_enable_brand_sync" value="yes"
<?php checked( get_option( 'wbc_enable_brand_sync', 'no' ), 'yes' ); ?> />
<?php esc_html_e( 'Sync BC item category to the product_brand taxonomy, and its parent category to the WooCommerce product category', 'woo-business-central' ); ?>
<?php esc_html_e( 'Sync BC item category to the product_brand taxonomy', 'woo-business-central' ); ?>
</label>
<p class="description">
<?php esc_html_e( 'Requires the custom ItemCategoryHierarchy OData endpoint and the WooCommerce Brands plugin (product_brand taxonomy).', 'woo-business-central' ); ?>
<?php esc_html_e( 'Uses the standard itemCategories API. Requires the WooCommerce Brands plugin (product_brand taxonomy).', 'woo-business-central' ); ?>
</p>
</td>
</tr>
<tr>
<th scope="row">
<label for="wbc_category_parent_map"><?php esc_html_e( 'Category Parent Map', 'woo-business-central' ); ?></label>
</th>
<td>
<textarea id="wbc_category_parent_map" name="wbc_category_parent_map"
class="large-text code" rows="6"
placeholder="DAVINES=Haircare&#10;OBAGI=Skincare"><?php echo esc_textarea( get_option( 'wbc_category_parent_map', '' ) ); ?></textarea>
<p class="description">
<?php esc_html_e( 'Optional. One "CODE=Parent Category Name" pair per line. Business Central\'s item categories here are flat (no parent-category field), so the WooCommerce product category grouping (e.g. brand "Davines" under category "Haircare") is maintained here rather than pulled from BC. Leave empty to skip - only the brand taxonomy will be set.', 'woo-business-central' ); ?>
</p>
</td>
</tr>