Related
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
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
I am working on building a few interfaces with Remedy 9.1 web services. It is configured with Forms authentication to get to the WSDL. I would like to keep it in that configuration so that the more powerful web services remain protected.
I have parts of a solution, but I am not sure that they can work together, perhaps you know of a solution?
This works if I remove forms auth:
function New-ObjectFromProxy {
param($proxy, $proxyAttributeName, $typeName)
# Locate the assembly for $proxy
$attribute = $proxy | gm | where { $_.Name -eq $proxyAttributeName }
$str = "`$assembly = [" + $attribute.TypeName + "].assembly"
invoke-expression $str
# Instantiate an AuthenticationHeaderValue object.
$type = $assembly.getTypes() | where { $_.Name -eq $typeName }
return $assembly.CreateInstance($type)
}
$Now = get-date -Format G
$Q = "'System Broadcast End Date' >= """ + $Now + """"
$proxy = New-WebServiceProxy -Uri "https://mycompany-itsm.columncloud.com/arsys/WSDL/public/servername/CFG%3ABroadcast"
$authHeader = New-ObjectFromProxy -proxy $proxy -proxyAttributeName "AuthenticationInfoValue" -typeName "AuthenticationInfo"
$authHeader.userName = "username"
$authHeader.password = "password"
$proxy.AuthenticationInfoValue = $authHeader
$Response = $proxy.GetList($Q,"","")
$Response | format-Table Broadcast_Start_Date, Broadcast_Message
However, if I move the webservice back behind the forms auth, I can get to the WSDL if I do this:
#this is the url that you want will send thae request to
$url = "https://mycompany-itsm.columncloud.com/arsys/servlet/LoginServlet"
#here you can set your POST params
$parameters = "username=username&pwd=ppaasswwoorrdd&encpwd=1&ipoverride=0&initialState=-1&timezone=-28800000&goto=/arsys/WSDL/protected/servername/HPD_IncidentInterface_Create_WS"
#creating the xmlHtpp system object
$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.open('POST', $url, $false)
#Setting required header of the request
$http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
$http_request.setRequestHeader("Content-length", $parameters.length)
#Assigning the params to the request
$Resp = $http_request.send($parameters)
echo $http_request.responseText
I would like to find a solution to combine these solutions together to use forms auth to get to the WSDL and create a webServiceProxy object. Perhaps my google-fu is weak, but I have not found a formsauth solution for new-webserviceProxy.
Origin code from POSHCODE site. updated to add formsauth
Basically I had to use the way back machine to figure out how this was done before it was made super simple by new-WebServiceProxy. I fire up a web request to post with forms auth data and grab the cookie for the conversation. If my cookie expires, I go get a new one (might explain my waistline).
Huge props to Oisin Grehan for publishing his code 7 years ago.
Call it like this:
.\New-WebServiceProxy-FormsAuth.ps1 -Url "https://mycompany/WSDL/public/servername/CFG%3ABroadcast" -Namespace "mystuff" -Cookies $CookieJar -lurl "https://mycompany/servlet/LoginServlet" -postData "username=username&pwd=ppaasswwoorrdd&encpwd=1&ipoverride=0&initialState=-1&timezone=-28800000"
# New-WebServiceProxy-FormsAuth.ps1 (v3.0 Sep 23, 2009)
#
# Oisin Grehan <oising#gmail.com> (x0n)
# ghangas
#
# Usage:
# $proxy = .\New-WebServiceProxy.ps1 [-Url] http://site/service.asmx -lurl <http://site/loginpostpage> -postData <form data url encoded> [[-SoapProtocol] <Soap | Soap12>] [-Namespace <namespace>] [-Cookies <CookieContainer>]
#
# to see available webmethods:
# $proxy | gm
#
param($url = $(throw "need `$url"), [string]$protocol = "Soap", [string]$Namespace="", [System.Net.CookieContainer]$CookieJar, [string]$lurl, [string]$postData)
[void][system.Reflection.Assembly]::LoadWithPartialName("system.web.services")
trap {
"Error:`n`n $error";
break;
}
#$request = [System.Net.WebRequest]::Create($url);
$dcp = new-object system.web.services.discovery.discoveryclientprotocol
if ($CookieJar -ne $null) {
If ($CookieJar.ToString() = "System.Net.CookieContainer") {
$dcp.CookieContainer = $CookieJar
}
}
Write-Progress "Discovery" "Searching..."
$dcp.AllowAutoRedirect = $true
try {[void]$dcp.DiscoverAny($url)
}
catch {
$CookieJar = New-Object System.Net.CookieContainer
$buffer = [text.encoding]::ascii.getbytes($postData)
[net.httpWebRequest] $req = [net.webRequest]::create($lurl)
$req.method = "POST"
$req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
$req.Headers.Add("Accept-Language: en-US")
$req.Headers.Add("Accept-Encoding: gzip,deflate")
$req.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7")
$req.AllowAutoRedirect = $true
$req.UserAgent = "Mozilla/4.0"
$req.ContentType = "application/x-www-form-urlencoded"
$req.ContentLength = $buffer.length
$req.TimeOut = 50000
$req.KeepAlive = $true
$req.CookieContainer = $CookieJar
$reqst = $req.getRequestStream()
$reqst.write($buffer, 0, $buffer.length)
$reqst.flush()
$reqst.close()
[net.httpWebResponse] $res = $req.getResponse()
$dcp.CookieContainer = $CookieJar
[void]$dcp.DiscoverAny($url)
}
$dcp.ResolveAll()
# get service name
foreach ($entry in $dcp.Documents.GetEnumerator()) { # needed for Dictionary
if ($entry.Value -is [System.Web.Services.Description.ServiceDescription]) {
$script:serviceName = $entry.Value.Services[0].Name
Write-Verbose "Service: $serviceName"
}
}
Write-Progress "WS-I Basic Profile 1.1" "Validating..."
$ns = new-Object System.CodeDom.CodeNamespace $Namespace
$wref = new-object System.Web.Services.Description.WebReference $dcp.Documents, $ns
$wrefs = new-object system.web.services.description.webreferencecollection
[void]$wrefs.Add($wref)
$ccUnit = new-object System.CodeDom.CodeCompileUnit
[void]$ccUnit.Namespaces.Add($ns)
$violations = new-object system.web.Services.Description.BasicProfileViolationCollection
$wsi11 = [system.web.services.WsiProfiles]::BasicProfile1_1
if ([system.web.Services.Description.WebServicesInteroperability]::CheckConformance($wsi11, $wref, $violations)) {
Write-Progress "Proxy Generation" "Compiling..."
$webRefOpts = new-object System.Web.Services.Description.WebReferenceOptions
$webRefOpts.CodeGenerationOptions = "GenerateNewAsync","GenerateProperties" #,"GenerateOldAsync"
#StringCollection strings = ServiceDescriptionImporter.GenerateWebReferences(
# webReferences, codeProvider, codeCompileUnit, parameters.GetWebReferenceOptions());
$csprovider = new-object Microsoft.CSharp.CSharpCodeProvider
$warnings = [System.Web.Services.Description.ServiceDescriptionImporter]::GenerateWebReferences(
$wrefs, $csprovider, $ccunit, $webRefOpts)
if ($warnings.Count -eq 0) {
$param = new-object system.CodeDom.Compiler.CompilerParameters
[void]$param.ReferencedAssemblies.Add("System.Xml.dll")
[void]$param.ReferencedAssemblies.Add("System.Web.Services.dll")
$param.GenerateInMemory = $true;
#$param.TempFiles = (new-object System.CodeDom.Compiler.TempFileCollection "c:\temp", $true)
$param.GenerateExecutable = $false;
#$param.OutputAssembly = "$($ns.Name)_$($sdname).dll"
$param.TreatWarningsAsErrors = $false;
$param.WarningLevel = 4;
# do it
$compileResults = $csprovider.CompileAssemblyFromDom($param, $ccUnit);
if ($compileResults.Errors.Count -gt 0) {
Write-Progress "Proxy Generation" "Failed."
foreach ($output in $compileResults.Output) { write-host $output }
foreach ($err in $compileResults.Errors) { write-warning $err }
} else {
$assembly = $compileResults.CompiledAssembly
if ($assembly) {
if ($namespace) {
$serviceType = $assembly.GetType($namespace + "." + $serviceName)
} else {
$serviceType = $assembly.GetType($serviceName)
}
$assembly.GetTypes() | % { Write-Verbose $_.FullName }
} else {
Write-Warning "Failed: `$assembly is null"
return
}
# return proxy instance
$proxy = new-object $serviceType.FullName
$proxy # dump instance to pipeline
}
} else {
Write-Progress "Proxy Generation" "Failed."
Write-Warning $warnings
}
#Write-Progress -Completed
}
i hope someone can help with this. At one point i thought i had this working but cannot figure out why it is not.
The script below does everything but include the Zend_Json::encode. It saves the user in the database it emails the person a link, however the link does not have the encryption included with it.
thanks for your help!
public function contribjoinAction()
{
$request = $this->getRequest();
$conn = XXX_Db_Connection::factory()->getMasterConnection();
$userDao = XXX_Model_Dao_Factory::getInstance()->setModule('core')->getUserDao();
$userDao->setDbConnection($conn);
if ($request->isPost()) {
$fullname = $request->getPost('full_name');
$username = $request->getPost('username');
$password = $request->getPost('password');
$password2 = $request->getPost('confirmPassword');
$email = $request->getPost('email');
$islegal = $request->getPost('islegal');
$user = new Core_Models_User(array(
'user_name' => $username,
'password' => $password,
'full_name' => $fullname,
'email' => $email,
'is_active' => 0,
'created_date' => date('Y-m-d H:i:s'),
'logged_in_date' => null,
'is_online' => 0,
'role_id' => 2,
'islegal' => $islegal,
));
$id = $userDao->add($user);
$templateDao = XXX_Model_Dao_Factory::getInstance()->setModule('mail')->getTemplateDao();
$templateDao->setDbConnection($conn);
$template = $templateDao->getByName(Mail_Models_Template::TEMPLATE_ACTIVATE_CONTRIBUTOR);
if ($template == null) {
$message = sprintf($this->view->translator('auth_mail_template_not_found'), Mail_Models_Template::TEMPLATE_ACTIVATE_CONTRIBUTOR);
throw new Exception($message);
}
$search = array(Mail_Models_Mail::MAIL_VARIABLE_EMAIL, Mail_Models_Mail::MAIL_VARIABLE_USERNAME);
$replace = array($user->email, $user->user_name);
$subject = str_replace($search, $replace, $template->subject);
$content = str_replace($search, $replace, $template->body);
/**
* Replace the reset password link
* #TODO: Add security key?
*/
$encodedLink = array(
'email' => $email,
'user_name' => $username,
);
$encodedLink = base64_encode(urlencode(Zend_Json::encode($encodedLink)));
$link = $this->view->serverUrl() . $this->view->url(array('encoded_link' => $encodedLink), 'core_user_emailactivate');
$content = str_replace('%activate_link%', $link, $content);
/**
* Get mail transport instance
*/
$transport = Mail_Services_Mailer::getMailTransport();
$mail = new Zend_Mail();
$mail->setFrom($template->from_mail, $template->from_name)
->addTo($user->email, $user->user_name)
->setSubject($subject)
->setBodyHtml($content)
->send($transport);
if ($id > 0) {
$this->_helper->getHelper('FlashMessenger')
->addMessage($this->view->translator('user_join_success'));
$this->_redirect($this->view->serverUrl() . $this->view->url(array(), 'core_user_contribjoin'));
}
}
}
I have found the error. I somehow did not put the variable encoded_link into the .ini file for that module under routes.
I am getting this type of error:
=> i am getting error in the integration of the netsuite.
In sales order add the items in the netsuite so there are some error is define in above section my code is below please see the code add how to solve this problem.
[code] => USER_ERROR
[message] => You must enter at least one line item for this transaction.
[type] => ERRORi am gatting this type of error please help me
[code] => USER_ERROR
[message] => You must enter at least one line item for this transaction.
[type] => ERROR
my code is
include('NetSuiteService.php');
$service = new NetSuiteService();
if($order_items->netsuitid > 0){
$internal_Id = $order_items->netsuitid;
$emailCustomer = $order_items->user_email;
}
else{
$customer_Info = $order->get_customer_info($order->user_id);
$customer_information = array();
foreach($customer_Info as $customer_key => $customer_value){
if($customer_value->meta_key == 'first_name'){
$customer_information['first_name'] = $customer_value->meta_value;
}
if($customer_value->meta_key == 'last_name'){
$customer_information['last_name'] = $customer_value->meta_value;
}
}
$customer_information['email'] = $customer_Info->user_email;
//Add customer into net suit integration
$service = new NetSuiteService();
$customer = new Customer();
$customer->lastName = $customer_information['last_name'];
$customer->firstName = $customer_information['first_name'];
$customer->companyName = 'Company Name';
$customer->phone = '2222222222';
$customer->email = $customer_information['email'];
$emailCustomer = $customer_information['email'];
$request = new AddRequest();
$request->record = $customer;
$addResponse = $service->add($request);
if (!$addResponse->writeResponse->status->isSuccess) {
echo "You are already Registered with Netsuit.";
}
else {
$internal_Id = $addResponse->writeResponse->baseRef->internalId;
$order->insert_Customer($internal_Id,$order->user_id);
}
//End customer into net suit integration
}
//Add Product Information
/*$items = array();
foreach ( $order_items as $item_id => $item ) {
$itemRef = new nsRecordRef(array('internalId'=>$internal_Id));
$qty = $item['qty'];
if($item['type'] == 'line_item'){
$salesOrderItemFieldArray = array(
"item" => $itemRef,
"quantity" => $qty
);
}
if($item['type'] == 'fee'){
$salesOrderItemFieldArray = array(
"item" => $itemRef,
"quantity" => $qty
);
}
$SalesOrderItem->setFields($salesOrderItemFieldArray);
$items[] = $SalesOrderItem;
}
$salesOrderItemList = new nsComplexObject("SalesOrderItemList");
$salesOrderItemList->setFields(array(
"item" => $items
));
$salesOrderFields = array(
"orderStatus" => $order->status,
"entity" => '',
"getAuth" => true,
"shippingCost" => $order->order_shipping,
"shipMethod" => $order->payment_method,
"toBeEmailed" => true,
"email" => $emailCustomer,
"itemList" => $salesOrderItemList
);*/
$so = new SalesOrder();
//created Date
//$so->createdDate = $order->order_date;
//entity
$so->entity = new RecordRef();
$so->entity->internalId = $internal_Id;
$so->entity->name = $order->order_custom_fields['_billing_company'][0];
//Transaction Id
//$so->tranId = $order->order_custom_fields['Transaction ID'][0];
//Transaction Paid Date
//$so->tranDate = $order->order_custom_fields['_paid_date'][0];
//Source
$so->source = 'littlecrate';
//Created From
$so->createdFrom = 'littlecrate.com';
//Currency Name
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->currency = $order->order_custom_fields['_order_currency'];
$so->currencyName = $geoplugin->countryName;
$so->currency = $order->order_custom_fields['_order_currency'][0];
//Discount
$so->discountRate = $order->order_custom_fields['_order_discount'][0];
//Tax
$so->taxRate = $order->order_custom_fields['_order_tax'][0];
//email
$so->email = $order->billing_email;
//Status
//$so->orderStatus = $order->status;
//Billing Address
$so->billAddressList = array(
'billFirstname' => $order->order_custom_fields['_billing_first_name'][0],
'lastname' => $order->order_custom_fields['_billing_last_name'][0],
'billAddressee' => $order->order_custom_fields['_billing_address_1'][0],
'billAddr1' => $order->order_custom_fields['_billing_address_2'][0],
'billCountry' => $order->order_custom_fields['_billing_country'][0],
'billState' => $order->order_custom_fields['_billing_state'][0],
'billZip' => $order->order_custom_fields['_billing_postcode'][0],
'billPhone' => $order->order_custom_fields['_billing_phone'][0],
'billEmail' => $order->order_custom_fields['_billing_email'][0]);
//Shipping Address
$so->shipAddressList = array(
'shipFirstname' => $order->order_custom_fields['_shipping_first_name'][0],
'shipLastname' => $order->order_custom_fields['_shipping_last_name'][0],
'shipAddressee' => $order->order_custom_fields['_shipping_address_1'][0],
'shipAddr1' => $order->order_custom_fields['_shipping_address_2'][0],
'shipCity' => $order->order_custom_fields['_shipping_city'][0],
'shipState' => $order->order_custom_fields['_shipping_state'][0],
'shipZip' => $order->order_custom_fields['_shipping_postcode'][0],
'shiplPhone' => $order->order_custom_fields['_billing_phone'][0],
'shipEmail' => $order->order_custom_fields['_billing_email'][0]);
//Ship Date
//$so->shipDate = $order->order_custom_fields['Transaction ID'][0];
//Shipping Method
$so->shipMethod = $order->shipping_method;
//Shipping Charges
$so->shippingCost = $order->order_shipping;
//Shipping Tax Rate
$so->shippingTax1Rate = $order->order_shipping_tax;
//Payment Method
$so->paymentMethod = $order->payment_method;
//Sub Total
//$so->subTotal = $order->order_total;
//Discount Total(Cart Total)
//$so->discountTotal = $order->cart_discount;
//Tax Total
//$so->taxTotal = $order->order_tax;
//Total
//$so->total = $order->order_total;
//Product Listing
$arrItemsList = array();
$i = 0;
foreach($order_items_product as $keyProduct =>$valueProduct){
if($valueProduct['type'] == 'line_item'){
//$arrItemsList[$i]['item']['internalId'] = $valueProduct['product_id'];
//$arrItemsList[$i]['item']['externalId'] = $keyProduct;
$arrItemsList[$i]['item']['name'] = $valueProduct['name'];
$arrItemsList[$i]['item']['quantity'] = $valueProduct['qty'];
$arrItemsList[$i]['item']['description'] = $valueProduct['type'];
$arrItemsList[$i]['item']['amount'] = $valueProduct['line_total'];
}
if($valueProduct['type'] == 'fee'){
//$arrItemsList[$i]['item']['internalId'] = $valueProduct['product_id'];
//$arrItemsList[$i]['item']['externalId'] = $keyProduct;
$arrItemsList[$i]['item']['name'] = $valueProduct['name'];
$arrItemsList[$i]['item']['quantity'] = $valueProduct['qty'];
$arrItemsList[$i]['item']['description'] = $valueProduct['type'];
$arrItemsList[$i]['item']['amount'] = $valueProduct['line_total'];
}
$i++;
}
//print_r($arrItemsList);
$so->itemList->item = $arrItemsList;
/*$so->itemList = new SalesOrderItemList();
$soi = new SalesOrderItem();
$soi->item = new RecordRef();
$soi->item->internalId = 15;
$soi->quantity = 3;
$soi->price = new RecordRef();
$soi->price->internalId = $id;
$soi->amount = 55.3;
$so->itemList->item = array($soi);*/
$request = new AddRequest();
$request->record = $so;
//print_r($request);
$addResponse = $service->add($request);
print_r($addResponse);
exit;
if (!$addResponse->writeResponse->status->isSuccess) {
echo "ADD ERROR";
} else {
echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}
+
I Complited Using The Help Of Saqib,
http://stackoverflow.com/users/810555/saqib
He is The Great Developer And Regarding Netsuite Information Please Contact To Saqib Thanks Man U Just Do It.
<?php
$order_date = date('Y-m-d H:i:s');
// create array of fields
$itemArr = array();
$i = 0;
foreach($order_items_product as $keyProduct =>$valueProduct){
//if you not have internal id of item in netsuuite then please add the item in the netsuite and try.
$netsuiteItemId = 'Your Item Internal id Which is in the Netsuite Item';
$itemArr[$i]['item']['internalId'] = $netsuiteItemId;
$itemArr[$i]['quantity'] = $valueProduct['qty'];
$i++;
}
if (!define('LF', "\n")) {
define('LF', "\n");
}
/* for use in formatting custom addresses since NetSuite converts to <br> */
//Billing Address Information
/* this example has the customer address info in a db record, just pulled into $row */
$billAddress = stripslashes($order->order_custom_fields['_billing_first_name'][0]) . ' ' . $order->order_custom_fields['_billing_last_name'][0] . LF;
$billAddress .= stripslashes($order->order_custom_fields['_billing_address_1'][0]).LF;
$billAddress .= stripslashes($order->order_custom_fields['_billing_address_2'][0]).LF;
$billAddress .= stripslashes($order->order_custom_fields['_billing_country'][0]).LF;
$billAddress .= stripslashes($order->order_custom_fields['_billing_state'][0]) . ' - ' . $order->order_custom_fields['_billing_postcode'][0] . ', ' . LF;
$billAddress .= $order->order_custom_fields['_billing_phone'][0] . ', ' . $order->order_custom_fields['_billing_email'][0];
//Shipping Address Information
$shipAddress = stripslashes($order->order_custom_fields['_shipping_first_name'][0]) . ' ' . $order->order_custom_fields['_shipping_last_name'][0] . LF;
$shipAddress .= stripslashes($order->order_custom_fields['_shipping_address_1'][0]).LF;
$shipAddress .= stripslashes($order->order_custom_fields['_shipping_address_2'][0]).LF;
$shipAddress .= stripslashes($order->order_custom_fields['_shipping_city'][0]).LF;
$shipAddress .= stripslashes($order->order_custom_fields['_shipping_state'][0]) . ', ' . $order->order_custom_fields['_shipping_postcode'][0] . ', ' . LF;
$shipAddress .= $order->order_custom_fields['_billing_phone'][0] .', '. $order->order_custom_fields['_billing_email'][0];
$purchaseOrderFields = array (
'entity' => array ('internalId' => $internal_Id, 'type' => 'customer'),
'shippingCost' => $order->order_shipping,
'shipMethod' => $order->payment_method,
'toBeEmailed' => true,
//'tranId' => $order->order_custom_fields['Transaction ID'][0],
//'tranDate' => date('Y-m-d H:i:s'),
'source' => 'littlecrate',
'createdFrom' => 'littlecrate.com',
'discountRate' => $order->order_custom_fields['_order_discount'][0],
'taxRate' => $order->order_custom_fields['_order_tax'][0],
'email' => $order->billing_email,
//'shipDate' => date('Y-m-d H:i:s'),
'shipMethod' => $order->shipping_method,
'shippingCost' => $order->order_shipping,
'shippingTax1Rate' => $order->order_shipping_tax,
'paymentMethod' => $order->payment_method,
//'taxTotal' => $order->order_tax,
//'total' => $order->order_total,
'billAddress' => $billAddress,
'shipAddress' => $shipAddress,
'itemList' => array (
'item' => $itemArr
)
);
$salesOrder = new nsComplexObject('SalesOrder');
$salesOrder ->setFields($purchaseOrderFields);
$addResponse = $myNSclient->add($salesOrder );
if (!$addResponse->isSuccess) {
echo "Order Information is Not Inserted Into The Netsuite. Please Contact to Administration.";
exit;
}
?>
You item List object doesn't seem in correct format. Your code should look like this
$itemArr = array();
foreach($order_items_product as $keyProduct =>$valueProduct){
$item = new SalesOrderItem();
$item->item = $valueProduct['product_id'];
$item->quantity = $valueProduct['qty'];
$itemArr[] = $item;
}
$itemList = new SalesOrderItemList();
$itemList->item = $itemArr;
$so->itemList->item = $itemList;