backup
This commit is contained in:
parent
7e0aa41be6
commit
3247eed766
@ -74,23 +74,22 @@ class EcomZoneProductSync
|
||||
try {
|
||||
do {
|
||||
$catalog = $this->client->getCatalog($page, $perPage);
|
||||
$importedCount = 0;
|
||||
foreach ($catalog['data'] as $product) {
|
||||
$importedCount = 0;
|
||||
foreach ($catalog['data'] as $product) {
|
||||
if ($this->importSingleProduct($product)) {
|
||||
$importedCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$totalImported += $importedCount;
|
||||
$totalAvailable = $catalog['total'];
|
||||
$page++;
|
||||
$totalImported += $importedCount;
|
||||
$totalAvailable = $catalog['total'];
|
||||
$page++;
|
||||
|
||||
EcomZoneLogger::log("Imported page $page", 'INFO', [
|
||||
EcomZoneLogger::log("Imported page $page", 'INFO', [
|
||||
'total_imported' => $totalImported,
|
||||
'page' => $page,
|
||||
'total_available' => $totalAvailable
|
||||
]);
|
||||
|
||||
]);
|
||||
} while ($page <= ceil($totalAvailable / $perPage) && isset($catalog['next_page_url']) && $catalog['next_page_url'] !== null);
|
||||
|
||||
EcomZoneLogger::log("Finished importing products", 'INFO', [
|
||||
@ -109,7 +108,6 @@ EcomZoneLogger::log("Imported page $page", 'INFO', [
|
||||
'imported' => $totalImported,
|
||||
'total' => $totalAvailable
|
||||
];
|
||||
|
||||
} catch (Exception $e) {
|
||||
EcomZoneLogger::log("Error importing products: " . $e->getMessage(), 'ERROR');
|
||||
throw $e;
|
||||
@ -161,9 +159,9 @@ EcomZoneLogger::log("Imported page $page", 'INFO', [
|
||||
} else {
|
||||
$product->update();
|
||||
}
|
||||
StockAvailable::setQuantity($product->id, 0, (int)$data['stock']);
|
||||
$product->available_for_order = true; // Ensure product is available for order
|
||||
$product->show_price = true; // Ensure price is shown
|
||||
StockAvailable::setQuantity($product->id, 0, (int)$data['stock']);
|
||||
$product->available_for_order = true; // Ensure product is available for order
|
||||
$product->show_price = true; // Ensure price is shown
|
||||
|
||||
// Handle image import if URL is provided
|
||||
if (isset($data['image']) && !empty($data['image'])) {
|
||||
@ -179,7 +177,6 @@ $product->show_price = true; // Ensure price is shown
|
||||
]);
|
||||
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
EcomZoneLogger::log("Error importing product", 'ERROR', [
|
||||
'sku' => $data['sku'],
|
||||
@ -191,8 +188,8 @@ $product->show_price = true; // Ensure price is shown
|
||||
|
||||
|
||||
|
||||
private function importProductImage($product, $imageUrl)
|
||||
{
|
||||
private function importProductImage($product, $imageUrl)
|
||||
{
|
||||
try {
|
||||
// Create temporary file
|
||||
$tmpFile = tempnam(_PS_TMP_IMG_DIR_, 'ecomzone_');
|
||||
@ -251,7 +248,6 @@ private function importProductImage($product, $imageUrl)
|
||||
'sku' => $product->reference,
|
||||
'image' => $imageUrl
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
EcomZoneLogger::log("Error importing product image", 'ERROR', [
|
||||
'sku' => $product->reference,
|
||||
@ -259,12 +255,12 @@ private function importProductImage($product, $imageUrl)
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createDirectoryIfNotExists($directory)
|
||||
{
|
||||
private function createDirectoryIfNotExists($directory)
|
||||
{
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory, 0755, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user