예제 #1
0
 public function beforeUpdateCallback($e)
 {
     if ($this->isAttributeChanged('canceled')) {
         $this->canceled_at = \Yii::$app->formatter->asTimestamp(time());
     }
     if ($this->isAttributeChanged('payed')) {
         $this->payed_at = \Yii::$app->formatter->asTimestamp(time());
     }
     if ($this->isAttributeChanged('status_code')) {
         $this->status_at = \Yii::$app->formatter->asTimestamp(time());
         (new ShopOrderChange(['type' => ShopOrderChange::ORDER_STATUS_CHANGED, 'shop_order_id' => $this->id, 'data' => ['status' => $this->status->name]]))->save();
         //Письмо тому кто заказывает
         if ($this->user->email) {
             try {
                 \Yii::$app->mailer->view->theme->pathMap['@app/mail'][] = '@skeeks/cms/shop/mail';
                 \Yii::$app->mailer->compose('order-status-change', ['order' => $this])->setFrom([\Yii::$app->cms->adminEmail => \Yii::$app->cms->appName . ''])->setTo($this->user->email)->setSubject(\Yii::$app->cms->appName . ': ' . \Yii::t('skeeks/shop/app', 'Change order status') . ' #' . $this->id)->send();
             } catch (\Exception $e) {
                 \Yii::error('Ошибка отправки email: ' . $e->getMessage(), Module::className());
             }
         }
     }
     if ($this->isAttributeChanged('allow_payment') && $this->allow_payment == Cms::BOOL_Y) {
         (new ShopOrderChange(['type' => ShopOrderChange::ORDER_ALLOW_PAYMENT, 'shop_order_id' => $this->id]))->save();
         //Письмо тому кто заказывает
         if ($this->user->email) {
             try {
                 \Yii::$app->mailer->view->theme->pathMap['@app/mail'][] = '@skeeks/cms/shop/mail';
                 \Yii::$app->mailer->compose('order-allow-payment', ['order' => $this])->setFrom([\Yii::$app->cms->adminEmail => \Yii::$app->cms->appName . ''])->setTo($this->user->email)->setSubject(\Yii::$app->cms->appName . ': ' . \Yii::t('skeeks/shop/app', 'Resolution of payment on request') . ' #' . $this->id)->send();
             } catch (\Exception $e) {
                 \Yii::error('Ошибка отправки email: ' . $e->getMessage(), Module::className());
             }
         }
     }
     if ($this->isAttributeChanged('allow_delivery') && $this->allow_delivery == Cms::BOOL_Y) {
         (new ShopOrderChange(['type' => ShopOrderChange::ORDER_ALLOW_DELIVERY, 'shop_order_id' => $this->id]))->save();
         //Письмо тому кто заказывает
         if ($this->user->email) {
             try {
                 \Yii::$app->mailer->view->theme->pathMap['@app/mail'][] = '@skeeks/cms/shop/mail';
                 \Yii::$app->mailer->compose('order-allow-delivery', ['order' => $this])->setFrom([\Yii::$app->cms->adminEmail => \Yii::$app->cms->appName . ''])->setTo($this->user->email)->setSubject(\Yii::$app->cms->appName . ': ' . \Yii::t('skeeks/shop/app', 'Resolution of payment on request') . ' #' . $this->id)->send();
             } catch (\Exception $e) {
                 \Yii::error('Ошибка отправки email: ' . $e->getMessage(), Module::className());
             }
         }
     }
     if ($this->isAttributeChanged('canceled') && $this->canceled == Cms::BOOL_Y) {
         (new ShopOrderChange(['type' => ShopOrderChange::ORDER_CANCELED, 'shop_order_id' => $this->id, 'data' => ['reason_canceled' => $this->reason_canceled]]))->save();
         //Письмо тому кто заказывает
         if ($this->user->email) {
             try {
                 \Yii::$app->mailer->view->theme->pathMap['@app/mail'][] = '@skeeks/cms/shop/mail';
                 \Yii::$app->mailer->compose('order-canceled', ['order' => $this])->setFrom([\Yii::$app->cms->adminEmail => \Yii::$app->cms->appName . ''])->setTo($this->user->email)->setSubject(\Yii::$app->cms->appName . ': ' . \Yii::t('skeeks/shop/app', 'Cancellations') . ' #' . $this->id)->send();
             } catch (\Exception $e) {
                 \Yii::error('Ошибка отправки email: ' . $e->getMessage(), Module::className());
             }
         }
     }
 }