Version: current

     1 <?php
     2 // Уведомление менеджера по емайл (создание заказа и изменение заказа пользователем (например оплата))
     3 class ManagerEmailOrderNotification extends OrderHandlersDecorator {
     4
     5     function OnAfterCreateOrder(& $member) {
     6         $conf = SiteConfig::current_site_config();
     7         if (!$conf->ManagerEmailOrderNotificationActive) {
     8             return false;
     9         }
    10
    11         $mail = new Email();
    12         $mail->setFrom($conf->CartSenderEmail());
    13         $mail->setSubject($this->owner->fill_vars($conf->CartAdminNewOrderSubject($this->owner->ID)));
    14         $mail->setTo($conf->CartAdminEmail());
    15         $mail->setTemplate('Order_AdminReceiptEmail');
    16         $mail->populateTemplate(array(
    17             'Order' => $this->owner,
    18             'SiteConfig' => $conf,
    19         ));
    20         $mail->send();
    21     }
    22
    23     function OnAfterChangeStatus($member, $changedStatus, $note) {
    24         $conf = SiteConfig::current_site_config();
    25         if (!$conf->ManagerEmailOrderNotificationActive) {
    26             return false;
    27         }
    28
    29         // если текущий пользователь - админ, то вероятно он сменил статус в админке - то не шлем ему письмо
    30         if (0 && $member && $member->isAdmin())
    31             return false;
    32
    33         if (!$note) {
    34             $log = DataObject::get_one('Order_StatusLog', "OrderID = {$this->owner->ID}", "Created DESC");
    35             $note = $log->Note;
    36         }
    37         $mail = new Email();
    38         $mail->setFrom($conf->CartSenderEmail());
    39         $mail->setTo($conf->CartAdminEmail());
    40         $mail->setSubject($this->owner->fill_vars($conf->CartUserStatusSubject($this->owner->ID)));
    41         $mail->setTemplate('Order_AdminStatusEmail');
    42
    43         $mail->populateTemplate(array(
    44             'Order' => $this->owner,
    45             'Note' => $note,
    46             'Statuses' => $changedStatus,
    47             'SiteConfig' => $conf,
    48         ));
    49         $mail->send();
    50     }
    51 }
    52
    53 // Декоратор SiteConfig для этого типа уведомлений
    54 class ManagerEmailOrderNotification_SiteConfig extends SiteConfigDecorator {
    55     function extraStatics() {
    56         return array(
    57             'db' => array(
    58                 'ManagerEmailOrderNotificationActive' => 'Boolean', // Активность
    59             )
    60         );
    61     }
    62     public function updateCMSFields(FieldSet &$fields) {
    63         $tab = self::get_config_tab($fields, 'OrderNotifications.EmailOrderNotification');
    64         $tab->push(new CheckboxField('ManagerEmailOrderNotificationActive', $this->owner->FieldLabel('ManagerEmailOrderNotificationActive')));
    65
    66     }
    67 }
    68

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -