source: branches/version-2_5-dev/data/class/helper/SC_Helper_Mail.php @ 19978

Revision 19978, 10.3 KB checked in by nanasess, 13 years ago (diff)

#843(複数配送先の指定)

  • 受注完了メールの対応
  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/**
25 * メール関連 のヘルパークラス.
26 *
27 * @package Helper
28 * @author LOCKON CO.,LTD.
29 * @version $Id$
30 */
31class SC_Helper_Mail {
32
33    /** メールテンプレートのパス */
34    var $arrMAILTPLPATH;
35
36    /**
37     * コンストラクタ.
38     */
39    function SC_Helper_Mail() {
40        $masterData = new SC_DB_MasterData_Ex();
41        $this->arrMAILTPLPATH =  $masterData->getMasterData("mtb_mail_tpl_path");
42        $this->arrPref = $masterData->getMasterData('mtb_pref');
43    }
44
45    /* DBに登録されたテンプレートメールの送信 */
46    function sfSendTemplateMail($to, $to_name, $template_id, &$objPage, $from_address = "", $from_name = "", $reply_to = "") {
47
48        $objQuery = new SC_Query();
49        // メールテンプレート情報の取得
50        $where = "template_id = ?";
51        $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
52        $objPage->tpl_header = $arrRet[0]['header'];
53        $objPage->tpl_footer = $arrRet[0]['footer'];
54        $tmp_subject = $arrRet[0]['subject'];
55
56        $objSiteInfo = new SC_SiteInfo();
57        $arrInfo = $objSiteInfo->data;
58
59        $objMailView = new SC_SiteView();
60        // メール本文の取得
61        $objMailView->assignobj($objPage);
62        $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
63
64        // メール送信処理
65        $objSendMail = new SC_SendMail_Ex();
66        if ($from_address == "") $from_address = $arrInfo['email03'];
67        if ($from_name == "") $from_name = $arrInfo['shop_name'];
68        if ($reply_to == "") $reply_to = $arrInfo['email03'];
69        $error = $arrInfo['email04'];
70        $tosubject = $this->sfMakeSubject($tmp_subject);
71       
72        $objSendMail->setItem('', $tosubject, $body, $from_address, $from_name, $reply_to, $error, $error);
73        $objSendMail->setTo($to, $to_name);
74        $objSendMail->sendMail();    // メール送信
75    }
76
77    /* 受注完了メール送信 */
78    function sfSendOrderMail($order_id, $template_id, $subject = "", $header = "", $footer = "", $send = true) {
79
80        $arrTplVar = new stdClass();
81        $objSiteInfo = new SC_SiteInfo();
82        $arrInfo = $objSiteInfo->data;
83        $arrTplVar->arrInfo = $arrInfo;
84
85        $objQuery = new SC_Query();
86
87        if($subject == "" && $header == "" && $footer == "") {
88            // メールテンプレート情報の取得
89            $where = "template_id = ?";
90            $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
91            $arrTplVar->tpl_header = $arrRet[0]['header'];
92            $arrTplVar->tpl_footer = $arrRet[0]['footer'];
93            $tmp_subject = $arrRet[0]['subject'];
94        } else {
95            $arrTplVar->tpl_header = $header;
96            $arrTplVar->tpl_footer = $footer;
97            $tmp_subject = $subject;
98        }
99
100        // 受注情報の取得
101        $where = "order_id = ?";
102        $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
103        $arrOrder = $arrRet[0];
104        $arrTplVar->arrOrderDetail = $objQuery->select("*", "dtb_order_detail", $where, array($order_id));
105
106        $objProduct = new SC_Product();
107        $objQuery->setOrder('shipping_id');
108        $arrRet = $objQuery->select("*", "dtb_shipping", "order_id = ?", array($order_id));
109        foreach (array_keys($arrRet) as $key) {
110            $objQuery->setOrder('shipping_id');
111            $arrItems = $objQuery->select("*", "dtb_shipment_item", "order_id = ? AND shipping_id = ?",
112                                          array($order_id, $arrRet[$key]['shipping_id']));
113            foreach ($arrItems as $itemKey => $arrDetail) {
114                foreach ($arrDetail as $detailKey => $detailVal) {
115                    $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal;
116                }
117
118                $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] =& $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']);
119            }
120        }
121        $arrTplVar->arrShipping = $arrRet;
122
123        $arrTplVar->Message_tmp = $arrOrder['message'];
124
125        // 顧客情報の取得
126        $customer_id = $arrOrder['customer_id'];
127        $objQuery->setOrder('customer_id');
128        $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
129        $arrCustomer = isset($arrRet[0]) ? $arrRet[0] : "";
130
131        $arrTplVar->arrCustomer = $arrCustomer;
132        $arrTplVar->arrOrder = $arrOrder;
133
134        //その他決済情報
135        if($arrOrder['memo02'] != "") {
136            $arrOther = unserialize($arrOrder['memo02']);
137
138            foreach($arrOther as $other_key => $other_val){
139                if(SC_Utils_Ex::sfTrim($other_val["value"]) == ""){
140                    $arrOther[$other_key]["value"] = "";
141                }
142            }
143
144            $arrTplVar->arrOther = $arrOther;
145        }
146
147        // 都道府県変換
148        $arrTplVar->arrPref = $this->arrPref;
149
150        $objCustomer = new SC_Customer();
151        $arrTplVar->tpl_user_point = $objCustomer->getValue('point');
152
153       if(Net_UserAgent_Mobile::isMobile() === true) {
154            $objMailView = new SC_MobileView();
155       } else {
156            $objMailView = new SC_SiteView();
157       }
158        // メール本文の取得
159        $objMailView->assignobj($arrTplVar);
160        $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
161
162        // メール送信処理
163        $objSendMail = new SC_SendMail_Ex();
164        $bcc = $arrInfo['email01'];
165        $from = $arrInfo['email03'];
166        $error = $arrInfo['email04'];
167        $tosubject = $this->sfMakeSubject($tmp_subject);
168
169        $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
170        $objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] ." 様");
171
172
173        // 送信フラグ:trueの場合は、送信する。
174        if($send) {
175            if ($objSendMail->sendMail()) {
176                $this->sfSaveMailHistory($order_id, $template_id, $tosubject, $body);
177            }
178        }
179
180        return $objSendMail;
181    }
182
183    // テンプレートを使用したメールの送信
184    function sfSendTplMail($to, $tmp_subject, $tplpath, &$objPage) {
185        $objMailView = new SC_SiteView();
186        $objSiteInfo = new SC_SiteInfo();
187        $arrInfo = $objSiteInfo->data;
188        // メール本文の取得
189        $objPage->tpl_shopname=$arrInfo['shop_name'];
190        $objPage->tpl_infoemail = $arrInfo['email02'];
191        $objMailView->assignobj($objPage);
192        $body = $objMailView->fetch($tplpath);
193        // メール送信処理
194        $objSendMail = new SC_SendMail_Ex();
195        $bcc = $arrInfo['email01'];
196        $from = $arrInfo['email03'];
197        $error = $arrInfo['email04'];
198        $tosubject = $this->sfMakeSubject($tmp_subject);
199       
200        $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
201        $objSendMail->sendMail();
202    }
203
204    // 通常のメール送信
205    function sfSendMail($to, $tmp_subject, $body) {
206        $objSiteInfo = new SC_SiteInfo();
207        $arrInfo = $objSiteInfo->data;
208        // メール送信処理
209        $objSendMail = new SC_SendMail_Ex();
210        $bcc = $arrInfo['email01'];
211        $from = $arrInfo['email03'];
212        $error = $arrInfo['email04'];
213        $tosubject = $this->sfMakeSubject($tmp_subject);
214       
215        $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
216        $objSendMail->sendMail();
217    }
218
219    //件名にテンプレートを用いる
220    function sfMakeSubject($subject) {
221        $objQuery = new SC_Query();
222        $objMailView = new SC_SiteView();
223        $objTplAssign = new stdClass;
224       
225        $arrInfo = $objQuery->select("*","dtb_baseinfo");
226        $arrInfo = $arrInfo[0];
227        $objTplAssign->tpl_shopname=$arrInfo['shop_name'];
228        $objTplAssign->tpl_infoemail=$subject; // 従来互換
229        $objTplAssign->tpl_mailtitle=$subject;
230        $objMailView->assignobj($objTplAssign);
231        $subject = $objMailView->fetch('mail_templates/mail_title.tpl');
232        return $subject;
233    }
234
235    // メール配信履歴への登録
236    function sfSaveMailHistory($order_id, $template_id, $subject, $body) {
237        $sqlval['subject'] = $subject;
238        $sqlval['order_id'] = $order_id;
239        $sqlval['template_id'] = $template_id;
240        $sqlval['send_date'] = "Now()";
241        if (!isset($_SESSION['member_id'])) $_SESSION['member_id'] = "";
242        if($_SESSION['member_id'] != "") {
243            $sqlval['creator_id'] = $_SESSION['member_id'];
244        } else {
245            $sqlval['creator_id'] = '0';
246        }
247        $sqlval['mail_body'] = $body;
248
249        $objQuery = new SC_Query();
250        $sqlval['send_id'] = $objQuery->nextVal("dtb_mail_history_send_id");
251        $objQuery->insert("dtb_mail_history", $sqlval);
252    }
253
254    /* 会員登録があるかどうかのチェック(仮会員を含まない) */
255    function sfCheckCustomerMailMaga($email) {
256        $col = "email, mailmaga_flg, customer_id";
257        $from = "dtb_customer";
258        $where = "(email = ? OR email_mobile = ?) AND status = 2 AND del_flg = 0";
259        $objQuery = new SC_Query();
260        $arrRet = $objQuery->select($col, $from, $where, array($email));
261        // 会員のメールアドレスが登録されている
262        if(!empty($arrRet[0]['customer_id'])) {
263            return true;
264        }
265        return false;
266    }
267}
268?>
Note: See TracBrowser for help on using the repository browser.