M
M
Maxim Shadrin2021-07-19 10:49:55
MODX
Maxim Shadrin, 2021-07-19 10:49:55

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.

60f529b518f57433016694.png

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.

60f52babdc534341500111.png

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++;
      }
    }


And this code works, the processor gives the number of downloaded files and the number of files that already existed in the database. Checks by article.
There is only one catch, if I am logged in as an administrator, then everything works. Files are processed, data is written to the database, goods appear. If I am logged in as a manager, then visually the webmord does not differ in any way, the processor for processing the Excel file works, the file is loaded where it needs to be, and the next import processor works with it. The answer from the processor also comes, it counts how many goods have been loaded. There is only one problem, the goods are not added after the fact. They are not in the database. I'm catching the "permission_denied_processor" error.
Moreover, even adding administrator access rights to the "manager" user does not help.
What rights are missing, I'll never know.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question