I have a store which is set up with Open Cart 3. I want to disable the checkout on Sundays. I have tried the following code but it doesn't seem to be working.
I added the code to following file cataloge/controller/checkout/checkput.php
class ControllerCheckoutCheckout extends Controller {
public function index() {
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$this->response->redirect($this->url->link('checkout/cart'));
}
if (date("l") == "Sunday") {
$this->response->redirect($this->url->link('checkout/cart'));
$this->session->data['error'] = 'Sorry we are closed on Sundays';
}
Here is the full code before I added my line;
<?php
class ControllerCheckoutCheckout extends Controller {
public function index() {
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$this->response->redirect($this->url->link('checkout/cart'));
}
// Validate minimum quantity requirements.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$this->response->redirect($this->url->link('checkout/cart'));
}
}
$this->load->language('checkout/checkout');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment/moment.min.js');
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment/moment-with-locales.min.js');
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
// Required by klarna
if ($this->config->get('payment_klarna_account') || $this->config->get('payment_klarna_invoice')) {
$this->document->addScript('http://cdn.klarna.com/public/kitt/toc/v1.0/js/klarna.terms.min.js');
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_cart'),
'href' => $this->url->link('checkout/cart')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('checkout/checkout', '', true)
);
$data['text_checkout_option'] = sprintf($this->language->get('text_checkout_option'), 1);
$data['text_checkout_account'] = sprintf($this->language->get('text_checkout_account'), 2);
$data['text_checkout_payment_address'] = sprintf($this->language->get('text_checkout_payment_address'), 2);
$data['text_checkout_shipping_address'] = sprintf($this->language->get('text_checkout_shipping_address'), 3);
$data['text_checkout_shipping_method'] = sprintf($this->language->get('text_checkout_shipping_method'), 4);
if ($this->cart->hasShipping()) {
$data['text_checkout_payment_method'] = sprintf($this->language->get('text_checkout_payment_method'), 5);
$data['text_checkout_confirm'] = sprintf($this->language->get('text_checkout_confirm'), 6);
} else {
$data['text_checkout_payment_method'] = sprintf($this->language->get('text_checkout_payment_method'), 3);
$data['text_checkout_confirm'] = sprintf($this->language->get('text_checkout_confirm'), 4);
}
if (isset($this->session->data['error'])) {
$data['error_warning'] = $this->session->data['error'];
unset($this->session->data['error']);
} else {
$data['error_warning'] = '';
}
$data['logged'] = $this->customer->isLogged();
if (isset($this->session->data['account'])) {
$data['account'] = $this->session->data['account'];
} else {
$data['account'] = '';
}
$data['shipping_required'] = $this->cart->hasShipping();
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('checkout/checkout', $data));
}
public function country() {
$json = array();
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
if ($country_info) {
$this->load->model('localisation/zone');
$json = array(
'country_id' => $country_info['country_id'],
'name' => $country_info['name'],
'iso_code_2' => $country_info['iso_code_2'],
'iso_code_3' => $country_info['iso_code_3'],
'address_format' => $country_info['address_format'],
'postcode_required' => $country_info['postcode_required'],
'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']),
'status' => $country_info['status']
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
public function customfield() {
$json = array();
$this->load->model('account/custom_field');
// Customer Group
if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->get['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
$json[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'required' => $custom_field['required']
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
Could anyone have any idea why this doesn't work or another way of disabling the checkout on Sundays?
If you put this line below befoe the redirection, the error message will show up.
$this->session->data['error'] = 'Sorry we are closed on Sundays';
here is code after the change
class ControllerCheckoutCheckout extends Controller {
public function index() {
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$this->response->redirect($this->url->link('checkout/cart'));
}
if (date("l") == "Sunday") {
$this->session->data['error'] = 'Sorry we are closed on Sundays';
$this->response->redirect($this->url->link('checkout/cart'));
}
Related
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class index extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('P_pmb', 'p_pmb');
}
public function index()
{
$data['title'] = 'Dashboard';
$this->render('index/index', $data);
}
public function pendaftarprodi1()
{
$data['title'] = 'Grafik Berdasarkan Prodi 1';
$prodi = $this->p_pmb->listProdi();
foreach ($prodi as $key => $p) {
$prodi[$key]['jumlah'] = $this->p_pmb->jumlahPendaftarProdi1($p['id_prodi']);
$prodi[$key]['jumlah2'] = $this->p_pmb->jumlahPendaftarProdi2($p['id_prodi']);
$prodi[$key]['size'] = rand(10, 30);
}
//grafik 1
$result = null;
foreach ($prodi as $p => $prod) {
// if ($prod['jumlah'] > $sum) {
// $sum = $prod['jumlah'];
// $sliced = true;
// $selected = true;
// }
$result[$p] = [
"name" => $prod['nama_prodi'],
"jumlah" => $prod['jumlah'],
"y" => $prod['size'],
// "sliced" => $sliced,
// 'selected' => $selected
];
}
$data['pendaftar'] = $prodi;
$data['grafik1'] = json_encode($result);
$this->render('index/grafik1', $data);
}
public function pendaftarprodi2()
{
$data['title'] = 'Grafik Berdasarkan Prodi 2';
$prodi = $this->p_pmb->listProdi();
foreach ($prodi as $key => $p) {
$prodi[$key]['jumlah'] = $this->p_pmb->jumlahPendaftarProdi1($p['id_prodi']);
$prodi[$key]['jumlah2'] = $this->p_pmb->jumlahPendaftarProdi2($p['id_prodi']);
$prodi[$key]['size'] = rand(10, 30);
}
//grafik 2
$hasil = null;
foreach ($prodi as $p => $prod) {
$hasil[$p] = [
"name" => $prod['nama_prodi'],
"jumlah" => $prod['jumlah2'],
"y" => $prod['size'],
// "sliced" => $sliced,
// 'selected' => $selected
];
}
$data['pendaftar'] = $prodi;
$data['grafik2'] = json_encode($hasil);
$this->render('index/grafik2', $data);
}
public function pendaftarprestasi()
{
$pendaftarprestasi = $this->p_pmb->listpendaftarprestasi();
foreach ($pendaftarprestasi as $key => $p) {
$pendaftarprestasi[$key]['jumlah'] = $this->p_pmb->jumlahpendaftarprestasi($p['tingkat_prestasi']);
$pendaftarprestasi[$key]['size'] = rand(10, 30);
}
$result = null;
$sum = 0;
foreach ($pendaftarprestasi as $p => $pendpres) {
//if ($pendpres['jumlah'] > $sum) {
// $sum = $pendpres['jumlah'];
// $sliced = true;
// $selected = true;
// }
$result[$p] = [
"name" => $pendpres['tingkat_prestasi'],
'jumlah' => $pendpres['jumlah'],
'y' => $pendpres['size'],
// $sliced => $sliced,
// $selected => $selected
];
}
$data['pendaftarprestasi'] = $pendaftarprestasi;
$data['grafikprestasi'] = json_encode($result);
$this->render('index/grafikprestasi', $data);
}
public function jalurmasuk()
{
$pendaftar = $this->p_pmb->listjalurpendaftar();
foreach ($pendaftar as $key => $p) {
$pendaftar[$key]['jumlah'] = $this->p_pmb->jumlahjalurpendaftar($p['nama_jalur']);
$pendaftar[$key]['jumlah'] = rand(10, 30);
}
$result = null;
$sum = 0;
foreach ($pendaftar as $p => $jalmask) {
//if ($jalmask['jumlah'] > $sum) {
// $sum = $jalmask['jumlah'];
// $sliced = true;
// $selected = true;
// }
$result[$p] = [
"name" => $jalmask['nama_jalur'],
'jumlah' => $jalmask['jumlah'],
'y' => $jalmask['jumlah'],
// $sliced => $sliced,
// $selected => $selected
];
}
$data['jalur_masuk'] = $jalmask;
$data['grafikmasuk'] = json_encode($result);
$this->render('index/grafikmasuk', $data);
}
public function pendapatan()
{
$data['title'] = 'Grafik Pendapatan Berdasarkan Bank';
$bank = $this->p_pmb->listBank();
$pendaftar = $this->p_pmb->pendaftarBank();
$categories = null;
$lunas = null;
$belum_lunas = null;
$sumTotal = 0;
foreach ($bank as $i => $b) {
$categories[] = $b['bank'];
foreach ($pendaftar as $key => $value) {
if ($b['id_bank'] == $value['id_bank']) {
if ($value['is_bayar'] == '1') {
$sumTotal += intval($value['total']);
$lunas[] = intval($value['total']);
} else {
$belum_lunas[] = intval($value['total']);
}
}
}
}
$result[] = [
'name' => 'Pendapatan',
'data' => $lunas,
];
$data['subtitle'] = 'Total Pendapatan Rp.' . $sumTotal;
$grafik['id_bank'] = json_encode($result);
$grafik['categories'] = json_encode($categories);
$data['grafikpendapatan'] = $grafik;
$this->render('index/grafikpendapatan', $data);
}
public function bank()
{
$data['title'] = 'Grafik Pendapatan Berdasarkan Bank';
$bank = $this->p_pmb->listBank();
$pendaftar = $this->p_pmb->pendaftarBank();
$categories = null;
$lunas = null;
$belum_lunas = null;
$sumTotal = 0;
foreach ($bank as $i => $b) {
$categories[] = $b['bank'];
foreach ($pendaftar as $key => $value) {
if ($b['id_bank'] == $value['id_bank']) {
if ($value['is_bayar'] == '1') {
$sumTotal += intval($value['total']);
$lunas[] = intval($value['total']);
} else {
$sumTotal += $value['jumlah'];
$belum_lunas[] = intval($value['total']);
}
}
}
}
$result[] = [
'name' => 'Lunas',
'data' => $lunas,
];
$result[] = [
'name' => 'Belum Lunas',
'data' => $belum_lunas,
];
$data['subtitle'] = 'Total Pendaftar: ' . $sumTotal;
$data['id_bank'] = $bank;
$data['grafikbank'] = json_encode($result);
$this->render('index/grafikbank', $data);
}
}
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class BaseController extends CI_Controller
{
public function render($filename, $data)
{
$this->load->view('template/app_top', $data);
$this->load->view('template/template_scripts', $data);
$this->load->view($filename, $data);
$this->load->view('template/app_bottom', $data);
}
}
so I have a problem with the stripe PaymentIntent status. Every time I edit the code I can purchase but only once. If I try to purchase something again it shows me this error:
This PaymentIntent's amount could not be updated because it has a status of succeeded. You may only update the amount of a PaymentIntent with one of the following statuses: requires_payment_method, requires_confirmation, requires_action.
The code for it is:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Srmklive\PayPal\Services\ExpressCheckout;
use App\Stock;
use App\OrderItem;
use App\Order;
use App\Coupon;
use App\Package;
use App\Mail\Reciepe;
use RealRashid\SweetAlert\Facades\Alert;
use Cart;
use Auth;
use Session;
use Cache;
use Mail;
class CartController extends Controller
{
protected $provider;
public function __construct() {
$this->provider = new ExpressCheckout();
}
// Add Item to Cart
public function addItem(Request $request)
{
$package = Package::where('id', $request->get('id'))->first();
// make sure there arent any more packages in the cart
Cart::destroy();
// add shit
Cart::add($package->id, $package->name, 1, $package->price, ['type' => 'package', 'fee' => $package->fee]);
if($request->fast) {
$this->setMethodCtrl('fast');
}
return redirect('/checkout');
}
// Add Item to Cart
public function addItemApi(Request $request)
{
$package = Package::where('id', $request->get('id'))->first();
// make sure there arent any more packages in the cart
Cart::destroy();
// add shit
Cart::add($package->id, $package->name, 1, $package->price, ['type' => 'package', 'fee' => $package->fee]);
if($request->fast) {
$this->setMethodCtrl('fast');
}
}
// Remove item from cart
public function removeItem($id)
{
$item = Cart::get($id);
if($item->options->type != "package") {
Cart::remove($id);
} else {
Cart::destroy();
}
return redirect()->back();
}
// View checkout page
public function checkout()
{
return view('gold.checkout');
}
// Handles bunch of stripe stuff
public function getStripeIntent() {
$currency = 'USD';
$fee = 0;
// Handle processing fee
foreach(\Cart::content() as $i) {
$fee += $i->options->fee;
}
$total = ((Cart::subtotal()) + $fee) * 100;
//Session::forget(Auth::user()->id.'-intent-new');
if(Cache::get(Auth::user()->id.'-intent-new')) {
// Update payment intent here
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$intent = \Stripe\PaymentIntent::update(
Cache::get(Auth::user()->id.'-intent-new')->id,
['amount' = $total]
);
} else {
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$intent = \Stripe\PaymentIntent::create([
'amount' = $total,
'currency' => 'usd',
]);
Cache::put(Auth::user()->id.'-intent-new', $intent, 60);
}
// handle order here
$order = Order::where('stripe_intent', $intent->client_secret)->first();
if(!$order) {
$order = new Order;
$order->our_tx = uniqid();
$order->user_id = Auth::user()->id;
$order->method = 'Stripe';
$order->currency = $currency;
$order->coupon = '';
$order->total = $total / 100;
$order->stripe_intent = $intent->client_secret;
$order->status = -1;
$order->fast_delivery = 0;
$order->save();
foreach(Cart::content() as $i) {
$item = new OrderItem;
$item->product_id = $i->id;
$item->order_id = $order->id;
$item->type = $i->options->type;
$item->name = $i->name;
$item->price = $i->price;
$item->amount = $i->qty;
$item->total = $i->price * $i->qty;
$item->save();
if($i->name == "Fast Delivery") {
$order->fast_delivery = 1;
$order->save();
}
}
} else {
$order->total = $total / 100;
$order->fast_delivery = 0;
$order->save();
$items = OrderItem::where('order_id', $order->id)->get();
foreach($items as $i) {
$i->delete();
}
foreach(Cart::content() as $i) {
$item = new OrderItem;
$item->product_id = $i->id;
$item->order_id = $order->id;
$item->type = $i->options->type;
$item->name = $i->name;
$item->price = $i->price;
$item->amount = $i->qty;
$item->total = $i->price * $i->qty;
$item->save();
if($i->name == "Fast Delivery") {
$order->fast_delivery = 1;
$order->save();
}
}
}
// Set intent order_id meta
$intent = \Stripe\PaymentIntent::update(
Cache::get(Auth::user()->id.'-intent-new')->id,
['metadata' => ['order_id' => $order->id]]
);
return $intent;
}
// Function for handling the checkout and various gateways
public function handleCheckout(Request $request)
{
$gateway = $request->get('payment_gateway');
$currency = 'USD';
$fee = 0;
// Handle Coupon
if($request->get('coupon') != "")
{
$coupon = Coupon::where('coupon', $request->get('coupon'))->first();
if(!$coupon)
{
$coupon = new Coupon;
$coupon->discount = 0;
}
} else {
$coupon = new Coupon;
$coupon->discount = 0;
}
// Handle processing fee
foreach(\Cart::content() as $i) {
$fee += $i->options->fee;
}
$total = Cart::subtotal() + $fee;
if($gateway == "paypal")
{
$provider = new ExpressCheckout;
$order = new Order;
$order->our_tx = uniqid();
$order->user_id = Auth::user()->id;
$order->method = 'Paypal';
$order->currency = $currency;
$order->coupon = '';
$order->total = $total;
$order->status = -1;
$order->fast_delivery = 0;
$order->save();
$data = [];
$data['items'] = array();
foreach(Cart::content() as $i) {
$item = new OrderItem;
$item->product_id = $i->id;
$item->order_id = $order->id;
$item->type = $i->options->type;
$item->name = $i->name;
$item->price = $i->price;
$item->amount = $i->qty;
$item->total = $i->price * $i->qty;
$item->save();
if($i->name == "Fast Delivery") {
$order->fast_delivery = 1;
$order->save();
}
array_push($data['items'], [
'name' => $item->name,
'price' => $item->price,
'qty' => $item->amount
]);
}
array_push($data['items'], [
'name' => 'Processing Fee',
'price' => $fee,
'qty' => 1
]);
// Paypal stuff
$options = [
'BRANDNAME' => env('APP_NAME'),
'LOGOIMG' => 'http://vaneblox.com/img/logo_desktop.png',
'CHANNELTYPE' => 'Merchant'
];
$data['invoice_id'] = $order->id;
$data['invoice_description'] = "Order #{$order->our_tx}";
$data['return_url'] = url('/success/'.$order->our_tx);
$data['cancel_url'] = url('/checkout');
$data['total'] = $order->total;
$response = $provider->addOptions($options)->setExpressCheckout($data);
//Cart::destroy();
return redirect($response['paypal_link']);
}
}
public function paypalSuccess($id, Request $request) {
$order = Order::where('our_tx', $id)->first();
// redo data thing
$data = [];
$fee = 0;
$data['items'] = array();
$items = $order->items;
foreach($items as $item) {
array_push($data['items'], [
'name' => $item->name,
'price' => $item->price,
'qty' => $item->amount
]);
}
foreach(\Cart::content() as $i) {
$fee += $i->options->fee;
}
array_push($data['items'], [
'name' => 'Processing Fee',
'price' => $fee,
'qty' => 1
]);
$data['invoice_id'] = $order->id;
$data['invoice_description'] = "Order #{$order->our_tx}";
$data['return_url'] = url('/success/'.$order->our_tx);
$data['cancel_url'] = url('/checkout');
$data['total'] = $order->total;
$token = $request->get('token');
$PayerID = $request->get('PayerID');
$response = $this->provider->getExpressCheckoutDetails($token);
if (!in_array(strtoupper($response['ACK']), ['SUCCESS', 'SUCCESSWITHWARNING'])) {
return redirect('/');
}
// charge the user
$payment_status = $this->provider->doExpressCheckoutPayment($data, $token, $PayerID);
$status = $payment_status['PAYMENTINFO_0_PAYMENTSTATUS'];
$order->status = 1;
$order->save();
Cart::destroy();
// Update Orders
$user = $order->user;
$user->orders += 1;
$user->paid += $order->total;
$user->save();
Mail::to($user)->send(new Reciepe($order));
// Here we check if the user has an old order that is in progress
if($user->order()->where(function($q) {
$q->where('status', 3)->orWhere('status', 1);
})->orderBy('id', 'asc')->count() > 1) {
$old_order = $user->order()->where(function($q) {
$q->where('status', 3)->orWhere('status', 1);
})->orderBy('id', 'asc')->first();
$items = $order->items;
foreach($items as $i) {
$item = new OrderItem;
$item->product_id = $i->product_id;
$item->order_id = $old_order->id;
$item->type = $i->type;
$item->name = $i->name;
$item->price = $i->price;
$item->amount = $i->amount;
$item->total = $i->total;
$item->new = 1;
$item->save();
if($i->name == "Fast Delivery") {
$old_order->fast_delivery = 1;
$old_order->save();
}
}
$old_order->total += $order->total;
$old_order->save();
$order->delete();
return redirect('/track/'.$old_order->our_tx);
}
return redirect('/track/'.$order->our_tx);
}
public function destroyCart() {
Cart::destroy();
}
// Handle new stripe orders etc.
public function stripeWebhook(Request $request) {
$order = Order::where('id', $request->data['object']['metadata']['order_id'])->first();
// Mark order as paid
if($order) {
$order->status = 1;
$order->save();
// Update Orders
$user = $order->user;
$user->orders += 1;
$user->paid += $order->total;
$user->save();
// mail user
Mail::to($user)->send(new Reciepe($order));
Cache::forget($order->user_id.'-intent-new');
// Here we check if the user has an old order that is in progress
if($user->order()->where(function($q) {
$q->where('status', 3)->orWhere('status', 1);
})->orderBy('id', 'asc')->count() > 1) {
$old_order = $user->order()->where(function($q) {
$q->where('status', 3)->orWhere('status', 1);
})->orderBy('id', 'asc')->first();
$items = $order->items;
foreach($items as $i) {
$item = new OrderItem;
$item->product_id = $i->product_id;
$item->order_id = $old_order->id;
$item->type = $i->type;
$item->name = $i->name;
$item->price = $i->price;
$item->amount = $i->amount;
$item->total = $i->total;
$item->new = 1;
$item->save();
if($i->name == "Fast Delivery") {
$old_order->fast_delivery = 1;
$old_order->save();
}
}
$old_order->total += $order->total;
$old_order->save();
$order->delete();
}
}
}
public function paypalWebhook(Request $request) {
Log::info($request);
/*
$order = Order::where('id', $request->invoice)->first();
// Mark order as paid
if($order) {
$order->status = 1;
$order->save();
}
*/
}
// For setting delivery method
public function setMethod($method) {
if($method == "fast") {
foreach(Cart::content() as $i) {
if($i->name == 'Fast Delivery') {
return redirect('/checkout');
}
}
Cart::add(666, 'Fast Delivery', 1, 15, ['type' => 'delivery']);
} else {
foreach(Cart::content() as $i) {
if($i->name == 'Fast Delivery') {
Cart::remove($i->rowId);
}
}
}
return redirect()->back();
}
public function setMethodCtrl($method) {
if($method == "fast") {
foreach(Cart::content() as $i) {
if($i->name == 'Fast Delivery') {
return redirect('/checkout');
}
}
Cart::add(666, 'Fast Delivery', 1, 15, ['type' => 'delivery']);
} else {
foreach(Cart::content() as $i) {
if($i->name == 'Fast Delivery') {
Cart::remove($i->rowId);
}
}
}
}
}
I am thinking that is a problem about this part:
foreach(\Cart::content() as $i) {
$fee += $i->options->fee;
}
$total = ((Cart::subtotal()) + $fee) * 100;
//Session::forget(Auth::user()->id.'-intent-new');
if(Cache::get(Auth::user()->id.'-intent-new')) {
// Update payment intent here
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$intent = \Stripe\PaymentIntent::update(
Cache::get(Auth::user()->id.'-intent-new')->id,
['amount' = $total]
);
} else {
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$intent = \Stripe\PaymentIntent::create([
'amount' = $total,
'currency' => 'usd',
]);
Cache::put(Auth::user()->id.'-intent-new', $intent, 60);
}
But I don't know how to fix it, someone who can help me out ?
While you can update the amount on a given Payment Intent (while customer modifies their cart, for example), they can only be used for a single actual payment.
If you need to collect multiple payments, you will need to create multiple Payment Intents.
I tried to generate a REST API for my customers, categories, products, coupons, manufacturers and all others to use it in my Android application, but I can't get any solution.
Can anyone tell me how to create APIs in opencart 3.0.2.0?
Make a custom controller in catalog > Controller > api folder
Create controller file name: allproducts.php
You can copy following code and paste of allproducts.php
<?php
class ControllerApiAllproducts extends Controller {
private $error = array();
// All Products
public function index(){
$products = array();
$this->load->language('catalog/product');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$error[]['no_json']= "No JSON";
$product_total = $this->model_catalog_product->getTotalProducts();
$results = $this->model_catalog_product->getProducts();
foreach ($results as $result) {
if (is_file(DIR_IMAGE . $result['image'])) {
$image = $this->model_tool_image->resize($result['image'], 40, 40);
} else {
$image = $this->model_tool_image->resize('no_image.png', 40, 40);
}
$special = false;
$product_specials = $this->model_catalog_product->getProductSpecials($result['product_id']);
foreach ($product_specials as $product_special) {
//if (($product_special['date_start'] == '0000-00-00' || strtotime($product_special['date_start']) < time()) && ($product_special['date_end'] == '0000-00-00' || strtotime($product_special['date_end']) > time())) {
$special = $product_special['price'];
//break;
// }
}
$shop_products['shop_products'][] = array(
'product_id' => $result['product_id'],
'image' => $image,
'name' => $result['name'],
'model' => $result['model'],
'price' => $result['price'],
'special' => $special,
'quantity' => $result['quantity'],
'status' => $result['status']
);
}
if (isset($this->request->get['json'])) {
echo json_encode($shop_products);die;
} else {
$this->response->setOutput(json_encode($error));
}
}
// Product info Page
public function productInfo(){
$this->load->language('catalog/product');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$product_details = array();
$error['fail'] = 'Failed';
if (isset($this->request->get['product_id'])) {
//$product_details['product_id'] = $this->request->get['product_id'];
$product_details = $this->model_catalog_product->getProduct($this->request->get['product_id']);
echo json_encode($product_details);die;
} else {
$this->response->setOutput(json_encode($error));
}
}
// Category Listing Page
public function categories(){
$shop_categories = array();
$this->load->model('catalog/category');
$error['fail'] = 'Failed';
if (isset($this->request->get['json'])) {
$shop_categories =$this->model_catalog_category->getCategories();
echo json_encode($shop_categories);die;
} else {
$this->response->setOutput(json_encode($error));
}
}
// Product Listing By Category
public function categoryList(){
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$error['fail'] = 'Failed';
if (isset($this->request->get['path'])) {
$url = '';
$path = '';
$parts = explode('_', (string)$this->request->get['path']);
$category_id = (int)array_pop($parts);
foreach ($parts as $path_id) {
if (!$path) {
$path = (int)$path_id;
} else {
$path .= '_' . (int)$path_id;
}
$category_info = $this->model_catalog_category->getCategory($path_id);
}
} else {
$category_id = 0;
}
$category_info = $this->model_catalog_category->getCategory($category_id);
if ($category_info) {
$url = '';
//$data['categories'] = array();
$results = $this->model_catalog_category->getCategories($category_id);
foreach ($results as $result) {
$filter_data = array(
'filter_category_id' => $result['category_id'],
'filter_sub_category' => true
);
}
$products = array();
$filter_data = array(
'filter_category_id' => $category_id
);
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$products = $this->model_catalog_product->getProducts($filter_data);
echo json_encode($products); die;
} else {
$this->response->setOutput(json_encode($error));
}
}
// All Manufacturers Listing
public function manufactureList() {
$this->load->model('catalog/manufacturer');
$this->load->model('tool/image');
$error['fail'] = 'Failed';
$manufactureList = array();
if (isset($this->request->get['json'])) {
$manufactureList = $this->model_catalog_manufacturer->getManufacturers();
echo json_encode($manufactureList);die;
} else {
$this->response->setOutput(json_encode($error));
}
}
// Manufactur info Page
public function manufactureInfo() {
$this->load->model('catalog/manufacturer');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$error['fail'] = 'Failed';
if (isset($this->request->get['manufacturer_id'])) {
$manufactureInfo = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
echo json_encode($product_details);die;
} else {
$this->response->setOutput(json_encode($error));
}
}
// Category Listing Page
public function specialProduct(){
$specialProduct = array();
$this->load->model('catalog/product');
$this->load->model('tool/image');
$error['fail'] = 'Failed';
if (isset($this->request->get['json'])) {
$specialProduct = $this->model_catalog_product->getProductSpecials();
echo json_encode($specialProduct);die;
} else {
$this->response->setOutput(json_encode($error));
}
}
}
I made following APIs and its path (see Postman apps):
ALL Products : http://examples.com/index.php?route=api/allproducts&json
Product By ID : http://examples.com/index.php?route=api/allproducts/productInfo&json&product_id=30
ALL Categories : http://examples.com/index.php?route=api/allproducts/categories&json
Category Wise Product : http://examples.com/index.php?route=api/allproducts/categoryList&json&path=25_28
ALL Manufacturers : http://examples.com/index.php?route=api/allproducts/manufactureList&json
Manufactur By ID : http://examples.com/index.php?route=api/allproducts/manufactureInfo&manufacturer_id=11
Special Products : http://examples.com/index.php?route=api/allproducts/specialProduct&json
I am newer in Open cart frame work. I am working to create custom page with file uploading and direct checkout button(just like shopping cart page.)In this page, i already create (tpl files) view and controller based on contact form.
Here my controller:
<?php
class ControllerInformationRequest extends Controller {
private $error = array();
public function index() {
$this->language->load('information/request');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('account/request');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->redirect($this->url->link('information/request/success'));
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/request'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_location'] = $this->language->get('text_location');
$this->data['text_contact'] = $this->language->get('text_contact');
$this->data['text_address'] = $this->language->get('text_address');
$this->data['text_telephone'] = $this->language->get('text_telephone');
$this->data['text_fax'] = $this->language->get('text_fax');
$this->data['entry_name'] = $this->language->get('entry_name');
$this->data['entry_email'] = $this->language->get('entry_email');
$this->data['entry_enquiry'] = $this->language->get('entry_enquiry');
$this->data['entry_captcha'] = $this->language->get('entry_captcha');
$this->data['entry_phone'] = $this->language->get('entry_phone');
if (isset($this->error['name'])) {
$this->data['error_name'] = $this->error['name'];
} else {
$this->data['error_name'] = '';
}
if (isset($this->error['telephone'])) {
$this->data['error_telephone'] = $this->error['telephone'];
} else {
$this->data['error_telephone'] = '';
}
if (isset($this->error['email'])) {
$this->data['error_email'] = $this->error['email'];
} else {
$this->data['error_email'] = '';
}
if (isset($this->error['enquiry'])) {
$this->data['error_enquiry'] = $this->error['enquiry'];
} else {
$this->data['error_enquiry'] = '';
}
if (isset($this->error['captcha'])) {
$this->data['error_captcha'] = $this->error['captcha'];
} else {
$this->data['error_captcha'] = '';
}
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['action'] = $this->url->link('information/request');
$this->data['store'] = $this->config->get('config_name');
$this->data['address'] = nl2br($this->config->get('config_address'));
$this->data['telephone'] = $this->config->get('config_telephone');
$this->data['fax'] = $this->config->get('config_fax');
if (isset($this->request->post['name'])) {
$this->data['name'] = $this->request->post['name'];
} else {
$this->data['name'] = $this->customer->getFirstName();
}
if (isset($this->request->post['email'])) {
$this->data['email'] = $this->request->post['email'];
} else {
$this->data['email'] = $this->customer->getEmail();
}
if (isset($this->request->post['telephone'])) {
$this->data['telephone'] = $this->request->post['telephone'];
} else {
//$this->data['phone'] = $this->customer->getPhone();
$this->data['telephone'] = $this->customer->getTelephone();
}
if (isset($this->request->post['enquiry'])) {
$this->data['enquiry'] = $this->request->post['enquiry'];
} else {
$this->data['enquiry'] = '';
}
if (isset($this->request->post['captcha'])) {
$this->data['captcha'] = $this->request->post['captcha'];
} else {
$this->data['captcha'] = '';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/request.tpl')) {
$this->template = $this->config->get('config_template') . '/template/information/request.tpl';
} else {
$this->template = 'default/template/information/request.tpl';
}
$this->load->model('account/request');
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
public function success() {
$this->language->load('information/request');
$this->document->setTitle($this->language->get('heading_title'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/request'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_message'] = $this->language->get('text_message');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['continue'] = $this->url->link('common/home');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/success.tpl';
} else {
$this->template = 'default/template/common/success.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
private function validate() {
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
$this->error['name'] = $this->language->get('error_name');
}
if (!preg_match('/^[^\#]+#.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
$this->error['email'] = $this->language->get('error_email');
}
if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
$this->error['enquiry'] = $this->language->get('error_enquiry');
}
if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
$this->error['captcha'] = $this->language->get('error_captcha');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
public function captcha() {
$this->load->library('captcha');
$captcha = new Captcha();
$this->session->data['captcha'] = $captcha->getCode();
$captcha->showImage();
}
}
?>
In view .tpl files contain name,Email address, phone,message and captcha images.I just want to stored that data into database,I already create model file in particular locations,
How to call model file ($this->load->model('account/request');)...its doesnt working and its cant stored database also.How is it possible ?please provide me solutions for this....
To load model from controller use this syntax;
for instance to load opencart folder / catalog/model/catalog/category
$this->load->model('catalog/category');
then you can happily call method from that model like below ;
$categories = $this->model_catalog_category->getCategories(0);
newbies should be encouraged. rather discouraging
I am new an having problems in understanding docs of php.
can someone give the exact code steps for my future reference to :
I want to run this query:
$query = $this->db->query("SELECT tracking_code FROM " . DB_PREFIX . "customer WHERE language_id = '" . (int)$this->customer->getId() . "'");
(I know it will return only one value) and 1. if "if tacking named cookie exists, delete it or replace it and set a cookie named "tracking" for one year with the value returned by that query. How can i do it?
I know little about php . but i get the feeling that i have no reference to db in that confirm.php . it doesnot extends model, nor i know would $this work here or not
the file iam working on is.
<?php
class ControllerCheckoutConfirm extends Controller {
public function index() {
$redirect = '';
if ($this->cart->hasShipping()) {
// Validate if shipping address has been set.
$this->load->model('account/address');
if ($this->customer->isLogged() && isset($this->session->data['shipping_address_id'])) {
$shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
} elseif (isset($this->session->data['guest'])) {
$shipping_address = $this->session->data['guest']['shipping'];
}
if (empty($shipping_address)) {
$redirect = $this->url->link('checkout/checkout', '', 'SSL');
}
// Validate if shipping method has been set.
if (!isset($this->session->data['shipping_method'])) {
$redirect = $this->url->link('checkout/checkout', '', 'SSL');
}
} else {
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
}
// Validate if payment address has been set.
$this->load->model('account/address');
if ($this->customer->isLogged() && isset($this->session->data['payment_address_id'])) {
$payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']);
} elseif (isset($this->session->data['guest'])) {
$payment_address = $this->session->data['guest']['payment'];
}
if (empty($payment_address)) {
$redirect = $this->url->link('checkout/checkout', '', 'SSL');
}
// Validate if payment method has been set.
if (!isset($this->session->data['payment_method'])) {
$redirect = $this->url->link('checkout/checkout', '', 'SSL');
}
// Validate cart has products and has stock.
if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$redirect = $this->url->link('checkout/cart');
}
// Validate minimum quantity requirments.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$redirect = $this->url->link('checkout/cart');
break;
}
}
if (!$redirect) {
$total_data = array();
$total = 0;
$taxes = $this->cart->getTaxes();
$this->load->model('setting/extension');
$sort_order = array();
$results = $this->model_setting_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get($result['code'] . '_status')) {
$this->load->model('total/' . $result['code']);
$this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
}
}
$sort_order = array();
foreach ($total_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $total_data);
$this->language->load('checkout/checkout');
$data = array();
$data['invoice_prefix'] = $this->config->get('config_invoice_prefix');
$data['store_id'] = $this->config->get('config_store_id');
$data['store_name'] = $this->config->get('config_name');
if ($data['store_id']) {
$data['store_url'] = $this->config->get('config_url');
} else {
$data['store_url'] = HTTP_SERVER;
}
if ($this->customer->isLogged()) {
$data['customer_id'] = $this->customer->getId();
$data['customer_group_id'] = $this->customer->getCustomerGroupId();
$data['firstname'] = $this->customer->getFirstName();
$data['lastname'] = $this->customer->getLastName();
$data['email'] = $this->customer->getEmail();
$data['telephone'] = $this->customer->getTelephone();
$data['fax'] = $this->customer->getFax();
$this->load->model('account/address');
$payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']);
} elseif (isset($this->session->data['guest'])) {
$data['customer_id'] = 0;
$data['customer_group_id'] = $this->session->data['guest']['customer_group_id'];
$data['firstname'] = $this->session->data['guest']['firstname'];
$data['lastname'] = $this->session->data['guest']['lastname'];
$data['email'] = $this->session->data['guest']['email'];
$data['telephone'] = $this->session->data['guest']['telephone'];
$data['fax'] = $this->session->data['guest']['fax'];
$payment_address = $this->session->data['guest']['payment'];
}
$data['payment_firstname'] = $payment_address['firstname'];
$data['payment_lastname'] = $payment_address['lastname'];
$data['payment_company'] = $payment_address['company'];
$data['payment_company_id'] = $payment_address['company_id'];
$data['payment_tax_id'] = $payment_address['tax_id'];
$data['payment_address_1'] = $payment_address['address_1'];
$data['payment_address_2'] = $payment_address['address_2'];
$data['payment_city'] = $payment_address['city'];
$data['payment_postcode'] = $payment_address['postcode'];
$data['payment_zone'] = $payment_address['zone'];
$data['payment_zone_id'] = $payment_address['zone_id'];
$data['payment_country'] = $payment_address['country'];
$data['payment_country_id'] = $payment_address['country_id'];
$data['payment_address_format'] = $payment_address['address_format'];
if (isset($this->session->data['payment_method']['title'])) {
$data['payment_method'] = $this->session->data['payment_method']['title'];
} else {
$data['payment_method'] = '';
}
if (isset($this->session->data['payment_method']['code'])) {
$data['payment_code'] = $this->session->data['payment_method']['code'];
} else {
$data['payment_code'] = '';
}
if ($this->cart->hasShipping()) {
if ($this->customer->isLogged()) {
$this->load->model('account/address');
$shipping_address = $this->model_account_address->getAddress($this->session->data['shipping_address_id']);
} elseif (isset($this->session->data['guest'])) {
$shipping_address = $this->session->data['guest']['shipping'];
}
$data['shipping_firstname'] = $shipping_address['firstname'];
$data['shipping_lastname'] = $shipping_address['lastname'];
$data['shipping_company'] = $shipping_address['company'];
$data['shipping_address_1'] = $shipping_address['address_1'];
$data['shipping_address_2'] = $shipping_address['address_2'];
$data['shipping_city'] = $shipping_address['city'];
$data['shipping_postcode'] = $shipping_address['postcode'];
$data['shipping_zone'] = $shipping_address['zone'];
$data['shipping_zone_id'] = $shipping_address['zone_id'];
$data['shipping_country'] = $shipping_address['country'];
$data['shipping_country_id'] = $shipping_address['country_id'];
$data['shipping_address_format'] = $shipping_address['address_format'];
if (isset($this->session->data['shipping_method']['title'])) {
$data['shipping_method'] = $this->session->data['shipping_method']['title'];
} else {
$data['shipping_method'] = '';
}
if (isset($this->session->data['shipping_method']['code'])) {
$data['shipping_code'] = $this->session->data['shipping_method']['code'];
} else {
$data['shipping_code'] = '';
}
} else {
$data['shipping_firstname'] = '';
$data['shipping_lastname'] = '';
$data['shipping_company'] = '';
$data['shipping_address_1'] = '';
$data['shipping_address_2'] = '';
$data['shipping_city'] = '';
$data['shipping_postcode'] = '';
$data['shipping_zone'] = '';
$data['shipping_zone_id'] = '';
$data['shipping_country'] = '';
$data['shipping_country_id'] = '';
$data['shipping_address_format'] = '';
$data['shipping_method'] = '';
$data['shipping_code'] = '';
}
$product_data = array();
foreach ($this->cart->getProducts() as $product) {
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['option_value'];
} else {
$value = $this->encryption->decrypt($option['option_value']);
}
$option_data[] = array(
'product_option_id' => $option['product_option_id'],
'product_option_value_id' => $option['product_option_value_id'],
'option_id' => $option['option_id'],
'option_value_id' => $option['option_value_id'],
'name' => $option['name'],
'value' => $value,
'type' => $option['type']
);
}
$product_data[] = array(
'product_id' => $product['product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'download' => $product['download'],
'quantity' => $product['quantity'],
'subtract' => $product['subtract'],
'price' => $product['price'],
'total' => $product['total'],
'tax' => $this->tax->getTax($product['price'], $product['tax_class_id']),
'reward' => $product['reward']
);
}
// Gift Voucher
$voucher_data = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $voucher) {
$voucher_data[] = array(
'description' => $voucher['description'],
'code' => substr(md5(mt_rand()), 0, 10),
'to_name' => $voucher['to_name'],
'to_email' => $voucher['to_email'],
'from_name' => $voucher['from_name'],
'from_email' => $voucher['from_email'],
'voucher_theme_id' => $voucher['voucher_theme_id'],
'message' => $voucher['message'],
'amount' => $voucher['amount']
);
}
}
$data['products'] = $product_data;
$data['vouchers'] = $voucher_data;
$data['totals'] = $total_data;
$data['comment'] = $this->session->data['comment'];
$data['total'] = $total;
$query = $this->db->query("SELECT affiliate_code FROM " . DB_PREFIX . "customer WHERE language_id = '" . (int)$this->customer->getId() . "'");
//set cookie $query->rows;
if (isset($this->request->cookie['tracking'])) {
$this->load->model('affiliate/affiliate');
$affiliate_info = $this->model_affiliate_affiliate->getAffiliateByCode($this->request->cookie['tracking']);
$subtotal = $this->cart->getSubTotal();
if ($affiliate_info) {
$data['affiliate_id'] = $affiliate_info['affiliate_id'];
$data['commission'] = ($subtotal / 100) * $affiliate_info['commission'];
} else {
$data['affiliate_id'] = 0;
$data['commission'] = 0;
}
} else {
$data['affiliate_id'] = 0;
$data['commission'] = 0;
}
$data['language_id'] = $this->config->get('config_language_id');
$data['currency_id'] = $this->currency->getId();
$data['currency_code'] = $this->currency->getCode();
$data['currency_value'] = $this->currency->getValue($this->currency->getCode());
$data['ip'] = $this->request->server['REMOTE_ADDR'];
if (!empty($this->request->server['HTTP_X_FORWARDED_FOR'])) {
$data['forwarded_ip'] = $this->request->server['HTTP_X_FORWARDED_FOR'];
} elseif(!empty($this->request->server['HTTP_CLIENT_IP'])) {
$data['forwarded_ip'] = $this->request->server['HTTP_CLIENT_IP'];
} else {
$data['forwarded_ip'] = '';
}
if (isset($this->request->server['HTTP_USER_AGENT'])) {
$data['user_agent'] = $this->request->server['HTTP_USER_AGENT'];
} else {
$data['user_agent'] = '';
}
if (isset($this->request->server['HTTP_ACCEPT_LANGUAGE'])) {
$data['accept_language'] = $this->request->server['HTTP_ACCEPT_LANGUAGE'];
} else {
$data['accept_language'] = '';
}
$this->load->model('checkout/order');
$this->session->data['order_id'] = $this->model_checkout_order->addOrder($data);
$this->data['column_name'] = $this->language->get('column_name');
$this->data['column_model'] = $this->language->get('column_model');
$this->data['column_quantity'] = $this->language->get('column_quantity');
$this->data['column_price'] = $this->language->get('column_price');
$this->data['column_total'] = $this->language->get('column_total');
$this->data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['option_value'];
} else {
$filename = $this->encryption->decrypt($option['option_value']);
$value = utf8_substr($filename, 0, utf8_strrpos($filename, '.'));
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
);
}
$this->data['products'][] = array(
'product_id' => $product['product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'subtract' => $product['subtract'],
'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))),
'total' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']),
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);
}
// Gift Voucher
$this->data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $voucher) {
$this->data['vouchers'][] = array(
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'])
);
}
}
$this->data['totals'] = $total_data;
$this->data['payment'] = $this->getChild('payment/' . $this->session->data['payment_method']['code']);
} else {
$this->data['redirect'] = $redirect;
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/confirm.tpl')) {
$this->template = $this->config->get('config_template') . '/template/checkout/confirm.tpl';
} else {
$this->template = 'default/template/checkout/confirm.tpl';
}
$this->response->setOutput($this->render());
}
}
?>
It can be done this way .
<?php
$query = $this->db->query("SELECT tracking_code FROM " . DB_PREFIX . "customer WHERE language_id = '" . (int)$this->customer->getId() . "'");
if(isset($_COOKIE['tracking'])){
setcookie('tracking', '', time()-1);
sleep(1); // sleep for 1 sec
setcookie('tracking', '$query->row["tracking_code"]', time()+60*60*24*30*12);
}else{
setcookie('tracking', '$query->row["tracking_code"]', time()+60*60*24*30*12);
}
?>
So in the if condition ,if your cookie named tracking is set than it will delete it with 1 sec and and apply you new value from $query . I hope this will work .