Пример #1
0
 public function changeStatus()
 {
     $status = (int) $this->request->get('status');
     $shipment = Shipment::getInstanceByID('Shipment', (int) $this->request->get('id'), true, array('Order' => 'CustomerOrder', 'ShippingAddress' => 'UserAddress'));
     $shipment->loadItems();
     $zone = $shipment->getDeliveryZone();
     $shipmentRates = $zone->getShippingRates($shipment);
     $shipment->setAvailableRates($shipmentRates);
     $history = new OrderHistory($shipment->order->get(), $this->user);
     $shipment->status->set($status);
     $shipment->save();
     $history->saveLog();
     $status = $shipment->status->get();
     $enabledStatuses = $this->config->get('EMAIL_STATUS_UPDATE_STATUSES');
     $m = array('EMAIL_STATUS_UPDATE_NEW' => Shipment::STATUS_NEW, 'EMAIL_STATUS_UPDATE_PROCESSING' => Shipment::STATUS_PROCESSING, 'EMAIL_STATUS_UPDATE_AWAITING_SHIPMENT' => Shipment::STATUS_AWAITING, 'EMAIL_STATUS_UPDATE_SHIPPED' => Shipment::STATUS_SHIPPED);
     $sendEmail = false;
     foreach ($m as $configKey => $constValue) {
         if ($status == $constValue && array_key_exists($configKey, $enabledStatuses)) {
             $sendEmail = true;
         }
     }
     if ($sendEmail || $this->config->get('EMAIL_STATUS_UPDATE')) {
         $user = $shipment->order->get()->user->get();
         $user->load();
         $email = new Email($this->application);
         $email->setUser($user);
         $email->setTemplate('order.status');
         $email->set('order', $shipment->order->get()->toArray(array('payments' => true)));
         $email->set('shipments', array($shipment->toArray()));
         $email->send();
     }
     return new JSONResponse(false, 'success');
 }
Пример #2
0
 function testUser()
 {
     $user = User::getNewInstance('*****@*****.**');
     $user->firstName->set('test');
     $user->lastName->set('recipient');
     Swift_Connection_Fake::resetBuffer();
     $user->save();
     //var_dump(Swift_Connection_Fake::getBuffer());
     $email = new Email(self::getApplication());
     $email->setFrom('*****@*****.**', 'Unit Test');
     $email->setSubject('test');
     $email->setText('some text');
     $email->setUser($user);
     $res = $email->send();
     $this->assertTrue(strpos($email->getMessage()->getHeaders()->get('To'), $user->email->get()) !== false);
     $this->assertEqual($res, 1);
 }
Пример #3
0
 public function add()
 {
     if ($this->buildOrderNoteValidator()->isValid()) {
         $order = CustomerOrder::getInstanceById($this->request->get('id'), CustomerOrder::LOAD_DATA);
         $note = OrderNote::getNewInstance($order, $this->user);
         $note->isAdmin->set(true);
         $note->text->set($this->request->get('comment'));
         $note->save();
         if ($this->config->get('EMAIL_ORDERNOTE')) {
             $order->user->get()->load();
             $email = new Email($this->application);
             $email->setUser($order->user->get());
             $email->setTemplate('order.message');
             $email->set('order', $order->toArray(array('payments' => true)));
             $email->set('message', $note->toArray());
             $email->send();
         }
         return new ActionRedirectResponse('backend.orderNote', 'view', array('id' => $note->getID()));
     } else {
         return new RawResponse('invalid');
     }
 }
Пример #4
0
 public function do_register()
 {
     $request = $this->application->getRequest();
     $first_name = $request->get('firstName');
     $last_name = $request->get('lastName');
     $company = $request->get('companyName');
     $email = $request->get('email');
     $pass = $request->get('password');
     if (!isset($first_name) || !isset($last_name) || !isset($email) || !isset($pass)) {
         throw new Exception("Please complete required field " . $last_name);
     }
     $user = User::getInstanceByEmail($email);
     if (isset($user)) {
         throw new Exception('User already exist');
     }
     $user = User::getNewInstance($email, $pass);
     $user->firstName->set($first_name);
     $user->lastName->set($last_name);
     if (isset($company)) {
         $user->companyName->set($company);
     }
     $user->email->set($email);
     $user->isEnabled->set('1');
     $user->save();
     $code = rand(1, 10000000) . rand(1, 10000000);
     $user->setPreference('confirmation', $code);
     $user->save();
     $_email = new Email($this->application);
     $_email->setUser($user);
     $_email->set('code', $code);
     $_email->setTemplate('user.confirm');
     $_email->send();
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     $response->addChild('state', '1');
     return new SimpleXMLResponse($response);
 }
Пример #5
0
 public function sendWelcomeEmail(User $user)
 {
     // send welcome email with user account details
     if ($this->config->get('EMAIL_NEW_USER')) {
         if ($this->session->get('password')) {
             $user->setPassword($this->session->get('password'));
         }
         $email = new Email($this->application);
         $email->setUser($user);
         $email->setTemplate('user.new');
         $email->send();
     }
 }
Пример #6
0
 public function sendStatusNotifyEmail(CustomerOrder $order)
 {
     $status = $order->status->get();
     $enabledStatuses = $this->config->get('EMAIL_STATUS_UPDATE_STATUSES');
     $m = array('EMAIL_STATUS_UPDATE_NEW' => CustomerOrder::STATUS_NEW, 'EMAIL_STATUS_UPDATE_PROCESSING' => CustomerOrder::STATUS_PROCESSING, 'EMAIL_STATUS_UPDATE_AWAITING_SHIPMENT' => CustomerOrder::STATUS_AWAITING, 'EMAIL_STATUS_UPDATE_SHIPPED' => CustomerOrder::STATUS_SHIPPED);
     $sendEmail = false;
     foreach ($m as $configKey => $constValue) {
         if ($status == $constValue && array_key_exists($configKey, $enabledStatuses)) {
             $sendEmail = true;
         }
     }
     if ($this->config->get('EMAIL_STATUS_UPDATE') || $sendEmail) {
         $this->loadLanguageFile('Frontend');
         $this->application->loadLanguageFiles();
         $order->user->get()->load();
         $email = new Email($this->application);
         $email->setUser($order->user->get());
         $email->setTemplate('order.status');
         $email->set('order', $order->toArray(array('payments' => true)));
         $email->set('shipments', $order->getShipments()->toArray());
         $email->send();
     }
 }
Пример #7
0
 public function save($con = null)
 {
     if ($this->getObject()->isNew()) {
         $signup = true;
     } else {
         $signup = false;
     }
     $object = parent::save();
     // update profile
     $values = $this->getValues();
     $profile = $object->getProfile();
     // save and remove photo from values
     $photo = $values["profile"]["photo"];
     unset($values["profile"]["photo"]);
     // update profile object
     $profile->fromArray($values["profile"], BasePeer::TYPE_FIELDNAME);
     $profile->setUser($object);
     // new photo??
     if ($photo) {
         $fileName = $profile->getPhoto(false);
         if (!$fileName) {
             $fileName = $profile->generateAvatarName() . '.jpg';
         }
         $photo->save(sfConfig::get('sf_userimage_dir') . DIRECTORY_SEPARATOR . $fileName);
         $profile->setPhoto($fileName);
     }
     if ($values["profile"]["remove_photo"]) {
         $fileName = $profile->getPhoto(false);
         if ($fileName) {
             $profile->setPhoto(null);
             $profile->save();
             // remove from filesystem
             unlink(sfConfig::get('sf_userimage_dir') . DIRECTORY_SEPARATOR . $fileName);
         } else {
             $profile->save();
         }
     } else {
         $profile->save();
     }
     // if creating, setup email and permanent jotag
     if ($signup) {
         // setup email
         $email = new Email();
         $email->setEmail($this->getValue('email'));
         $email->setIsConfirmed(true);
         $email->setIsPrimary(true);
         $email->setType(ContactPeer::TP_PERSONAL);
         $email->setUser($object);
         $email->save();
         // generate JOTAG.
         $tag = new Tag();
         $tag->setJotag($object->generateRandomJOTAG());
         $tag->setIsPrimary(true);
         $tag->setStatus(TagPeer::ST_ACTIVE);
         $tag->setUser($object);
         // link primary email to tag
         $tm = new TagEmail();
         $tm->setEmail($email);
         $tag->addTagEmail($tm);
         // save new tag
         $tag->save();
     }
     return $object;
 }
Пример #8
0
 protected function finalizeOrder($options = array())
 {
     if (!count($this->order->getShipments())) {
         throw new ApplicationException('No shipments in order');
     }
     $user = $this->order->user->get();
     $user->load();
     $newOrder = $this->order->finalize($options);
     $orderArray = $this->order->toArray(array('payments' => true));
     // send order confirmation email
     if ($this->config->get('EMAIL_NEW_ORDER')) {
         $email = new Email($this->application);
         $email->setUser($user);
         $email->setTemplate('order.new');
         $email->set('order', $orderArray);
         $email->send();
     }
     // notify store admin
     if ($this->config->get('NOTIFY_NEW_ORDER')) {
         $email = new Email($this->application);
         $email->setTo($this->config->get('NOTIFICATION_EMAIL'), $this->config->get('STORE_NAME'));
         $email->setTemplate('notify.order');
         $email->set('order', $orderArray);
         $email->set('user', $user->toArray());
         $email->send();
     }
     $this->session->set('completedOrderID', $this->order->getID());
     if ($newOrder instanceof CustomerOrder) {
         SessionOrder::save($newOrder);
     } else {
         SessionOrder::destroy();
     }
     return new ActionRedirectResponse('checkout', 'completed');
 }
Пример #9
0
 protected function finalizeOrder(CustomerOrder $customer_order, User $user)
 {
     $user->load();
     /*if (!count($customer_order->getShipments()))
       {
           throw new Exception('No shipments in order');
       }*/
     $newOrder = $customer_order->finalize();
     $orderArray = $customer_order->toArray(array('payments' => true));
     // send order confirmation email
     if ($this->application->config->get('EMAIL_NEW_ORDER')) {
         $email = new Email($this->application);
         $email->setUser($user);
         $email->setTemplate('order.new');
         $email->set('order', $orderArray);
         $email->send();
     }
     // notify store admin
     if ($this->application->config->get('NOTIFY_NEW_ORDER')) {
         $email = new Email($this->application);
         $email->setTo($this->application->config->get('NOTIFICATION_EMAIL'), $this->application->config->get('STORE_NAME'));
         $email->setTemplate('notify.order');
         $email->set('order', $orderArray);
         $email->set('user', $user->toArray());
         $email->send();
     }
     // if user hasn't wish list items order->finalize() will return null, saving null with SessionOrder causes fatal error!
     if ($newOrder instanceof CustomerOrder) {
         return true;
     }
     return false;
 }