Павел

Павел

Был в сети 22 июля 2020, 13:56
Заказы принимаю
Спасибо, но уже реализовал… конечно не корректно, потом поправлю (так как при обновлении все затрётся).

Поправил метод changeOrderStatus, а именно для менеджеров
if ($status->get('email_manager')) {
                $subject = $this->pdoTools->getChunk('@INLINE ' . $status->get('subject_manager'), $pls);
                $tpl = '';
                if ($chunk = $this->modx->getObject('modChunk', $status->get('body_manager'))) {
                    $tpl = $chunk->get('name');
                }
                $body = $this->modx->runSnippet('msGetOrder', array_merge($pls, array('tpl' => $tpl)));
                $emails = array_map('trim', explode(',',
                        $this->modx->getOption('ms2_email_manager', null, $this->modx->getOption('emailsender')))
                );
                
                // Получаем файл
                $attachment = $order->get('properties')["excelfile"];
                
                if (!empty($subject)) {
                    foreach ($emails as $email) {
                        if (preg_match('#.*?@.*#', $email)) {
			    //$this->sendEmail($email, $subject, $body);
                            $this->sendEmail($email, $subject, $body, $attachment);
                        }
                    }
                }
            }

Затем поправил метод sendEmail

public function sendEmail($email, $subject, $body = '', $attachment)
    {
        $this->modx->getParser()->processElementTags('', $body, true, false, '[[', ']]', array(), 10);
        $this->modx->getParser()->processElementTags('', $body, true, true, '[[', ']]', array(), 10);

        /** @var modPHPMailer $mail */
        $mail = $this->modx->getService('mail', 'mail.modPHPMailer');
        $mail->setHTML(true);

        $mail->address('to', trim($email));
        $mail->set(modMail::MAIL_SUBJECT, trim($subject));
        $mail->set(modMail::MAIL_BODY, $body);
        $mail->set(modMail::MAIL_FROM, $this->modx->getOption('emailsender'));
        $mail->set(modMail::MAIL_FROM_NAME, $this->modx->getOption('site_name'));
        $mail->attach(MODX_BASE_PATH.'assets/'.$attachment);
                                
        if (!$mail->send()) {
            $this->modx->log(modX::LOG_LEVEL_ERROR,
                'An error occurred while trying to send the email: ' . $mail->mailer->ErrorInfo
            );
        }
        $mail->reset();
    }
Конечно бы разобраться стоит, как правильно расширять, буду благодарен, если кто подскажет корректное решение, а так всё работает.
Вызываю так:
Ваш город:
<span class="gl-current-select">[[!+gl.current.city.name_ru:is=`По умолчанию`:then=`Щёлково`:else=`[[!+gl.current.city.name_ru]]`]]</span>
            [[!gl.modal?
            	&modalShow=`0`
            	&class=`glCity`
            	&tpl=`my.tpl.gl.modal`
            ]]

Чанк my.tpl.gl.modal:

<div style="display: none;">
    <div class="gl-modal uk-modal">
        
        <div class="gl-default uk-modal-dialog">
            <h5>Выберите Ваш город</h5>

            <p class="desc">
                Введите название вашего города
            </p>

            <div class="gl-change-input-block">
                <select name="location" value="" style="width: 100%" class="select2 " multiple>
                </select>
                <span class="gl-select2-container"></span>
            </div>

            <ul class="gl-change-list">
                [[!gl.location?
                &class=`[[+class]]`
                &where=`{"default":0}`
                &limit=`0`
                ]]
            </ul>
        </div>
   
    </div>
</div>