Exemplo n.º 1
0
 /**
  * @param Boolean $result: how did the email go? 1 = sent, 0 = not sent
  * @param Order $order: the order to which the email is associated.
  * @return DataObject (OrderEmailRecord)
  **/
 protected function createRecord($result, $order)
 {
     $obj = new OrderEmailRecord();
     $obj->From = $this->emailToVarchar($this->from);
     $obj->To = $this->emailToVarchar($this->to);
     $obj->Subject = $this->subject;
     $obj->Content = $this->body;
     $obj->Result = $result ? 1 : 0;
     $obj->OrderID = $order->ID;
     $obj->OrderStepID = $order->StatusID;
     if (Email::$send_all_emails_to) {
         $obj->To .= Email::$send_all_emails_to;
     }
     $obj->write();
     return $obj;
 }
 function read($request)
 {
     $id = intval($request->param("ID"));
     $email = OrderEmailRecord::get()->byID($id);
     return $email->Content;
 }
 /**
  * Has an email been sent to the customer for this
  * order step.
  *"-10 days"
  *
  * @param Order $order
  * @param Boolean $checkDateOfOrder
  * @return Boolean
  **/
 public function hasBeenSent(Order $order, $checkDateOfOrder = true)
 {
     //if it has been more than a XXX days since the order was last edited (submitted) then we do not send emails as
     //this would be embarrasing.
     if ($checkDateOfOrder) {
         if ($log = $order->SubmissionLog()) {
             $lastEditedValue = $log->LastEdited;
         } else {
             $lastEditedValue = $order->LastEdited;
         }
         if (strtotime($lastEditedValue) < strtotime("-" . EcommerceConfig::get("OrderStep", "number_of_days_to_send_update_email") . " days")) {
             return true;
         }
     }
     $count = OrderEmailRecord::get()->Filter(array("OrderID" => $order->ID, "OrderStepID" => $this->ID, "Result" => 1))->count();
     return $count ? true : false;
 }
 /**
  * @param Boolean $result: how did the email go? 1 = sent, 0 = not sent
  * @return DataObject (OrderEmailRecord)
  **/
 protected function createRecord($result)
 {
     $orderEmailRecord = OrderEmailRecord::create();
     $orderEmailRecord->From = $this->emailToVarchar($this->from);
     $orderEmailRecord->To = $this->emailToVarchar($this->to);
     if ($this->cc) {
         $orderEmailRecord->To .= ", CC: " . $this->emailToVarchar($this->cc);
     }
     if ($this->bcc) {
         $orderEmailRecord->To .= ", BCC: " . $this->emailToVarchar($this->bcc);
     }
     //always set result to try if
     if (!$result) {
         if (Director::isDev()) {
             $result = true;
             $this->Subject .= " -- FAKELY RECORDED AS SENT";
         }
     }
     $orderEmailRecord->Subject = $this->subject;
     $orderEmailRecord->Content = $this->body;
     $orderEmailRecord->Result = $result ? 1 : 0;
     $orderEmailRecord->OrderID = $this->order->ID;
     $orderEmailRecord->OrderStepID = $this->order->StatusID;
     if ($sendAllEmailsTo = Config::inst()->get("Email", "send_all_emails_to")) {
         $orderEmailRecord->To = $sendAllEmailsTo . " - (Email::send_all_emails_to setting)";
     }
     $orderEmailRecord->write();
     return $orderEmailRecord;
 }
 /**
  * @param Boolean $result: how did the email go? 1 = sent, 0 = not sent
  * @return DataObject (OrderEmailRecord)
  **/
 protected function createRecord($result)
 {
     $orderEmailRecord = OrderEmailRecord::create();
     $orderEmailRecord->From = $this->emailToVarchar($this->from);
     $orderEmailRecord->To = $this->emailToVarchar($this->to);
     if ($this->cc) {
         $orderEmailRecord->To .= ", CC: " . $this->emailToVarchar($this->cc);
     }
     if ($this->bcc) {
         $orderEmailRecord->To .= ", BCC: " . $this->emailToVarchar($this->bcc);
     }
     $orderEmailRecord->Subject = $this->subject;
     $orderEmailRecord->Content = $this->body;
     $orderEmailRecord->Result = $result ? 1 : 0;
     $orderEmailRecord->OrderID = $this->order->ID;
     $orderEmailRecord->OrderStepID = $this->order->StatusID;
     if ($sendAllEmailsTo = Config::inst()->get("Email", "send_all_emails_to")) {
         $orderEmailRecord->To = $sendAllEmailsTo . " - (Email::send_all_emails_to setting)";
     }
     $orderEmailRecord->write();
     return $orderEmailRecord;
 }
 function mergeUncompletedOrderForOneMember_170()
 {
     $explanation = "\r\n\t\t\t<h1>170. Merge uncompleted orders into one.</h1>\r\n\t\t\t<p>Merges uncompleted orders by the same user into one.</p>\r\n\t\t";
     if ($this->retrieveInfoOnly) {
         return $explanation;
     } else {
         echo $explanation;
     }
     $orders = Order::get()->filter(array("MemberID:GreaterThan" => 0))->sort(array("MemberID" => "ASC", "\"Order\".\"Created\"" => "DESC"))->innerJoin("Member", "\"Order\".\"MemberID\" = \"Member\".\"ID\"")->limit($this->limit, $this->start);
     $count = 0;
     $previousOrderMemberID = 0;
     $lastOrderFromMember = null;
     if ($orders->count()) {
         foreach ($orders as $order) {
             //crucial ONLY for non-submitted orders...
             if ($order->IsSubmitted()) {
                 //do nothing!
                 $count++;
             } else {
                 $memberID = $order->MemberID;
                 //recurring member
                 if ($previousOrderMemberID == $memberID && $lastOrderFromMember) {
                     $this->DBAlterationMessageNow("We have a duplicate order for a member: " . $order->Member()->Email, "created");
                     $orderAttributes = OrderAttribute::get()->filter(array("OrderID" => $order->ID));
                     if ($orderAttributes->count()) {
                         foreach ($orderAttributes as $orderAttribute) {
                             $this->DBAlterationMessageNow("Moving attribute #" . $orderAttribute->ID, "created");
                             DB::query("UPDATE \"OrderAttribute\" SET \"OrderID\" = " . $lastOrderFromMember->ID . " WHERE \"ID\" = " . $orderAttribute->ID);
                         }
                     } else {
                         $this->DBAlterationMessageNow("There are no attributes for this order");
                     }
                     $orderStatusLogs = OrderStatusLog::get()->filter(array("OrderID" => $order->ID));
                     if ($orderStatusLogs->count()) {
                         foreach ($orderStatusLogs as $orderStatusLog) {
                             $this->DBAlterationMessageNow("Moving order status log #" . $orderStatusLog->ID, "created");
                             DB::query("UPDATE \"OrderStatusLog\" SET \"OrderID\" = " . $lastOrderFromMember->ID . " WHERE \"ID\" = " . $orderStatusLog->ID);
                         }
                     } else {
                         $this->DBAlterationMessageNow("There are no order status logs for this order");
                     }
                     $orderEmailRecords = OrderEmailRecord::get()->filter(array("OrderID" => $order->ID));
                     if ($orderEmailRecords->count()) {
                         foreach ($orderEmailRecords as $orderEmailRecord) {
                             DB::query("UPDATE \"OrderEmailRecord\" SET \"OrderID\" = " . $lastOrderFromMember->ID . " WHERE \"ID\" = " . $orderEmailRecord->ID);
                             $this->DBAlterationMessageNow("Moving email #" . $orderEmailRecord->ID, "created");
                         }
                     } else {
                         $this->DBAlterationMessageNow("There are no emails for this order.");
                     }
                 } else {
                     $previousOrderMemberID = $order->MemberID;
                     $lastOrderFromMember = $order;
                     $this->DBAlterationMessageNow("Found last order from member.");
                 }
                 if ($order->BillingAddressID && !$lastOrderFromMember->BillingAddressID) {
                     $this->DBAlterationMessageNow("Moving Billing Address.");
                     DB::query("UPDATE \"Order\" SET \"BillingAddressID\" = " . $order->BillingAddressID . " WHERE \"ID\" = " . $lastOrderFromMember->ID);
                     DB::query("UPDATE \"BillingAddress\" SET \"OrderID\" = " . $lastOrderFromMember->ID . " WHERE \"ID\" = " . $order->BillingAddressID);
                 }
                 if ($order->ShippingAddressID && !$lastOrderFromMember->ShippingAddressID) {
                     $this->DBAlterationMessageNow("Moving Shipping Address.");
                     DB::query("UPDATE \"Order\" SET \"ShippingAddressID\" = " . $order->ShippingAddressID . " WHERE \"ID\" = " . $lastOrderFromMember->ID);
                     DB::query("UPDATE \"ShippingAddress\" SET \"OrderID\" = " . $lastOrderFromMember->ID . " WHERE \"ID\" = " . $order->ShippingAddressID);
                 }
                 $order->delete();
             }
         }
         $this->DBAlterationMessageNow("Ignored {$count} Orders that have already been submitted.");
         return $this->start + $this->limit;
     } else {
         $this->DBAlterationMessageNow("There were no orders at all to work through.");
     }
     return 0;
 }