Ich erstelle vorerst ein Plugin, um Produktdaten und reguläre Preis zu aktualisieren. Ich verwende den Batch -Update -API -Endpunkt wie folgt. Ich verwende eine CSV-Datei mit 3 Spaltenprodukt-SKU, Aktien und regulärem Preis, um meine Website mit WC Rest API (Home_url ('/WP-JSON/WC/V3/Products/Batch') zu aktualisieren. Datenanlage (wie die in der WC-REST-API-Dokumentation angegebene Produkte 100 Produkte verwendet). PrettyPrint-Override "> private function sendBatchRequest($data) {
$ch = curl_init($this->apiUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_USERPWD => $this->apiKey . ':' . $this->apiSecret,
CURLOPT_TIMEOUT => 60
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [
'success' => ($httpCode >= 200 && $httpCode < 300),
'response' => json_decode($response, true),
'http_code' => $httpCode
];
}
public function processStockFile() {
$products = $this->parseCSV();
/* parseCSV returns
$products[] = [
'sku' => trim($data[0]), // Product SKU
'id' => $id, // Product id
'stock' => !empty($data[1]) ? (int)trim($data[1]) : 0, // Stock quantity
'price' => !empty($data[2]) ? wc_format_decimal(str_replace(',', '.', trim($data[2]))) : 0//!empty($data[2]) ? (float)$data[2] : 0, // Product price
];
*/
$chunks = array_chunk($products, 50); // split into 50 products per batch
$results = [];
foreach ($chunks as $chunk) {
$data = ['update' => []];
foreach ($chunk as $product) {
$data['update'][] = [
'id' => $product['id'],
'sku' => $product['sku'],
'stock_quantity' => $product['stock'],
'regular_price' => $product['price'],
];
}
$results[] = $this->sendBatchRequest($data);
//used sleep(1) here did not change
}
return $results;
}
< /code>
Ich habe versucht, die Curl -Anfrage zu pausieren, bevor ich eine andere (mit PHP Sleep () und us im Sleep ()), aber ohne Erfolg, gesendet habe. Gibt es ohnehin, um dieses Grenze zu erhöhen (was ich versucht habe, hat in meinem Fall nicht funktioniert) oder vielleicht die zu senden, nach der vorherigen Antwort zu senden und weiterzumachen.>
WooCommerce Products Batch -Update -Begrenzung: So aktualisieren Sie mehr ⇐ Php
-
- Similar Topics
- Replies
- Views
- Last post