Files
2meet-data-optimizer-hivepr…/includes/hivepress/adapters/class-tmdo-hivepress-marketplace-adapter.php
T
wpdev f089b0934b fix(2meet-data-optimizer-hivepress-addon): map marketplace hot field to hp_price
- hivepress-marketplace stores its filterable, sortable listing price as
  hp_price; hp_purchase_price never existed (dev34: 588 hp_price rows)
- Drop hp_purchase_count: the addon keeps no per-listing sales counter
- Remove the stale docblock note about the legacy core registration path

Verify: vendor/bin/phpunit --filter test_on_register_fields_registers_hot_hp_price;
  addon unit 156 OK, integration 57 OK
PR: PR-011
2026-09-25 22:39:57 +08:00

126 lines
3.2 KiB
PHP

<?php
/**
* Marketplace adapter — `hivepress-marketplace` (DETECT-ONLY in v3.0.0).
*
* The marketplace addon turns listings into purchasable items, integrating
* with WooCommerce. Its filterable, sortable listing attribute `price` is
* stored as `hp_price` → decimal(10,2), used in price-range filters (HOT).
*
* Its other listing attributes (price tiers / extras / discounts, quantity,
* subscription period, …) are not search filters, and it keeps no per-listing
* sales counter.
*
* Detect-only: not installed in dev environment. Schema reserved for the
* day the addon ships.
*
* @package WP_Data_Optimizer
* @since 3.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'TMDO_HivePress_Marketplace_Adapter' ) ) {
/**
* Marketplace addon adapter (detect-only).
*/
final class TMDO_HivePress_Marketplace_Adapter implements TMDO_HivePress_Adapter {
use TMDO_HivePress_Adapter_Trait;
/**
* Constructor — bind register hooks via inherited trait.
*/
public function __construct() {
$this->bind_anti_eav_hooks();
}
/** Adapter slug (matches wp.org plugin slug). */
public function plugin_slug(): string {
return 'hivepress-marketplace';
}
/** Class probed for addon presence. */
public function detection_class(): string {
return 'HivePress\\Marketplace\\Plugin';
}
/** Version constant probed for addon presence. */
public function detection_const(): string {
return 'HIVEPRESS_MARKETPLACE_VERSION';
}
/** Minimum addon version supported. */
public function minimum_addon_version(): string {
return '1.0.0';
}
/**
* Register marketplace hot fields on the listing post type.
*
* @param TMDO_Schema_Registry $registry Schema registry singleton.
*/
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
$registry->register_many(
$this->plugin_slug(),
array(
array(
'post_type' => 'hp_listing',
'meta_key' => 'hp_price',
'zone' => 'hot',
'data_type' => 'decimal(10,2) DEFAULT NULL',
'column' => 'hp_price',
'indexed' => true,
),
)
);
}
/**
* Doctor probe — verify hot column exists on listing hot table.
*
* @return array{ok:bool, message:string}
*/
public function doctor_check(): array {
global $wpdb;
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
return array(
'ok' => false,
'message' => 'wpdb global not available',
);
}
$table = $wpdb->prefix . 'wpdo_hot_hp_listing';
try {
$exists = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) );
return array(
'ok' => $exists,
'message' => $exists
? 'hivepress-marketplace: shares wp_wpdo_hot_hp_listing'
: 'hivepress-marketplace: hot listing table missing',
);
} catch ( \Throwable $e ) {
return array(
'ok' => false,
'message' => sprintf( 'hivepress-marketplace doctor failed: %s', $e->getMessage() ),
);
}
}
/**
* 8-D self-score.
*
* D8 reduced to 0.9 — index assumption is best-effort until addon installs.
*/
public function suitability_score(): array {
return $this->compose_score(
array(
'd8_perf' => 0.9,
)
);
}
}
} // end if ( ! class_exists )