1
0
Fork 0
mirror of synced 2025-04-02 21:36:14 +03:00

add upload function

This commit is contained in:
ellynoize 2024-12-19 14:25:10 +03:00
parent cdc7ca71bc
commit 0873df325c
2 changed files with 49 additions and 1 deletions

View file

@ -111,6 +111,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
add_action('admin_enqueue_scripts', [$this, 'include_files_for_admin'], 101);
add_action('woocommerce_new_order', [$this, 'fill_array_create_orders'], 11, 1);
add_action('shutdown', [$this, 'create_order'], -2);
add_action('wp_console_upload', [$this, 'console_upload'], 99, 2);
if (
!$this->get_option('deactivate_update_order')
@ -174,6 +175,10 @@ if (!class_exists('WC_Retailcrm_Base')) {
$this->activateModule();
}
public function console_upload($entity, $page = 0)
{
$this->uploader->uploadConsole($entity, $page);
}
/**
* Init settings fields
*/

View file

@ -234,5 +234,48 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
);
}
}
public function uploadConsole($entity, $page = 0)
{
$ordersCount = $this->getCountOrders();
$customerCount = $this->getCountUsers();
$ordersPages = (int)($ordersCount / 50) + (($ordersCount % 50 === 0) ? -1 : 0);
$customerPages = (int)($customerCount / 50) + (($customerCount % 50 === 0) ? -1 : 0);
echo $customerPages;
try {
switch ($entity) {
case 'orders':
$this->ArchiveUpload('orders', $page, $ordersPages);
break;
case 'customers':
$this->ArchiveUpload('customers', $page, $customerPages);;
break;
case 'full_upload':
$this->ArchiveUpload('orders', 0, $ordersPages);
$this->ArchiveUpload('customers', 0, $customerPages);
break;
default:
echo 'Unknown entity: ' . $entity;
}
} catch (Exception $exception) {
echo $exception->getMessage();
}
}
public function archiveUpload($entity, $page, $countPages)
{
for ($i = $page; $i <= $countPages; $i++) {
if ($entity === 'orders') {
$this->uploadArchiveOrders($i);
echo $page . ' page uploaded' . PHP_EOL;
} elseif ($entity === 'customers') {
$this->uploadArchiveCustomers($i);
echo $page . ' page uploaded' . PHP_EOL;
}
}
}
}
}//end if
}