|
Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/serbaantik.com/public_html/application/controllers/ |
Upload File : |
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Cart extends Public_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('cart');
}
public function index()
{
//SEO configuration data
$this->db->select('browser_title, meta_description, why_title')->from('configuration')->where('id_configuration', 1);
$website_data = $this->db->get()->row();
$this->data_header['browser_title'] = 'Your Request';
$this->data_header['meta_description'] = 'Your Request';
// echo '<pre>';
// var_dump($this->cart->contents()); exit;
// echo '</pre>';
$this->load->helper('form');
$this->data['widget'] = $this->recaptcha->getWidget();
$this->data['script'] = $this->recaptcha->getScriptTag();
//LOAD VIEW
$this->load->view('template/header', $this->data_header);
$this->load->view('cart', $this->data);
$this->load->view('template/footer', $this->data_footer);
}
//add cart from product page
public function ajax_addtocart()
{
//test if ajax call to prevent direct access
if(!$this->input->is_ajax_request())
{
exit('No direct script access allowed');
}
//check cart max qty
$max_qty = $this->db->select('cart_max_items')->from('configuration')->where('id_configuration', 1)->get()->row()->cart_max_items;
if(count($this->cart->contents()) >= $max_qty)
{
return $this->output
->set_content_type('application/json')
->set_status_header(200)
->set_output(json_encode([
'success' => false,
'message' => 'Cart has reach max quantity of ' . count($this->cart->contents()) . ' items'
]));
}
$product_id = (int) $this->input->post('product_id');
//get product data
$product = $this->db->select('*')->from('products')->where('id_products', $product_id)->get()->row_array();
$data_cart['id'] = $product_id;
$data_cart['name'] = ucwords($product['title']);
$data_cart['qty'] = 1;
$data_cart['price'] = $product['price'];
$data_cart['options']['sku'] = $product['sku'];
$data_cart['options']['attributes'] = '';
for ($i = 1; $i <= 10; $i++)
{
if(!empty($product['varian' . $i]))
{
$data_cart['options']['attributes'] .= ucwords($product['varian' . $i]) . ' ' . ucwords($product['attribute' . $i]) . '. ';
}
}
$data_cart['options']['image'] = $product['image1'];
$data_cart['options']['alias'] = $product['alias'];
$this->cart->product_name_rules = '[:print:]'; //this is to eliminate cart product name restriction on special characters
$data_cart['cart_rowid'] = $this->cart->insert($data_cart);
return $this->output
->set_content_type('application/json')
->set_status_header(201)
->set_output(json_encode([
'success' => true,
'message' => 'Product added to your bag',
'count' => count($this->cart->contents())
]));
}
public function remove($rowid)
{
if ($rowid=="all") {
$this->cart->destroy();
}
else
{
$data = array(
'rowid' => $rowid,
'qty' => 0
);
$this->cart->update($data);
}
redirect('cart');
}
public function send_inquiry()
{
//validation check
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="form_error">', '</div>');
$config = array(
array(
'field' => 'name',
'label' => 'Name',
'rules' => 'trim|required|min_length[3]'
),
array(
'field' => 'email',
'label' => 'Email',
'rules' => 'trim|required|valid_email'
),
array(
'field' => 'handphone',
'label' => 'Handphone',
'rules' => 'trim|required|min_length[6]'
),
array(
'field' => 'address',
'label' => 'address',
'rules' => 'trim|required'
),
);
$this->form_validation->set_rules($config);
if($this->form_validation->run($this))
{
$recaptcha = $this->input->post('g-recaptcha-response');
if(!empty($recaptcha))
{
$response = $this->recaptcha->verifyResponse($recaptcha);
if (isset($response['success']) and $response['success'] === true)
{
$this->send_email($_POST);
}
}
else
{
$this->session->set_flashdata('error', 'Sorry Recaptcha Error');
redirect('cart');
}
}
$this->index();
}
private function send_email($email_data)
{
$email_conf = $this->db->select('email_smtp_host, email_smtp_port, email_smtp_password, email_smtp')->from('configuration')->where('id_configuration', 1)->get()->row();
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = $email_conf->email_smtp_host;
$config['smtp_port'] = $email_conf->email_smtp_port;
$config['smtp_user'] = $email_conf->email_smtp;
$config['smtp_pass'] = $email_conf->email_smtp_password;
$config['mailtype'] = 'html';
$config['smtp_crypto'] = 'ssl';
$config['charset'] = 'iso-8859-1';
//$config['charset'] = 'UTF-8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
$this->email->set_crlf( "\r\n" ); //add this for hotmail
$this->email->initialize($config);
$this->email->from('noreply@serbaantik.com', 'Serba Antik');
$this->email->to('inquiry@serbaantik.com');
$this->email->subject('Serba Antik Product Inquiry');
$products = '';
foreach($this->cart->contents() as $item)
{
$products = $products . '<br>Name: ' . $item['name'] . '<br>SKU: ' . $item['options']['sku'];
}
$this->email->message(
'Hello Admin, You have product inquiry:<br><br>
Customer Name: ' . ucwords($email_data['name']) . '<br><br>
Email: ' . $email_data['email'] . '<br><br>
Handphone: ' . $email_data['handphone'] . '<br><br>
Address: ' . $email_data['address'] . '<br><br>
Products:<br>' . $products);
$respon_email = $this->email->send();
if(!$respon_email)
{
var_dump($this->email->print_debugger()); exit();
}
$this->session->set_flashdata('success', 'Your inquiry have been sent. Thank you.');
redirect('cart');
}
}