RECORDGOD/wp-bridge/includes/class-rg-shipping.php
type-two 5ad4de1d2c feat(bridge): RecordGod WP bridge plugin (WowPlatter successor) + thumb on browse/release
Thin WordPress/Woo bridge — RecordGod owns catalog/stock/pricing/shipping; the plugin is a storefront
skin + checkout adapter over /shop:
- storefront: SSR /records (browse) + /release/{id} inside the theme, with title/meta/JSON-LD MusicAlbum
- on-the-fly Woo product: /?rg_add=<sku> mints a hidden WC_Product_Simple from /shop/item (the WowPlatter
  trick — 25k catalog, only sold items become Woo products)
- shipping: WC_Shipping_Method quoting /shop/shipping/quote by cart item count (AusPost flat rate)
- orders: order_status_completed -> POST /shop/woo-order (X-Bridge-Key), idempotent, marks SKUs sold
- settings page: base URL + bridge key + store id
Backend: added thumb to /shop/browse + /shop/release so storefront pages have cover art.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 01:43:30 +10:00

49 lines
1.8 KiB
PHP

<?php
if (!defined('ABSPATH')) exit;
/** Woo shipping method that quotes postage from RecordGod (record-count → AusPost flat rate). */
class RG_Shipping extends WC_Shipping_Method {
function __construct($instance_id = 0) {
$this->id = 'recordgod';
$this->instance_id = absint($instance_id);
$this->method_title = 'RecordGod Postage';
$this->method_description = 'Live AusPost flat-rate quote from RecordGod (Parcel / Express Post).';
$this->supports = ['shipping-zones', 'instance-settings', 'settings'];
$this->init();
}
function init() {
$this->init_form_fields();
$this->init_settings();
$this->enabled = $this->get_option('enabled', 'yes');
$this->title = $this->get_option('title', 'Postage');
add_action('woocommerce_update_options_shipping_' . $this->id, [$this, 'process_admin_options']);
}
function init_form_fields() {
$this->instance_form_fields = [
'enabled' => ['title' => 'Enable', 'type' => 'checkbox', 'default' => 'yes'],
'title' => ['title' => 'Title', 'type' => 'text', 'default' => 'Postage'],
];
}
function calculate_shipping($package = []) {
$units = 0;
foreach ($package['contents'] as $line) $units += (int) $line['quantity'];
if ($units < 1) return;
$q = RG_API::get('/shop/shipping/quote', ['units' => $units], 30);
if (!$q || empty($q['options'])) return;
foreach ($q['options'] as $opt) {
$this->add_rate([
'id' => $this->id . ':' . $opt['service'],
'label' => $opt['label'],
'cost' => (float) $opt['price'],
'calc_tax' => 'per_order',
]);
}
}
}