我正在使用opencart
当我点击链接确认新成员时我发现了一些问题,
这是邮件错误
致命错误:致电成员函数couponNC()..第23行
和ini第23行,我的代码是
$这 - > generate-> couponNC($ CUSTOMER_ID);
couponNC是文件夹系统/库中的函数..
我的文件generate.php和我的函数是
<?php
private $db;
public function __construct($registry)
{
$this->db = $registry->get('db');
$this->config = $registry->get('config');
}
public function couponNC ($customer_id) {
// my function code
}
?>
帮我解决一下。
答案 0 :(得分:0)
这是我的generated.php @kyleDomingo
<?php
class Generate
{
private $db;
public function __construct($registry)
{
$this->db = $registry->get('db');
$this->config = $registry->get('config');
}
public function couponNC ($customer_id) {
$customer = $this->getCustomer($customer_id);
if(isset($customer['firstname'])){
$this->db->query("UPDATE " . DB_PREFIX . "customer SET approved = '1' WHERE customer_id='" . $customer_id . "'");
$date_add = date("Y-m-d H:i:s");
$date_start = date("Y-m-d");
$date_end = date("Y-m-d", mktime(date("H"),date("i"),date("s"),date("m"),date("d")+30,date("Y")));
$length = '5';
$random = strtoupper(crypt(uniqid(rand(),1)));
$random_no_slashes = strip_tags(stripslashes($random));
$random_id = str_replace(".","",$random_no_slashes);
$random_final = strrev(str_replace("/","",$random_id));
$random_use = "NC".substr($random_final,0,$length);
//$kupon .= "Random Id: $random_use<br>" ;
$counpons[]=array(
'code' => $random_use
);
$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon` SET name = 'Coupon New Customer', code = '".$random_use."', type = 'F', discount = '50000', logged = '0', shipping = '0', total = '150000', date_start = '".$date_start."', date_end = '".$date_end."', uses_total = '1', uses_customer = '1', status = '1', date_added = '".$date_add."', discount_type = 'A', one_product = '0'");
/*, product_not_include = '1'*/
$lastId = $this->db->getLastId();
$categories = array('43','206');
foreach($categories as $category){
$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon_category` SET coupon_id = '".$lastId."', category_id = '".$category."'");
}
$no = 1;
$html = ''
foreach($counpons as $coupon){
$html .= ' <tr>
<td class="left">'.$no.'</td>
<td class="left">'.$coupon['code'].'</td>
<td class="right">Rp. 50.000</td>
</tr>';
$no++;
}
$html .= '';
//echo $html;die;
$this->sendMail("domain.com Gift Voucher. Just For You!",$html,$customer['email']);
}
}
public function getOrder($order_id) {
$order_query = $this->db->query("SELECT *, (SELECT os.name FROM `" . DB_PREFIX . "order_status` os WHERE os.order_status_id = o.order_status_id AND os.language_id = o.language_id) AS order_status FROM `" . DB_PREFIX . "order` o WHERE o.order_id = '" . (int)$order_id . "'");
if ($order_query->num_rows) {
$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['payment_country_id'] . "'");
if ($country_query->num_rows) {
$payment_iso_code_2 = $country_query->row['iso_code_2'];
$payment_iso_code_3 = $country_query->row['iso_code_3'];
} else {
$payment_iso_code_2 = '';
$payment_iso_code_3 = '';
}
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['payment_zone_id'] . "'");
if ($zone_query->num_rows) {
$payment_zone_code = $zone_query->row['code'];
} else {
$payment_zone_code = '';
}
$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['shipping_country_id'] . "'");
if ($country_query->num_rows) {
$shipping_iso_code_2 = $country_query->row['iso_code_2'];
$shipping_iso_code_3 = $country_query->row['iso_code_3'];
} else {
$shipping_iso_code_2 = '';
$shipping_iso_code_3 = '';
}
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['shipping_zone_id'] . "'");
if ($zone_query->num_rows) {
$shipping_zone_code = $zone_query->row['code'];
} else {
$shipping_zone_code = '';
}
return array(
'order_id' => $order_query->row['order_id'],
'invoice_no' => $order_query->row['invoice_no'],
'invoice_prefix' => $order_query->row['invoice_prefix'],
'store_id' => $order_query->row['store_id'],
'store_name' => $order_query->row['store_name'],
'store_url' => $order_query->row['store_url'],
'customer_id' => $order_query->row['customer_id'],
'firstname' => $order_query->row['firstname'],
'lastname' => $order_query->row['lastname'],
'telephone' => $order_query->row['telephone'],
'fax' => $order_query->row['fax'],
'email' => $order_query->row['email'],
'payment_firstname' => $order_query->row['payment_firstname'],
'payment_lastname' => $order_query->row['payment_lastname'],
'payment_company' => $order_query->row['payment_company'],
'payment_company_id' => $order_query->row['payment_company_id'],
'payment_tax_id' => $order_query->row['payment_tax_id'],
'payment_address_1' => $order_query->row['payment_address_1'],
'payment_address_2' => $order_query->row['payment_address_2'],
'payment_postcode' => $order_query->row['payment_postcode'],
'payment_city' => $order_query->row['payment_city'],
'payment_zone_id' => $order_query->row['payment_zone_id'],
'payment_zone' => $order_query->row['payment_zone'],
'payment_zone_code' => $payment_zone_code,
'payment_country_id' => $order_query->row['payment_country_id'],
'payment_country' => $order_query->row['payment_country'],
'payment_iso_code_2' => $payment_iso_code_2,
'payment_iso_code_3' => $payment_iso_code_3,
'payment_address_format' => $order_query->row['payment_address_format'],
'payment_method' => $order_query->row['payment_method'],
'payment_code' => $order_query->row['payment_code'],
'shipping_firstname' => $order_query->row['shipping_firstname'],
'shipping_lastname' => $order_query->row['shipping_lastname'],
'shipping_company' => $order_query->row['shipping_company'],
'shipping_address_1' => $order_query->row['shipping_address_1'],
'shipping_address_2' => $order_query->row['shipping_address_2'],
'shipping_postcode' => $order_query->row['shipping_postcode'],
'shipping_district' => $order_query->row['shipping_district'],
'shipping_city' => $order_query->row['shipping_city'],
'shipping_zone_id' => $order_query->row['shipping_zone_id'],
'shipping_zone' => $order_query->row['shipping_zone'],
'shipping_zone_code' => $shipping_zone_code,
'shipping_country_id' => $order_query->row['shipping_country_id'],
'shipping_country' => $order_query->row['shipping_country'],
'shipping_iso_code_2' => $shipping_iso_code_2,
'shipping_iso_code_3' => $shipping_iso_code_3,
'shipping_address_format' => $order_query->row['shipping_address_format'],
'shipping_method' => $order_query->row['shipping_method'],
'shipping_code' => $order_query->row['shipping_code'],
'comment' => $order_query->row['comment'],
'total' => $order_query->row['total'],
'order_status_id' => $order_query->row['order_status_id'],
'order_status' => $order_query->row['order_status'],
'currency_id' => $order_query->row['currency_id'],
'currency_code' => $order_query->row['currency_code'],
'currency_value' => $order_query->row['currency_value'],
'ip' => $order_query->row['ip'],
'senddata' => $order_query->row['senddata'],
'forwarded_ip' => $order_query->row['forwarded_ip'],
'user_agent' => $order_query->row['user_agent'],
'accept_language' => $order_query->row['accept_language'],
'date_modified' => $order_query->row['date_modified'],
'installment' => $order_query->row['installment'],
'weight' => $order_query->row['weight'],
'card_discount_id' => $order_query->row['card_discount_id'],
'lazada_order' => $order_query->row['lazada_order'],
'date_added' => date("d.m.Y H:i:s", strtotime($order_query->row['date_added']))
);
} else {
return false;
}
}
public function getOrderProducts($order_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
return $query->rows;
}
public function getTotal($order_id,$code){
$query = $this->db->query("select * from `" . DB_PREFIX . "order_total` where order_id = '" . (int)$order_id . "' and code='$code'");
return $query->row;
}
public function getOrderCoupon($order_id) {
$query = $this->db->query("Select * from (
SELECT amount,coupon_id FROM `cartcoupon_history` WHERE order_id = '" . (int)$order_id . "'
) ch
left join
(
SELECT code,coupon_id,`name` as nama,type,discount FROM `cartcoupon`
) c
on c.coupon_id=ch.coupon_id");
return $query->rows;
}
public function getCustomer($customer_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "' AND approved = '0'");
return $query->row;
}
public function getLogVoucher($order_id){
$query = $this->db->query("SELECT * FROM log_voucher WHERE order_id = '" . $order_id . "'");
return $query->row;
}
public function sendMail($subject,$message,$to){
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setFrom($this->config->get('config_email'));
$mail->setSender("/*my domain*/");
$mail->setSubject($subject);
//$mail->setText($message);
$mail->setHtml($message);
$mail->setTo($to);
$mail->send();
}
}
?>