msOrderFiles

Attaching files to the miniShop2 order
The author
Павел
Packages
32
Downloads
44 005
Usually answers within a few days
Автор дополнения
Packages
32
Downloads
44 005
Usually answers within a few days
Version 1.1.7-beta
Release date 06.26.2020
Downloads 207
Views 2 752
Warning! This component requires PHP version 5.4 or higher! If your site uses PHP less than required, the installation of this package could break it.
Warning! This package requires MODX not less than 2.3 !


The component is designed to attach files to the order miniShop2, both from the back-end, and from the front-end.
In the back end, files are displayed on the tab built into the edit box of the miniShop2 order.

As you know, after placing an order by an anonymous user, the user is created at the specified email when ordering. So this user is attached to the files that were downloaded when placing an order.

Creating the file download form
It's best to place the snippet in chunk tpl.msOrder so that the form is not displayed in the empty basket.

MsofForm snippet options:

  • tpl — Template call form,
  • order — Order ID. By default, 0,
  • user — User ID. By default the current one,
  • source — The source of the files. By default, it is specified from the msof_source setting,
  • anonym — Allow anonymous users to use the form,
  • dropzone — An array Dropzone parameters, you can JSON,
  • maxFiles — Maximum number of files. By default 2,
  • maxFilesize — The maximum file size in MB. Default is 2.

Example of a call:

{'!msofForm' | snippet : [
    'maxFiles' => 20,
    'maxFilesize' => 10,
    'anonym' => false,
]}

Important

To allow the user to download files from the front end, add the msOrderFilesPolicy access policy to the group. The same applies to the anonymous authors.

Creating files in a letter to the user / manager
In the right place of the letter template, we write a pdoResources snippet call with our msOrderFiles model:

{'!pdoResources' | snippet : [
    'class' => 'msOrderFile',
    'loadModels' => 'msOrderFiles',
    'where' => [
        'order_id' => $order['id'],
        'active' => 1,
    ],
    'sortby' => '{"rank":"ASC"}',
    'tplWrapper' => '@INLINE <ul>{$output}</ul>',
    'tpl' => '@INLINE <li><a href="{("site_url" | option) ~ $url}">{$name}</a></li>',
]}

It is important to consider that this solution is 100% working for miniShop2 >= 2.4, because was checked only on it. Although you can try to combine with earlier versions of the store, most likely, even without significant edits.

List of order files
To display the list of files of a specific order (for example, in the user's personal cabinet), you need to use the pdoResources snippet:
{'!pdoResources' | snippet : [
    'class' => 'msOrderFile',
    'loadModels' => 'msOrderFiles',
    'where' => [
        'active' => 1,
        'order_id' => 10,
    ],
    'sortby' => '{"rank":"ASC"}',
    'tplWrapper' => '@INLINE <ul>{$output}</ul>',
    'tpl' => '@INLINE
        <li><a href="{$url}">{$name}</a></li>
    ',
]}


Placeholders for the parameter tpl

  • id — id of the order file,
  • order_id — order id in ms2,
  • source — id of the source of files,
  • name — the name of the file,
  • description — description of the file,
  • file — the name of the file with the extension,
  • url — the path to the file, starting from the root of the site,
  • mime — the file type, according to the MIME standard,
  • ext — file extension,
  • hash — hash, which is used to compare the uniqueness of the downloaded file,
  • size — the size of the file in bytes,
  • createdon — the date the file was downloaded,
  • createdby — the id of the user who uploaded the file,
  • rank — the position number of the file in the list,
  • active — whether the file is active.


MsOrderFiles source file


In the source file, in addition to the standard settings (basePath, baseUrl), you can specify:

  • allowedFileTypes — a list of file extras that can be downloaded,
  • fileNameType — familiar to many of ms2Gallery, means the method of renaming a file,
  • positionNewFiles — position of new files in the list. In other words, where to upload new files: to the beginning or to the end.

The author thanks Mikhail Voevodsky for the idea of the extra.
Thread in MODX.PRO community.

1.1.7-beta (26.06.2020)

  • Добавлено удаление пустой папки из под файлов

1.1.6-beta (18.06.2020)

  • Добавлен сниппет msofList

1.1.5-beta2 (20.09.2018)

  • Поправлена передача параметра &timeout в JS

1.1.5-beta (20.09.2018)

  • Добавлен параметр &timeout у сниппета msofForm для указания ожидания запроса на загрузку файла, по-умолчанию 90000

1.1.4-beta (15.08.2018)

  • Добавлена работа с облаком
  • Поправлена ошибка подгрузки файлов при наличии нескольких форм компонента на странице

1.1.3-beta (15.08.2018)

  • Исправлен способ инициализации JS класса для копии формы, теперь напрямую в JS передаётся propkey

1.1.2-beta (11.04.2018)

  • Добавлен сброс кеша состояния файлов

1.1.1-beta (02.08.2017)

  • Поправлен баг на фронте, когда список файлов не очищался после оформления заказа
  • Поправлено удаление объектов файлов заказа при удалении связанного объекта msOrder
  • Небольшой рефакторинг

1.1.0-beta2 (26.12.2016)

  • Поправлен баг на MODX ниже 2.5.2, когда из фронт-энда ключ сортировки не передавался и SQL запрос из-за этого крашился

1.1.0-beta (26.12.2016)

  • Добавлена загрузка файлов из фронт-энда
  • Рефакторинг кода
  • Стилизация внешнего вида в бек-энде

1.0.2-beta2 (23.12.2016)

  • Поправлена совместимость с PHP 5.3

1.0.2-beta (20.12.2016)

  • Добавлено удаление файлов из базы при удалении связанного заказа
  • Подкорректирован внешний вид таблицы файлов заказа в бек-энде

1.0.1-beta3 (29.10.2016)

  • Поправлен тип поля rank в базе

1.0.1-beta2 (28.10.2016)

  • Поправлена подстановка базового пути в файл при аплоаде
  • При обновлении файла через процессор mgr/file/update добавлена возможность заменить файл новой версией

1.0.1-beta (28.10.2016)

  • Добавлена возможность добавлять файлы, не загруженные методом HTTP POST, через процессор mgr/file/upload

1.0.0-beta (09.09.2016)

  • Start