private function notifyOrderInfo(NotifyOrder $notify) { $this->log('consume notify', $notify->getAttributes()); $customerId = $notify->customer_id; $orderId = $notify->order_id; $customer = Customer::instance()->initByExternalId($customerId); if (!$customer) { $this->log('Customer is not initialized', ['customer_id' => $customerId]); return; } if (!$customer->get()->email) { $this->log('Email is empty', ['customer_id' => $customerId]); $notify->sent = 1; $notify->save(); return; } $password = $customer->get()->credential->agbis_password; if (!$password) { $this->log('Customer password is not exists', ['customer_id' => $customerId]); return; } if (isset($this->keys[$customerId])) { $key = $this->keys[$customerId]; } else { try { $user = $this->api->Login_con('+7' . $customer->get()->phone, $password); } catch (ApiException $e) { $this->log($e->getMessage(), [$customerId]); $notify->sent = 1; $notify->save(); return; } $this->keys[$customerId] = $user->key; $key = $user->key; } $order = $this->api->getOrder($orderId, $key); $services = (new OrderServiceComponent())->parseOrderService($orderId, $key); $email = $customer->get()->email; $name = $customer->get()->name; $this->log('ready data send', ['services' => count($services)]); try { $attach = self::createClothesFile($order, $services, $name); Mailer::notifyNewOrder($order, $services, $email, $name, $attach); $notify->sent = 1; $notify->save(); OrderRequest::markAsCompleted($customer->get()->phone, $orderId); } catch (\Exception $e) { $this->log('send mail error', ['email' => $customer->get()->email, 'id' => $customer->get()->id, 'message' => $e->getMessage()]); } }