Answer the question
In order to leave comments, you need to log in
What are the permissions for the 'resource/create' processor in modx?
Hello. I was faced with the task of processing an excel file and loading goods into the modx database, where the mihishop2 component was installed.
I created a template in which I simply displayed a form for selecting a file. The template checks for authorization in the admin panel by the manager or admin. Otherwise, the form is not displayed.
The manager loads the file, presses the "check" button, then I pull the written processor through ajax, which processes the file, uploads it to the server in a specific folder with a specific name and displays some kind of presentation to the user so that he understands that everything was considered correct and the Excel file of the desired format.
After that, the "start import" button appears, which pulls another processor to import goods from a file.
This is done via modx->runProcessor('resource/create', $options);
In more detail, then:
//получаем массив артикулов
foreach ($prods as $prod) {
array_push($vendor_codes, $prod->get('article'));
}
// var_dump($vendor_codes);
$count = 0;
$duplicate = 0;
//проходимся по товарам из эксель файла, сравнивая артикулы с имеющимися, если совпадение есть, не добавляем
foreach ($array as $item) {
//если еще нет в базе, добавляем
if(!in_array($item['vendor_code'], $vendor_codes)) {
$options = array();
//создаем товар
$options = array(
'class_key' => 'msProduct',
'pagetitle' => $item['title'],
'parent' => $category,
'template' => 2,
'show_in_tree' => 0,
'alias' => $item['vendor_code'],
'price' => $item['price'],
'old_price' => $item['old_price'],
'favorite' => 0,
'popular' => 0,
'color' => array($item['color']),
'article' => $item['vendor_code'],
'weight' => $item['weight'],
'made_in' => $item['country'],
'serial_num' => $item['barcode'],
'package_width' => $item['width'],
'package_height' => $item['height'],
'package_length' => $item['length'],
'guarantee' => $item['guarantee'],
'shelf_life' => $item['shelf_life'],
'life_time' => $item['life_time'],
'content' => $item['description']
);
//добавляем доп опции в зависимости от категории
if ($category == 10) {
// если термосы
$options['options-volume'] = $item['volume'];
}
// var_dump($options);
// exit();
$response = $this->modx->runProcessor('resource/create', $options);
$count++;
}else{
$duplicate++;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question