/i', "\n", $desc); $desc = preg_replace('/<\/p>/i', "\n\n", $desc); $desc = strip_tags($desc); $desc = html_entity_decode($desc, ENT_QUOTES | ENT_HTML5, 'UTF-8'); $desc = trim(preg_replace('/\n{3,}/', "\n\n", $desc)); $payload = [ 'title' => html_entity_decode($product['name'], ENT_QUOTES | ENT_HTML5, 'UTF-8'), 'description' => $desc, 'sku' => $product['model'], 'inventory' => max(0, (int)$product['quantity']), 'has_inventory' => true, 'handmade' => !empty($reverb_data['handmade']), 'upc_does_not_apply' => !isset($reverb_data['upc_does_not_apply']) || (bool)$reverb_data['upc_does_not_apply'], 'price' => [ 'amount' => number_format((float)$product['price'], 2, '.', ''), 'currency' => $currency, ], ]; if (!empty($product['manufacturer'])) { $payload['make'] = $product['manufacturer']; } if (!empty($reverb_data['condition_uuid'])) { $payload['condition'] = ['uuid' => $reverb_data['condition_uuid']]; } if (!empty($reverb_data['reverb_category_uuid'])) { $payload['categories'] = [['uuid' => $reverb_data['reverb_category_uuid']]]; } if (!empty($reverb_data['origin_country_code'])) { $payload['origin_country_code'] = strtoupper($reverb_data['origin_country_code']); } // Shipping rates $rates = []; if (!empty($settings['shipping_domestic'])) { $rates[] = [ 'region_code' => 'AU', 'rate' => [ 'amount' => number_format((float)$settings['shipping_domestic'], 2, '.', ''), 'currency' => $currency, ], ]; } if (!empty($settings['shipping_international'])) { $rates[] = [ 'region_code' => 'XX', 'rate' => [ 'amount' => number_format((float)$settings['shipping_international'], 2, '.', ''), 'currency' => $currency, ], ]; } if ($rates) { $payload['shipping'] = ['rates' => $rates]; } return $payload; } /** * Extract updatable OC product fields from a Reverb listing payload * (used for Reverb → OpenCart sync). * * @param array $listing A listing object from the Reverb API. * @return array Partial product data to merge into OC. */ public static function fromReverb(array $listing) { $data = []; if (isset($listing['title'])) { $data['name'] = $listing['title']; } if (isset($listing['description'])) { $data['description'] = $listing['description']; } if (isset($listing['price']['amount'])) { $data['price'] = (float)$listing['price']['amount']; } if (isset($listing['inventory'])) { $data['quantity'] = (int)$listing['inventory']; } return $data; } /** * Build photo upload payloads for a product's images. * * @param array $images Array of image paths relative to OC image dir. * @param string $store_url Full base URL of the store (e.g. https://example.com/). * @return array Array of ['image_url' => '...'] payloads. */ public static function buildPhotoPayloads(array $images, $store_url) { $payloads = []; $base = rtrim($store_url, '/') . '/image/'; foreach ($images as $path) { if (!empty($path)) { $payloads[] = ['image_url' => $base . ltrim($path, '/')]; } } return $payloads; } }