I need load files order by "time DESC" when the iframe of laravel-filemanager is called.
Is posible? I read the code and see that we cant order by time DESC and the code dont have options to configure a default "sort_type"
https://github.com/UniSharp/laravel-filemanager
this is not good idea but it's work for me
i am change the code in vendor/unisharp/laravel-filemanager/public/js/script.js
var sort_type = 'alphabetic';
to
var sort_type = 'time';
if you want to sort date in desc order. change the code in
vendor/unisharp/laravel-filemanager/src/Controllers/ItemsController.php
public function getItems()
{
$currentPage = self::getCurrentPageFromRequest();
$perPage = $this->helper->getPaginationPerPage();
$items = array_merge($this->lfm->folders(), $this->lfm->files());
return [
'items' => array_map(function ($item) {
return $item->fill()->attributes;
}, array_slice($items, ($currentPage - 1) * $perPage, $perPage)),
'paginator' => [
'current_page' => $currentPage,
'total' => count($items),
'per_page' => $perPage,
],
'display' => $this->helper->getDisplayMode(),
'working_dir' => $this->lfm->path('working_dir'),
];
}
with
use Illuminate\Http\Request;
public function getItems(Request $request)
{
$currentPage = self::getCurrentPageFromRequest();
$perPage = $this->helper->getPaginationPerPage();
$files = $this->lfm->files();
if($request->sort_type=='time'){
$files = array_reverse($files);
}
$items = array_merge($this->lfm->folders(), $files);
return [
'items' => array_map(function ($item) {
return $item->fill()->attributes;
}, array_slice($items, ($currentPage - 1) * $perPage, $perPage)),
'paginator' => [
'current_page' => $currentPage,
'total' => count($items),
'per_page' => $perPage,
],
'display' => $this->helper->getDisplayMode(),
'working_dir' => $this->lfm->path('working_dir'),
];
}
i'm change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php
and it's worked
public function sortFilesAndDirectories($arr_items, $sort_type)
{
if ($sort_type == 'time') {
$key_to_sort = 'updated';
} elseif ($sort_type == 'alphabetic') {
$key_to_sort = 'name';
} else {
$key_to_sort = 'updated';
}
return strcmp($a->{$key_to_sort}, $b->{$key_to_sort});
});
return $arr_items;
}
with
public function sortFilesAndDirectories($arr_items, $sort_type)
{
if ($sort_type == 'time') {
$key_to_sort = 'updated';
} elseif ($sort_type == 'alphabetic') {
$key_to_sort = 'name';
} else {
$key_to_sort = 'updated';
}
uasort($arr_items, function ($a, $b) use ($key_to_sort) {
if ( $a->$key_to_sort == $a->$key_to_sort )
return 0;
else if ( $a->$key_to_sort > $a->$key_to_sort)
return -1;
else
return 1;
});
return $arr_items;
}
LFM 1.8:
Also, you can use this method, if you don't want to change the LFM Src code.
First use this command to generate views :
php artisan vendor:publish --tag=lfm_view
Find this file:
ROOT/resources/views/vendor/laravel-filemanager/grid-view.blade.php
and change the cod according the follow:
#if((sizeof($files) > 0) || (sizeof($directories) > 0))
<div class="row">
<!-- -----------------------------------Begin of added block -->
<?php
$file_temp = [];
if($files != null){
foreach ($files as $key => $value) {
$file_temp[$value['updated']] = $value;
}
krsort($file_temp);
$file_temp1 = [];
$i = 0;
foreach ($file_temp as $key => $value) {
$file_temp1[$i] = $value;
$i+=1;
}
$files = $file_temp1;
}
?>
<!-- ---------------------------------------End of added block -->
#foreach($items as $item)
....
...
As you can see, the <?php ?> code block was added.You can use krsort() or ksort() as you want for descending or ascending.
In 2.3 I did next steps
php artisan vendor:publish --tag=lfm_view
Then you can find file
ROOT/resources/views/vendor/laravel-filemanager/grid-view.blade.php
And after incuding
<script>{!! \File::get(base_path('vendor/unisharp/laravel-filemanager/public/js/script.js')) !!}</script>
I added one line of js
sort_type = 'time';
But files sorts from the oldest to the newest. Thast's why I redefined routes and ItemsController
Related
I am developing a Opencart module (Version 4.0.0.0).
Created the module with height and status. Installed the same in the Opencart application. But the problem is when I tried to save the value to the db, it is creating a new row inside "oc_module" table. While checking I just found that "module_id" is not appending the URL from the module listing page's edit button.
The testimonial module link looks like
http://localhost/op4/admin/index.php?route=extension/testimonials/module/testimonials&user_token=2e7a4d8fad2e1c4339e9c01bc83d707a
extensions --> testimonial --> admin --> controller --> module --> testimonials.php
<?php
namespace Opencart\Admin\Controller\Extension\Testimonials\Module;
class Testimonials extends \Opencart\System\Engine\Controller {
public function index(): void {
$this->load->language('extension/testimonials/module/testimonials');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/setting');
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module')
];
if (!isset($this->request->get['module_id'])) {
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/testimonials/module/testimonials', 'user_token=' . $this->session->data['user_token'])
];
} else {
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/testimonials/module/testimonials', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'])
];
}
if (!isset($this->request->get['module_id'])) {
$data['save'] = $this->url->link('extension/testimonials/module/testimonials|save', 'user_token=' . $this->session->data['user_token']);
} else {
$data['save'] = $this->url->link('extension/testimonials/module/testimonials|save', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']);
}
$data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module');
if (isset($this->request->get['module_id'])) {
$this->load->model('setting/module');
$module_info = $this->model_setting_module->getModule($this->request->get['module_id']);
print_r($module_info);
}
if (isset($module_info['name'])) {
$data['name'] = $module_info['name'];
} else {
$data['name'] = '';
}
if (isset($module_info['height'])) {
$data['height'] = $module_info['height'];
} else {
$data['height'] = 200;
}
if (isset($module_info['status'])) {
$data['status'] = $module_info['status'];
} else {
$data['status'] = '';
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/testimonials/module/testimonials', $data));
}
public function save(): void {
$this->load->language('extension/testimonials/module/testimonials');
$json = [];
if (!$this->user->hasPermission('modify', 'extension/testimonials/module/testimonials')) {
$json['error']['warning'] = $this->language->get('error_permission');
}
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) {
$json['error']['name'] = $this->language->get('error_name');
}
if (!$this->request->post['height']) {
$json['error']['height'] = $this->language->get('error_height');
}
if (!$json) {
$this->load->model('setting/module');
if (!isset($this->request->get['module_id'])) {
$this->model_setting_module->addModule('module_testimonials', $this->request->post);
} else {
$this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
You have error in your save function.
You need to change: $this->model_setting_module->addModule('module_testimonials', $this->request->post);
to:
$this->model_setting_module->addModule('testimonials.testimonials', $this->request->post);
I've been searching for this solution, couldn't find anything reasonably to what AWS currently have on their UI, so came up with mine in laravel, and dropping it here to help anyone hopefully searching for this as well.
public function convertTextToSpeakers($response)
{
$segments = $response['results']['speaker_labels']['segments'];
$items = $response['results']['items'];
$result = [];
foreach ($items as $key => $item) {
if (!isset($item['start_time'])) {
$prev_item = $items[$key - 1];
if ($prev_item) {
$item['start_time'] = $prev_item['start_time'];
$item['end_time'] = $prev_item['end_time'];
$items[$key] = $item;
}
}
}
foreach ($segments as $key => $segment) {
$has_data = true;
$temp_key = $key;
while ($has_data) {
$temp_key++;
$next_segment = $segments[$temp_key] ?? null;
if ($next_segment && $next_segment['speaker_label'] == $segment['speaker_label']) {
$itemsData = array_merge($segment['items'], $next_segment['items']);
$segment['items'] = $itemsData;
unset($segments[$temp_key]);
$segments[$key] = $segment;
} else {
$has_data = false;
}
}
}
$items = collect($items);
$segments = collect($segments)->sortBy('start_time');
foreach ($segments as $segment) {
$text = '';
$segmentItems = collect($segment['items'])->sortBy('start_time');
foreach ($segmentItems as $seg_item) {
$words = $items->where('start_time', $seg_item['start_time'])
->where('end_time', $seg_item['end_time']);
foreach ($words as $word) {
$text .= $word['alternatives'][0]['content'];
}
$text .= " ";
}
$result[] = [
'speaker' => $segment['speaker_label'],
'text' => $text,
];
}
return $result;
}
I need your help in how can I change this controller code of opencart 2.3 extension to be compatible for opencart 3.X,
I have changed the tpl files in admin/view/template/extension/payment/ to twig with their parameters
also I changed the 'token=' to user_token in the controller
file path
admin/controller/extension/payment/
<?php
class ControllerExtensionPaymentIcredit extends Controller {
private $error = array();
public function install()
{
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "iCredit` (
`id_icredit` int(1) NOT NULL AUTO_INCREMENT,
`enabled` varchar(255),
`PaymentMethodDescription` varchar(500) CHARACTER SET utf8,
`title` varchar(255) CHARACTER SET utf8,
`testmode` varchar(1),
`testtoken` varchar(255),
`grouptoken` varchar(500),
`maxpayment` varchar(255),
`creditpayment` varchar(500),
`windowtype` varchar(255),
`height` int(10),
`width` int(10),
`hideitemlist` varchar(1),
`createtoken` varchar(1),
`invoicelang` varchar(500),
`exemptvat` varchar(255),
`redirecturl` varchar(500),
`ipn` varchar(500),
`sortorder` varchar(500),
`date_added` datetime,
PRIMARY KEY (`id_icredit`)
)");
}
public function uninstall()
{
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "iCredit");
}
public function index()
{ // Default function
$this->install();
$this->load->language('extension/payment/icredit'); // Loading the language file of helloworld
$this->document->setTitle($this->language->get('heading_title')); // Set the title of the page to the heading title in the Language file i.e., Hello World
$this->load->model('setting/setting');
$this->load->model('extension/payment/icredit'); // Load the Setting Model (All of the OpenCart Module & General Settings are saved using this Model )
//fwrite($file,$this->validate()." -- validate\r\n");
//fwrite($file,print_r($_POST,TRUE)." -- post\r\n");
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate())
{
if ($this->request->post['icredit_id'] == "")
{
$this->model_setting_setting->editSetting('icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->addicreditsettings($this->request->post);
}
else
{
$this->model_setting_setting->editSetting('icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->editicreditsettings($this->request->post);
}
$this->session->data['success'] = $this->language->get('text_success'); // To display the success text on data save=
if($check == 1)
{
$this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'], 'SSL')); // Redirect to the Module Listing
}
}
/*Assign the language data for parsing it to view*/
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_content_top'] = $this->language->get('text_content_top');
$data['text_content_bottom'] = $this->language->get('text_content_bottom');
$data['text_column_left'] = $this->language->get('text_column_left');
$data['text_column_right'] = $this->language->get('text_column_right');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_paymentdescription'] = $this->language->get('text_paymentdescription');
$data['text_title'] = $this->language->get('text_title');
$data['text_testmode'] = $this->language->get('text_testmode');
$data['text_testgrouptoken'] = $this->language->get('text_testgrouptoken');
$data['text_prodgrouptoken'] = $this->language->get('text_prodgrouptoken');
$data['text_maxpayment'] = $this->language->get('text_maxpayment');
$data['text_creditpayment'] = $this->language->get('text_creditpayment');
$data['text_windowselecttype'] = $this->language->get('text_windowselecttype');
$data['text_optionredirect'] = $this->language->get('text_optionredirect');
$data['text_optionpopup'] = $this->language->get('text_optionpopup');
$data['text_optioniframe'] = $this->language->get('text_optioniframe');
$data['text_height'] = $this->language->get('text_height');
$data['text_width'] = $this->language->get('text_width');
$data['text_hideitemlist'] = $this->language->get('text_hideitemlist');
$data['text_createtoken'] = $this->language->get('text_createtoken');
$data['text_invoicelang'] = $this->language->get('text_invoicelang');
$data['text_english'] = $this->language->get('text_english');
$data['text_hebrew'] = $this->language->get('text_hebrew');
$data['text_billing'] = $this->language->get('text_billing');
$data['text_shipping'] = $this->language->get('text_shipping');
$data['text_billingshipping'] = $this->language->get('text_billingshipping');
$data['text_exemptvat'] = $this->language->get('text_exemptvat');
$data['text_chargevat'] = $this->language->get('text_chargevat');
$data['text_exempt'] = $this->language->get('text_exempt');
$data['text_billing'] = $this->language->get('text_billing');
$data['text_shipping'] = $this->language->get('text_shipping');
$data['text_billingshipping'] = $this->language->get('text_billingshipping');
$data['text_redirecturl'] = $this->language->get('text_redirecturl');
$data['text_sortorder'] = $this->language->get('text_sortorder');
$data['text_ipn'] = $this->language->get('text_ipn');
$data['text_yes'] = $this->language->get('text_yes');
$data['text_no'] = $this->language->get('text_no');
$data['entry_code'] = $this->language->get('entry_code');
$data['entry_layout'] = $this->language->get('entry_layout');
$data['entry_position'] = $this->language->get('entry_position');
$data['entry_status'] = $this->language->get('entry_status');
$data['entry_sort_order'] = $this->language->get('entry_sort_order');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
$data['button_add_module'] = $this->language->get('button_add_module');
$data['button_remove'] = $this->language->get('button_remove');
$data['entry_order_status'] = $this->language->get('entry_order_status');
$data['pending_order_status'] = $this->language->get('pending_order_status');
$data['processing_order_status'] = $this->language->get('processing_order_status');
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
// return warning if any*/
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['description'])) {
$data['description'] = $this->error['description'];
} else {
$data['description'] = '';
}
/* Making of Breadcrumbs to be displayed on site*/
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/payment/icredit', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
/* End Breadcrumb Block*/
$data['action'] = $this->url->link('extension/payment/icredit', 'token=' . $this->session->data['token'], 'SSL'); // URL to be directed when the save button is pressed
$data['cancel'] = $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'); // URL to be redirected when cancel button is pressed
/* This block checks, if the hello world text field is set it parses it to view otherwise get the default hello world text field from the database and parse it*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['PaymentMethodDescription'] = $this->request->post['PaymentMethodDescription'];
} else {
$data['PaymentMethodDescription'] = $this->config->get('PaymentMethodDescription');
}
if (isset($this->request->post['icredit_complete_order_status_id'])) {
$data['icredit_complete_order_status_id'] = $this->request->post['icredit_complete_order_status_id'];
} else {
$data['icredit_complete_order_status_id'] = $this->config->get('icredit_complete_order_status_id');
}
if (isset($this->request->post['icredit_pending_order_status_id'])) {
$data['icredit_pending_order_status_id'] = $this->request->post['icredit_pending_order_status_id'];
} else {
$data['icredit_pending_order_status_id'] = $this->config->get('icredit_pending_order_status_id');
}
if (isset($this->request->post['icredit_processing_order_status_id'])) {
$data['icredit_processing_order_status_id'] = $this->request->post['icredit_processing_order_status_id'];
} else {
$data['icredit_processing_order_status_id'] = $this->config->get('icredit_processing_order_status_id');
}
/* End Block*/
$data['modules'] = array();
/* This block parses the Module Settings such as Layout, Position,Status & Order Status to the view*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['modules'] = $this->request->post['PaymentMethodDescription'];
} elseif ($this->config->get('PaymentMethodDescription')) {
$data['modules'] = $this->config->get('PaymentMethodDescription');
}
/* End Block*/
$this->load->model('design/layout'); // Loading the Design Layout Models
$data['layouts'] = $this->model_design_layout->getLayouts(); // Getting all the Layouts available on system
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$getsettings = $this->model_extension_payment_icredit->addGeticreditsettings();
$data['editdata']=array();
if(isset($getsettings))
{
$data['editdata']['icredit_id'] = $getsettings['id_icredit'];
$data['editdata']['enabled'] = $getsettings['enabled'];
$data['editdata']['PaymentMethodDescription'] = $getsettings['PaymentMethodDescription'];
$data['editdata']['title'] = $getsettings['title'];
$data['editdata']['testmode'] = $getsettings['testmode'];
$data['editdata']['testtoken'] = $getsettings['testtoken'];
$data['editdata']['grouptoken'] = $getsettings['grouptoken'];
$data['editdata']['maxpayment'] = $getsettings['maxpayment'];
$data['editdata']['creditpayment'] = $getsettings['creditpayment'];
$data['editdata']['windowtype'] = $getsettings['windowtype'];
$data['editdata']['height'] = $getsettings['height'];
$data['editdata']['width'] = $getsettings['width'];
$data['editdata']['hideitemlist'] = $getsettings['hideitemlist'];
$data['editdata']['createtoken'] = $getsettings['createtoken'];
$data['editdata']['invoicelang'] = $getsettings['invoicelang'];
$data['editdata']['exemptvat'] = $getsettings['exemptvat'];
$data['editdata']['redirecturl'] = $getsettings['redirecturl'];
$data['editdata']['ipn'] = $getsettings['ipn'];
$data['editdata']['sortorder'] = $getsettings['sortorder'];
}
$data['editdata'] = $data['editdata'];
$this->response->setoutput($this->load->view('extension/payment/icredit.tpl', $data));
}
protected function validate() {
/* Block to check the user permission to manipulate the module*/
if (!$this->user->hasPermission('modify', 'extension/payment/icredit')) {
$this->error['warning'] = $this->language->get('error_permission');
}
/* End Block*/
/* Block to check if the helloworld_text_field is properly set to save into database, otherwise the error is returned*/
/*
if (!$this->request->post['PaymentMethodDescription']) {
$this->error['description'] = $this->language->get('error_description');
}
*/
/* End Block*/
/* if (!$this->request->post['redirecturl']) {
$this->error['redirecturl'] = $this->language->get('error_redirecturl');
}*/
return !$this->error;
}
/* End Validation Function*/
}
?>
Your controller file should look like this:
<?php
class ControllerExtensionPaymentIcredit extends Controller {
private $error = array();
public function install()
{
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "iCredit` (
`id_icredit` int(1) NOT NULL AUTO_INCREMENT,
`enabled` varchar(255),
`PaymentMethodDescription` varchar(500) CHARACTER SET utf8,
`title` varchar(255) CHARACTER SET utf8,
`testmode` varchar(1),
`testtoken` varchar(255),
`grouptoken` varchar(500),
`maxpayment` varchar(255),
`creditpayment` varchar(500),
`windowtype` varchar(255),
`height` int(10),
`width` int(10),
`hideitemlist` varchar(1),
`createtoken` varchar(1),
`invoicelang` varchar(500),
`exemptvat` varchar(255),
`redirecturl` varchar(500),
`ipn` varchar(500),
`sortorder` varchar(500),
`date_added` datetime,
PRIMARY KEY (`id_icredit`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; ");
}
public function uninstall()
{
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "iCredit");
}
public function index()
{ // Default function
$this->install();
$this->load->language('extension/payment/icredit'); // Loading the language file of helloworld
$this->document->setTitle($this->language->get('heading_title')); // Set the title of the page to the heading title in the Language file i.e., Hello World
$this->load->model('setting/setting');
$this->load->model('extension/payment/icredit'); // Load the Setting Model (All of the OpenCart Module & General Settings are saved using this Model )
//fwrite($file,$this->validate()." -- validate\r\n");
//fwrite($file,print_r($_POST,TRUE)." -- post\r\n");
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate())
{
if ($this->request->post['icredit_id'] == "")
{
$this->model_setting_setting->editSetting('payment_icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->addicreditsettings($this->request->post);
}
else
{
$this->model_setting_setting->editSetting('payment_icredit', $this->request->post);
$check = $this->model_extension_payment_icredit->editicreditsettings($this->request->post);
}
$this->session->data['success'] = $this->language->get('text_success'); // To display the success text on data save=
if($check == 1)
{
$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); // Redirect to the Module Listing
}
}
/*Assign the language data for parsing it to view*/
$data['heading_title'] = $this->language->get('heading_title');
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
// return warning if any*/
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['description'])) {
$data['description'] = $this->error['description'];
} else {
$data['description'] = '';
}
/* Making of Breadcrumbs to be displayed on site*/
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/payment/icredit', 'user_token=' . $this->session->data['user_token'], true)
);
$data['action'] = $this->url->link('extension/payment/icredit', 'user_token=' . $this->session->data['user_token'], true);
$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true);
/* This block checks, if the hello world text field is set it parses it to view otherwise get the default hello world text field from the database and parse it*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['PaymentMethodDescription'] = $this->request->post['PaymentMethodDescription'];
} else {
$data['PaymentMethodDescription'] = $this->config->get('PaymentMethodDescription');
}
if (isset($this->request->post['payment_icredit_complete_order_status_id'])) {
$data['payment_icredit_complete_order_status_id'] = $this->request->post['payment_icredit_complete_order_status_id'];
} else {
$data['payment_icredit_complete_order_status_id'] = $this->config->get('payment_icredit_complete_order_status_id');
}
if (isset($this->request->post['payment_icredit_pending_order_status_id'])) {
$data['payment_icredit_pending_order_status_id'] = $this->request->post['payment_icredit_pending_order_status_id'];
} else {
$data['payment_icredit_pending_order_status_id'] = $this->config->get('payment_icredit_pending_order_status_id');
}
if (isset($this->request->post['payment_icredit_processing_order_status_id'])) {
$data['payment_icredit_processing_order_status_id'] = $this->request->post['payment_icredit_processing_order_status_id'];
} else {
$data['payment_icredit_processing_order_status_id'] = $this->config->get('payment_icredit_processing_order_status_id');
}
/* End Block*/
$data['modules'] = array();
/* This block parses the Module Settings such as Layout, Position,Status & Order Status to the view*/
if (isset($this->request->post['PaymentMethodDescription'])) {
$data['modules'] = $this->request->post['PaymentMethodDescription'];
} elseif ($this->config->get('PaymentMethodDescription')) {
$data['modules'] = $this->config->get('PaymentMethodDescription');
}
/* End Block*/
$this->load->model('design/layout'); // Loading the Design Layout Models
$data['layouts'] = $this->model_design_layout->getLayouts(); // Getting all the Layouts available on system
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$getsettings = $this->model_extension_payment_icredit->addGeticreditsettings();
$data['editdata']=array();
if(isset($getsettings))
{
$data['editdata']['icredit_id'] = $getsettings['id_icredit'];
$data['editdata']['enabled'] = $getsettings['enabled'];
$data['editdata']['PaymentMethodDescription'] = $getsettings['PaymentMethodDescription'];
$data['editdata']['title'] = $getsettings['title'];
$data['editdata']['testmode'] = $getsettings['testmode'];
$data['editdata']['testtoken'] = $getsettings['testtoken'];
$data['editdata']['grouptoken'] = $getsettings['grouptoken'];
$data['editdata']['maxpayment'] = $getsettings['maxpayment'];
$data['editdata']['creditpayment'] = $getsettings['creditpayment'];
$data['editdata']['windowtype'] = $getsettings['windowtype'];
$data['editdata']['height'] = $getsettings['height'];
$data['editdata']['width'] = $getsettings['width'];
$data['editdata']['hideitemlist'] = $getsettings['hideitemlist'];
$data['editdata']['createtoken'] = $getsettings['createtoken'];
$data['editdata']['invoicelang'] = $getsettings['invoicelang'];
$data['editdata']['exemptvat'] = $getsettings['exemptvat'];
$data['editdata']['redirecturl'] = $getsettings['redirecturl'];
$data['editdata']['ipn'] = $getsettings['ipn'];
$data['editdata']['sortorder'] = $getsettings['sortorder'];
}
$data['editdata'] = $data['editdata'];
$this->response->setoutput($this->load->view('extension/payment/icredit.twig', $data));
}
protected function validate() {
/* Block to check the user permission to manipulate the module*/
if (!$this->user->hasPermission('modify', 'extension/payment/icredit')) {
$this->error['warning'] = $this->language->get('error_permission');
}
/* End Block*/
/* Block to check if the helloworld_text_field is properly set to save into database, otherwise the error is returned*/
/*
if (!$this->request->post['PaymentMethodDescription']) {
$this->error['description'] = $this->language->get('error_description');
}
*/
/* End Block*/
/* if (!$this->request->post['redirecturl']) {
$this->error['redirecturl'] = $this->language->get('error_redirecturl');
}*/
return !$this->error;
}
/* End Validation Function*/
}
I'm not sure it is will works because i do not see another files.
In your twig file you must find this strings:
icredit_complete_order_status_id
icredit_pending_order_status_id
icredit_processing_order_status_id
and replace with:
payment_icredit_complete_order_status_id
payment_icredit_pending_order_status_id
payment_icredit_processing_order_status_id
is there a way to make this if else condition:
$searchUserTypeName = UserType::findOrFail(1);
success = true;
$message = '';
$user = new User();
if ($searchUserTypeName->name == "Captain" || $searchUserTypeName->name == "Member") {
$fields = [
'teacher_id' => 'Teacher Id',
'team_id' => 'Team',
'mobile' => 'Mobile',
'launched_date' => 'Launched Date',
'endorsed_date' => 'Endorsed Date'
];
} else if ($searchUserTypeName->name == "Mentor" || $searchUserTypeName->name == "Mentee") {
$fields = [
'teacher_id' => 'Teacher Id',
'team_id' => 'Team',
'skype_id' => 'Skype Id',
'google_hangouts' => 'Google Hangouts',
'graduation_date' => 'Graduation Date',
'launched_date' => 'Launched Date',
'endorsed_date' => 'Endorsed Date'
];
}
foreach ($fields as $key => $field) {
if (!$request->has($key) || $request->{$key} == '') {
$success = false;
$message .= $field . ' is required.<br>';
} else {
$user->{$key} = $request->{$key};
}
}
if (!$success) {
$this->setStatus(400);
$this->setSuccess(false);
$this->setMessage($message);
return $this->sendResponse($fields);
}
$user->save();
to dynamic?
The value Captain, Member, Mentor and Mentee is from a mysql table
if Captain or Member
there is a specific field select that will save on the use tabel
same as for Mentor and Mentee
hope you can help
thanks
You can set method in your related model
User extends Model {
public function isName(...$names)
{
return in_array($this->name, $names);
}
}
if ($user->isName('Captain', 'Member')) {
//
}
Im having a very strange problem. When i add a product to my shopping cart on top header it shows the cart details/products. But when i click on the cart or checkout it says my cart is empty. So each time when i add the product and move to checkout or cart it automatically becomes empty.
I have tried the site on firefox, chrome and in different PCs but still the same problem. But the weird part is when i run firebug and move to the console to see the calls, the site works perfectly. But when i close firebug and refresh the page or move the cart becomes empty again.
Can someone tell me what might the problem be?
Im using Opencart 1.5.4
Checkout controller function
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->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) {
$this->redirect($this->url->link('checkout/cart'));
}
}
$this->language->load('checkout/checkout');
$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('text_cart'),
'href' => $this->url->link('checkout/cart'),
'separator' => $this->language->get('text_separator')
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('checkout/checkout', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_checkout_option'] = $this->language->get('text_checkout_option');
$this->data['text_checkout_account'] = $this->language->get('text_checkout_account');
$this->data['text_checkout_payment_address'] = $this->language->get('text_checkout_payment_address');
$this->data['text_checkout_shipping_address'] = $this->language->get('text_checkout_shipping_address');
$this->data['text_checkout_shipping_method'] = $this->language->get('text_checkout_shipping_method');
$this->data['text_checkout_payment_method'] = $this->language->get('text_checkout_payment_method');
$this->data['text_checkout_confirm'] = $this->language->get('text_checkout_confirm');
$this->data['text_modify'] = $this->language->get('text_modify');
$this->data['logged'] = $this->customer->isLogged();
$this->data['shipping_required'] = $this->cart->hasShipping();
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/checkout.tpl')) {
$this->template = $this->config->get('config_template') . '/template/checkout/checkout.tpl';
} else {
$this->template = 'default/template/checkout/checkout.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());
}
cart controller
public function index() {
$this->language->load('checkout/cart');
if (!isset($this->session->data['vouchers'])) {
$this->session->data['vouchers'] = array();
}
// Update
if (!empty($this->request->post['quantity'])) {
foreach ($this->request->post['quantity'] as $key => $value) {
$this->cart->update($key, $value);
}
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['reward']);
$this->redirect($this->url->link('checkout/cart'));
}
// Remove
if (isset($this->request->get['remove'])) {
$this->cart->remove($this->request->get['remove']);
unset($this->session->data['vouchers'][$this->request->get['remove']]);
$this->session->data['success'] = $this->language->get('text_remove');
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['reward']);
$this->redirect($this->url->link('checkout/cart'));
}
// Coupon
if (isset($this->request->post['coupon']) && $this->validateCoupon()) {
$this->session->data['coupon'] = $this->request->post['coupon'];
$this->session->data['success'] = $this->language->get('text_coupon');
$this->redirect($this->url->link('checkout/cart'));
}
// Voucher
if (isset($this->request->post['voucher']) && $this->validateVoucher()) {
$this->session->data['voucher'] = $this->request->post['voucher'];
$this->session->data['success'] = $this->language->get('text_voucher');
$this->redirect($this->url->link('checkout/cart'));
}
// Reward
if (isset($this->request->post['reward']) && $this->validateReward()) {
$this->session->data['reward'] = abs($this->request->post['reward']);
$this->session->data['success'] = $this->language->get('text_reward');
$this->redirect($this->url->link('checkout/cart'));
}
// Shipping
if (isset($this->request->post['shipping_method']) && $this->validateShipping()) {
$shipping = explode('.', $this->request->post['shipping_method']);
$this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
$this->session->data['success'] = $this->language->get('text_shipping');
$this->redirect($this->url->link('checkout/cart'));
}
$this->document->setTitle($this->language->get('heading_title'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'href' => $this->url->link('common/home'),
'text' => $this->language->get('text_home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'href' => $this->url->link('checkout/cart'),
'text' => $this->language->get('heading_title'),
'separator' => $this->language->get('text_separator')
);
if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) {
$points = $this->customer->getRewardPoints();
$points_total = 0;
foreach ($this->cart->getProducts() as $product) {
if ($product['points']) {
$points_total += $product['points'];
}
}
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_next'] = $this->language->get('text_next');
$this->data['text_next_choice'] = $this->language->get('text_next_choice');
$this->data['text_use_coupon'] = $this->language->get('text_use_coupon');
$this->data['text_use_voucher'] = $this->language->get('text_use_voucher');
$this->data['text_use_reward'] = sprintf($this->language->get('text_use_reward'), $points);
$this->data['text_shipping_estimate'] = $this->language->get('text_shipping_estimate');
$this->data['text_shipping_detail'] = $this->language->get('text_shipping_detail');
$this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
$this->data['text_select'] = $this->language->get('text_select');
$this->data['text_none'] = $this->language->get('text_none');
$this->data['column_image'] = $this->language->get('column_image');
$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['entry_coupon'] = $this->language->get('entry_coupon');
$this->data['entry_voucher'] = $this->language->get('entry_voucher');
$this->data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total);
$this->data['entry_country'] = $this->language->get('entry_country');
$this->data['entry_zone'] = $this->language->get('entry_zone');
$this->data['entry_postcode'] = $this->language->get('entry_postcode');
$this->data['button_update'] = $this->language->get('button_update');
$this->data['button_remove'] = $this->language->get('button_remove');
$this->data['button_coupon'] = $this->language->get('button_coupon');
$this->data['button_voucher'] = $this->language->get('button_voucher');
$this->data['button_reward'] = $this->language->get('button_reward');
$this->data['button_quote'] = $this->language->get('button_quote');
$this->data['button_shipping'] = $this->language->get('button_shipping');
$this->data['button_shopping'] = $this->language->get('button_shopping');
$this->data['button_checkout'] = $this->language->get('button_checkout');
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} elseif (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) {
$this->data['error_warning'] = $this->language->get('error_stock');
} else {
$this->data['error_warning'] = '';
}
if ($this->config->get('config_customer_price') && !$this->customer->isLogged()) {
$this->data['attention'] = sprintf($this->language->get('text_login'), $this->url->link('account/login'), $this->url->link('account/register'));
} else {
$this->data['attention'] = '';
}
if (isset($this->session->data['success'])) {
$this->data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$this->data['success'] = '';
}
$this->data['action'] = $this->url->link('checkout/cart');
if ($this->config->get('config_cart_weight')) {
$this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point'));
} else {
$this->data['weight'] = '';
}
$this->load->model('tool/image');
$this->data['products'] = array();
$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->data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']);
}
if ($product['image']) {
$image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
} else {
$image = '';
}
$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)
);
}
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']);
} else {
$total = false;
}
$this->data['products'][] = array(
'key' => $product['key'],
'thumb' => $image,
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'stock' => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')),
'reward' => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
'price' => $price,
'total' => $total,
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']),
'remove' => $this->url->link('checkout/cart', 'remove=' . $product['key'])
);
}
// Gift Voucher
$this->data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$this->data['vouchers'][] = array(
'key' => $key,
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount']),
'remove' => $this->url->link('checkout/cart', 'remove=' . $key)
);
}
}
if (isset($this->request->post['next'])) {
$this->data['next'] = $this->request->post['next'];
} else {
$this->data['next'] = '';
}
$this->data['coupon_status'] = $this->config->get('coupon_status');
if (isset($this->request->post['coupon'])) {
$this->data['coupon'] = $this->request->post['coupon'];
} elseif (isset($this->session->data['coupon'])) {
$this->data['coupon'] = $this->session->data['coupon'];
} else {
$this->data['coupon'] = '';
}
$this->data['voucher_status'] = $this->config->get('voucher_status');
if (isset($this->request->post['voucher'])) {
$this->data['voucher'] = $this->request->post['voucher'];
} elseif (isset($this->session->data['voucher'])) {
$this->data['voucher'] = $this->session->data['voucher'];
} else {
$this->data['voucher'] = '';
}
$this->data['reward_status'] = ($points && $points_total && $this->config->get('reward_status'));
if (isset($this->request->post['reward'])) {
$this->data['reward'] = $this->request->post['reward'];
} elseif (isset($this->session->data['reward'])) {
$this->data['reward'] = $this->session->data['reward'];
} else {
$this->data['reward'] = '';
}
$this->data['shipping_status'] = $this->config->get('shipping_status') && $this->config->get('shipping_estimator') && $this->cart->hasShipping();
if (isset($this->request->post['country_id'])) {
$this->data['country_id'] = $this->request->post['country_id'];
} elseif (isset($this->session->data['shipping_country_id'])) {
$this->data['country_id'] = $this->session->data['shipping_country_id'];
} else {
$this->data['country_id'] = $this->config->get('config_country_id');
}
$this->load->model('localisation/country');
$this->data['countries'] = $this->model_localisation_country->getCountries();
if (isset($this->request->post['zone_id'])) {
$this->data['zone_id'] = $this->request->post['zone_id'];
} elseif (isset($this->session->data['shipping_zone_id'])) {
$this->data['zone_id'] = $this->session->data['shipping_zone_id'];
} else {
$this->data['zone_id'] = '';
}
if (isset($this->request->post['postcode'])) {
$this->data['postcode'] = $this->request->post['postcode'];
} elseif (isset($this->session->data['shipping_postcode'])) {
$this->data['postcode'] = $this->session->data['shipping_postcode'];
} else {
$this->data['postcode'] = '';
}
if (isset($this->request->post['shipping_method'])) {
$this->data['shipping_method'] = $this->request->post['shipping_method'];
} elseif (isset($this->session->data['shipping_method'])) {
$this->data['shipping_method'] = $this->session->data['shipping_method']['code'];
} else {
$this->data['shipping_method'] = '';
}
// Totals
$this->load->model('setting/extension');
$total_data = array();
$total = 0;
$taxes = $this->cart->getTaxes();
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$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->data['totals'] = $total_data;
$this->data['continue'] = $this->url->link('common/home');
$this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/cart.tpl')) {
$this->template = $this->config->get('config_template') . '/template/checkout/cart.tpl';
} else {
$this->template = 'default/template/checkout/cart.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_bottom',
'common/content_top',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
} else {
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_error'] = $this->language->get('text_empty');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['continue'] = $this->url->link('common/home');
unset($this->session->data['success']);
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
} else {
$this->template = 'default/template/error/not_found.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());
}
}
session library
class Session {
public $data = array();
public function __construct() {
if (!session_id()) {
ini_set('session.use_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
session_set_cookie_params(0, '/');
session_start();
}
$this->data =& $_SESSION;
}
function getId() {
return session_id();
}
}
It's extremely hard to say, where's the root of the problem. If you have any 3rd party extensions (VQMods), they can change original OpenCart code. In this case you should look in cached files, not original ones. That's for the start.