| Server IP : 74.208.250.37 / Your IP : 216.73.216.114 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ubuntu 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : miferval ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/brainwavemx/app/Console/ |
Upload File : |
<?php
declare(strict_types=1);
namespace App\Console;
use App\Controller\Api\ApiController;
use App\Model\CategoriasModel;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Mosaico\BigCommerce\BaseApiHandlerV3;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CatalogCategoryUpdateCommand extends Command
{
protected function configure(): void
{
$this
->setName('catalog:category:update')
->setDescription('Assign BigCommerce Category Childs')
->setHelp('This command allows you Assign BigCommerce categoriy childs');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
new ApiController();
$categoriasModel = new CategoriasModel();
$categorias = (object) $categoriasModel->getCategoriesChild();
$array = [];
$httpMethod = 'PUT';
if ($categorias->num_rows > 0) :
$client = new BaseApiHandlerV3();
foreach ($categorias->rows as $value) {
$array = [
'id' => $value['id_bigcommerce'],
'parent_id' => $value['id_parent'],
'name' => $value['nombre_categoria'],
];
try {
$handler = HandlerStack::create();
$tapMiddleware = Middleware::tap(function ($request) {
echo $request->getBody() . "\r\n";
});
$response = $client->api()->request(
$httpMethod,
'catalog/categories/' . $value['id_bigcommerce'],
[
'headers' => [
'X-Auth-Token' => $client->token(),
],
'content-type' => 'application/json',
'json' => $array,
'handler' => $tapMiddleware($handler),
]);
$body = $response->getBody();
$category = json_decode((string) $body, true);
//print_r($category['data']);
if ($category) {
$categoriasModel->updateCategoriaIsUpdate((int) $value['id_categoria']);
$categoriasModel->updateCategoriaParent(
(int) $category['data']['parent_id'],
(int) $value['id_categoria']
);
$this->logInfo([
'status' => $response->getStatusCode(),
'categoria' => $value['nombre_categoria'],
'id' => $category['data']['id'],
]);
}
//$output->writeln($value['id_marca'] . '-' . $value['nombre_marca']);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$response = $e->getResponse();
$error = json_decode((string) $response->getBody());
$this->logError($error, $value);
}
}
endif;
return 0;
}
public function logError(object $error, array $categoria): void
{
$log = new Logger('ChildCategory');
$log->pushHandler(new StreamHandler(__DIR__ . '/../../logs/catalog/error-categoria.log', Logger::ERROR));
$errors = (array) $error->errors;
$log->error(
'status: ' . $error->status,
[
'title' => $error->title,
'id' => $categoria['id_categoria'],
]
);
}
public function logInfo(array $info)
{
$log = new Logger('ChildCategory');
$log->pushHandler(new StreamHandler(__DIR__ . '/../../logs/catalog/info-categoria.log', Logger::INFO));
$log->info(
'status: ' . $info['status'],
[
'Category Child: ' . $info['categoria'],
'BigCommerce ID: ' . $info['id'],
]
);
}
}