Add WooCommerce-style featured image and product gallery flow.
Deploy Ladill Woo Manager / deploy (push) Successful in 24s
Deploy Ladill Woo Manager / deploy (push) Successful in 24s
Sync full image sets through the plugin, with upload/URL support in the product editor and thumbnails in the list. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Services\Woo;
|
||||
|
||||
use App\Models\WooStore;
|
||||
use Illuminate\Http\Client\Response;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -32,6 +33,37 @@ class PluginClient
|
||||
return $this->raw($store, 'DELETE', $path)->successful();
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
public function uploadMedia(WooStore $store, UploadedFile $file, string $alt = ''): ?array
|
||||
{
|
||||
$site = rtrim((string) $store->site_url, '/');
|
||||
$url = $site.'/wp-json/ladill-woo/v1/media';
|
||||
|
||||
$response = Http::acceptJson()
|
||||
->timeout(60)
|
||||
->withHeaders(['X-Ladill-Store' => $store->public_id])
|
||||
->attach(
|
||||
'file',
|
||||
file_get_contents($file->getRealPath()) ?: '',
|
||||
$file->getClientOriginalName() ?: 'upload.jpg',
|
||||
)
|
||||
->post($url, array_filter(['alt' => $alt !== '' ? $alt : null]));
|
||||
|
||||
if (! $response->successful()) {
|
||||
Log::warning('Woo plugin media upload failed', [
|
||||
'store_id' => $store->id,
|
||||
'status' => $response->status(),
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var array<string, mixed>|null $json */
|
||||
$json = $response->json();
|
||||
|
||||
return is_array($json) ? $json : null;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
private function request(WooStore $store, string $method, string $path, array $data = []): ?array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user