Checkout page is not working - magento-1.8

i am using lotusbreath one step checkout. its work fine on localhost but its not working after uploading on server.
On server place order button is not redirected to order successfully page.
Both place(sever and localhost) has same file, so i doesn't understand what to do.
Can anybody help me what to do?
This is the link of checkout page on server: this
here is the validation of placed order button
public function saveOrderAction()
{
if (!$this->_validateFormKey()) {
$this->_redirect('*/*');
return;
}
if ($this->_expireAjax()) {
return;
}
$result = array();
try {
$requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds();
if ($requiredAgreements) {
$postedAgreements = array_keys($this->getRequest()->getPost('agreement', array()));
$diff = array_diff($requiredAgreements, $postedAgreements);
if ($diff) {
$result['success'] = false;
$result['error'] = true;
$result['error_messages'] = $this->__('Please agree to all the terms and conditions before placing the order.');
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
return;
}
}
$data = $this->getRequest()->getPost('payment', array());
if ($data) {
$data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT
| Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY
| Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY
| Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX
| Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;
$this->getOnepage()->getQuote()->getPayment()->importData($data);
}
$this->getOnepage()->saveOrder();
$redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();
$result['success'] = true;
$result['error'] = false;
} catch (Mage_Payment_Model_Info_Exception $e) {
$message = $e->getMessage();
if (!empty($message)) {
$result['error_messages'] = $message;
}
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
} catch (Mage_Core_Exception $e) {
Mage::logException($e);
Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
$result['success'] = false;
$result['error'] = true;
$result['error_messages'] = $e->getMessage();
$gotoSection = $this->getOnepage()->getCheckout()->getGotoSection();
if ($gotoSection) {
$result['goto_section'] = $gotoSection;
$this->getOnepage()->getCheckout()->setGotoSection(null);
}
$updateSection = $this->getOnepage()->getCheckout()->getUpdateSection();
if ($updateSection) {
if (isset($this->_sectionUpdateFunctions[$updateSection])) {
$updateSectionFunction = $this->_sectionUpdateFunctions[$updateSection];
$result['update_section'] = array(
'name' => $updateSection,
'html' => $this->$updateSectionFunction()
);
}
$this->getOnepage()->getCheckout()->setUpdateSection(null);
}
} catch (Exception $e) {
Mage::logException($e);
Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
$result['success'] = false;
$result['error'] = true;
$result['error_messages'] = $this->__('There was an error processing your order. Please contact us or try again later.');
}
$this->getOnepage()->getQuote()->save();

Related

Why latest updated sha is coming when using github api in switch case

I am doing file update operations using GitHub API. For example, let's say I am having a file called App.js and i am updating first line. While updating I will pass the sha.
When i am trying to update another line in the same file, the new updated sha is not coming, the older sha is coming. I am not doing all these steps manually, I have written code for all these operations. Let me paste the code for understanding,
var cosmos = [
{
"_id":"63773144c3160f782c087e35",
"nfrid":"637328ebf5c4b2558b064809",
"nfrname":"azuread",
"fileName":"index.js",
"isImport":true,
"isConst":false,
"isComponent":false,
"isNewFile":false,
"isPackage":false,
"landmark":null,
"isAfter":null,
"fileContent":"import { MsalProvider } from '#azure/msal-react';import { msalConfig } from './authConfig';import {PublicClientApplication } from '#azure/msal-browser';",
"filePath":"src/index.js",
"isIndexHtml":false,
"projecttypeid":"6372366d1b568e00d8af2e44",
"projecttypetitle":"PWA React",
"isReplace":false
},
{
"_id":"637731a2c3160f782c087e37",
"nfrid":"637328ebf5c4b2558b064809",
"nfrname":"azuread",
"fileName":"index.js",
"isImport":false,
"isConst":false,
"isComponent":true,
"isNewFile":false,
"isPackage":false,
"landmark":"<App />",
"isAfter":null,
"fileContent":"<MsalProvider instance={msalInstance}><App /></MsalProvider>",
"filePath":"src/index.js",
"isIndexHtml":false,
"projecttypeid":"6372366d1b568e00d8af2e44",
"projecttypetitle":"PWA React",
"isReplace":true,
}
];
for (let i = 0; i < cosmos.length; i++) {
switch (true) {
case cosmos[i].isImport:
const statusImport = common.updateImport(cosmos[i]);
console.log(statusImport);
break;
case cosmos[i].isConst:
const statusConst = common.updateConst(cosmos[i]);
console.log(statusConst);
break;
case cosmos[i].isPackage:
const statusPackage = common.updatePackage(cosmos[i]);
console.log(statusPackage);
break;
case cosmos[i].isIndexHtml:
const statusIndexHtml = common.updateIndexHTML(cosmos[i]);
console.log(statusIndexHtml);
break;
case cosmos[i].isNewFile:
const statusNewFile = common.addNewFile(cosmos[i]);
console.log(statusNewFile);
break;
case cosmos[i].isComponent:
const statusComponent = common.updateComponent(cosmos[i]);
console.log(statusComponent);
break;
default:
console.log("Nothing to add/update");
break;
}
}
I will be updating both these things in index.js file only. But the first thing is getting updated properly, when the second thing comes, it shows error like "src/index.js does not match with sha-id". I checked , that sha id is not the updated one, it changes after first update happens and i am getting that error . i will also paste my code logic which i wrote for updating files.
async function updateImport(cosmos) {
let temp = cosmos.filePath;
let newSha = "";
let newContent = "";
let decodedContent = "";
const octokit = new Octokit({
auth: "ghp_auth-token"
});
try {
return await new Promise(async (resolve, reject) => {
const response = await octokit.request(
`GET /repos/JaspreetAhden24/TestingGitHubIO/contents/${temp}`
);
newSha = response.data.sha;
decodedContent = atob(response.data.content);
if (cosmos.isImport === true) {
newContent = cosmos.fileContent + decodedContent;
}
let encodedContent = Buffer.from(newContent).toString("base64");
const update = await octokit.request(
`PUT /repos/JaspreetAhden24/TestingGitHubIO/contents/${temp}`,
{
message: "Updating import statements",
content: encodedContent,
sha: newSha
}
);
console.log(update.status);
resolve("success");
});
} catch (error) {
console.log(error);
}
}
async function updateComponent(cosmos) {
let temp = cosmos.filePath;
let newSha = "";
let newContent = "";
let decodedContent = "";
const octokit = new Octokit({
auth: "ghp_auth token"
});
try {
return await new Promise(async (resolve, reject) => {
const response = await octokit.request(
`GET /repos/JaspreetAhden24/TestingGitHubIO/contents/${temp}`
);
newSha = response.data.sha;
decodedContent = atob(response.data.content);
if (cosmos.isComponent === true) {
if (cosmos.isAfter === false) {
newContent = decodedContent.replace(
cosmos.landmark,
cosmos.fileContent + cosmos.landmark
);
} else if(cosmos.isAfter === true) {
newContent = decodedContent.replace(
cosmos.landmark,
cosmos.landmark + cosmos.fileContent
);
}
else if (cosmos.isReplace === true) {
newContent = decodedContent.replace(
cosmos.landmark,
cosmos.fileContent
);
}
}
// var formattedContent = prettier.format(newContent,{ semi: false, parser: "mdx" });
let encodedMDContent = Buffer.from(newContent).toString("base64");
const update = await octokit.request(
`PUT /repos/JaspreetAhden24/TestingGitHubIO/contents/${temp}`,
{
message: "Updating components",
content: encodedMDContent,
sha: newSha
}
);
console.log(update.status);
resolve("success");
});
} catch (error) {
console.log(error);
}
}
i need to know why the latest updated sha id is not coming when the second update is happening.
I need to know if the problem is with switch case or the new updated sha will not come in the second update function.

How to maintain a valid order book in kraken exchange with node,js

How's it going?
I got the example order book code in python (https://support.kraken.com/hc/en-us/articles/360027677512-Example-order-book-code-Python-) and translate it to javascript to run in node. But the book is wrong, it doesn't remove all old prices level. I'm sending my code below. I'd like help to solve this issue.
const websocket = require('ws');
const ws = new websocket('wss://ws.kraken.com');
const api_book = {'bid':[], 'ask':[]};
const api_depth = 10;
const api_output_book = () => {
bid = api_book['bid'].sort((x, y) => parseFloat(y[0])-parseFloat(x[0]));
ask = api_book['ask'].sort((x, y) => parseFloat(x[0])-parseFloat(y[0]));
console.log ('Bid\t\t\t\t\tAsk');
for (let x=0;x<api_depth;x++) {
console.log(`${bid[x][0]} (${bid[x][1]})\t\t\t${ask[x][0]} (${ask[x][1]})`);
}
}
const api_update_book = (side, data) => {
data.forEach((e) => {
let index = api_book[side].findIndex(o => o[0] == e[0]);
if (parseFloat(e[1]) > 0){
if(index < 0){
api_book[side].push([e[0],e[1]]);
} else {
api_book[side][index] = [e[0],e[1]];
}
} else {
api_book[side].splice(index,1);
}
});
if(side=='bid'){
api_book['bid'].sort((x, y) => parseFloat(y[0])-parseFloat(x[0]));
} else if(side=='ask'){
api_book['ask'].sort((x, y) => parseFloat(x[0])-parseFloat(y[0]));
}
}
ws.on('open', open = () => {
ws.send('{"event":"subscribe", "subscription":{"name":"book", "depth":'+api_depth+'}, "pair":["XBT/USD"]}');
console.log('Kraken websocket connected!');
});
ws.on('message', incoming = (data) => {
try {
data = JSON.parse(data.toString('utf8'));
if (data[1]) {
if (data[1]['as']) {
api_update_book('ask', data[1]['as'])
api_update_book('bid', data[1]['bs'])
} else if (data[1]['a'] || data[1]['b']) {
if (data[1]['a']) {
api_update_book('ask', data[1]['a']);
}
if (data[1]['b']) {
api_update_book('bid', data[1]['b']);
}
}
api_output_book();
}
} catch (error) {
console.log(error);
}
});
So I have also been playing around with Kraken's order book and came up with this solution using Angular. I also added a few console logs into the mix so that you can take it and run it in the browser. Hope this helps!
// variables
private ws = new WebSocket('wss://ws.kraken.com')
public asks = [];
public bids = [];
// Web Socket open connection
this.ws.onopen = () => {
this.ws.send(JSON.stringify(this.message));
console.log('Trade WS with Kraken connected')
}
// Fires when new data is received from web socket
this.ws.onmessage = (event) => {
var data = JSON.parse(event.data);
if (!data.event) {
if (data[1]['as']) {
this.asks = data[1]['as'];
this.bids = data[1]['bs'];
console.log('Initialised Book');
console.log(this.asks, this.bids);
} else if (data[1]['a'] || data[1]['b']) {
if (data[1]['a']) {
this.update_book(this.asks, 'ask', data[1]['a']);
}
if (data[1]['b']) {
this.update_book(this.bids, 'bid', data[1]['b']);
}
}
}
}
// Updating Orderbook
update_book (arr, side, data) {
if (data.length > 1) { // If 2 sets of data are received then the first will be deleted and the second will be added
let index = arr.findIndex(o => o[0] == data[0][0]); // Get position of first data
arr.splice(index, 1); // Delete data
arr.push([ data[1][0], data[1][1] ]); // Insert new data
console.log('Delete and Insert');
} else {
let index = arr.findIndex(o => o[0] == data[0][0]);
console.error(index);
if (index > -1) { // If the index matches a price in the list then it is an update message
arr[index] = [data[0][0], data[0][1]]; // Update matching position in the book
console.log('Updated ' + index);
} else { // If the index is -1 then it is a new price that came in
arr.push([data[0][0], data[0][1]]); // Insert new price
this.sort_book(arr, side); // Sort the book with the new price
arr.splice(10, 1); // Delete the 11th entry
console.log('Insert Only');
}
}
this.sort_book(arr, side); // Sort the order book
}
// Sort Orderbook
sort_book (arr, side) {
if (side == 'bid') {
arr.sort((x, y) => parseFloat(y[0]) - parseFloat(x[0]));
} else if (side == 'ask') {
arr.sort((x, y) => parseFloat(x[0]) - parseFloat(y[0]));
}
}
I would also recommend just having a look at this resource:
How to maintain a valid orderbook

Gantt - Modifying the Mouse-over information on a project

Good Morning;
I am looking to modify a Gantt Chart so that the Title found on the left and currently showing on the project are the same but when you hove the mouse over it, it will show a different set of information. Would also like to know the best way to separate the weeks with a noticeable break line that runs the entire gantt chart. Here is the code:
Page:
#using Kendo.Mvc.UI
<p></p>
<h2>#ViewBag.Title</h2>
#(Html.Kendo().Gantt<cpr_web.Models.TaskViewModel, cpr_web.Models.DependencyViewModel>()
.Name("Gantt")
.Views(views =>
{
views.WeekView(w => w.DayHeaderTemplate("#=kendo.toString(start, 'dd' )#").SlotSize(40));
views.MonthView(m => m.WeekHeaderTemplate("#=kendo.toString(start,'d', end,'d')#").SlotSize(150));
//views.YearView();
})
.Columns(columns =>
{
columns.Bound("title").Editable(false).Sortable(true).Width(100);
//columns.Bound("start").Format("{0:MM-dd}").Sortable(true).Width(10);
columns.Bound("State").Editable(false).Sortable(true).Width(30);
columns.Bound("City").Editable(false).Sortable(true).Width(40);
//columns.Bound("PercentComplete").Sortable(true).Width(10).Title("Complete");
})
.Events(e => {
e.Edit("editingGantt");
e.DataBound("databoundGantt");
e.Remove("unsupported");
e.Change("unsupported");
e.Move("unsupported");
e.MoveEnd("unsupported");
e.MoveStart("unsupported");
e.Resize("unsupported");
e.ResizeEnd("unsupported");
e.ResizeStart("unsupported");
})
.Navigatable(false)
.Editable(e => e.Confirmation(false))
.Toolbar(t =>
{
t.Add().Name("Menu").Template("<a href='/BackendSchedule/Index'>Schedule Menu</a>");
})
.ListWidth("450")
.ShowWorkDays(false)
.ShowWorkHours(false)
.Snap(true)
.Height(2000)
.DataSource(ds => ds
.Read(read => read
.Action("Tasks", "BackendSchedule")
)
.Model(m =>
{
m.Id(f => f.TaskID);
m.ParentId(f => f.ParentID);
m.OrderId(f => f.OrderId);
m.Field(f => f.Title);
m.Field(f => f.Title1);
m.Field(f => f.Start);
m.Field(f => f.End);
m.Field(f => f.Expanded).DefaultValue(false);
})
)
//.DependenciesDataSource(ds => ds
// .Read(read => read
// .Action("Dependencies", "BackendSchedule")
// )
// .Model(m =>
// {
// m.Id(f => f.DependencyID);
// m.PredecessorId(f => f.PredecessorID);
// m.SuccessorId(f => f.SuccessorID);
// m.Type(f => f.Type);
// })
//)
.Resources(r =>
{
r.Field("resources");
r.DataColorField("Color");
r.Field("PercentComplete");
r.DataSource(ds => ds
.Custom()
.Schema(s => s
.Model(m => m.Id("Id"))
.Data("Message")
)
.Transport(t =>
{
t.Read("GanttResources", "BackendSchedule");
})
);
})
)
#(Html.Kendo().Window().Name("utilityWindow")
.Title("Edit Job")
.Iframe(true)
.Visible(false)
.Modal(true)
.Draggable(true)
.Width(500)
.Height(250)
.Events(evt => evt
.Close("closeWindow")
)
)
<script>
kendo.culture().calendar.firstDay = 1;
function closeWindow(e) {
$(this.element).empty();
}
function unsupported(e) {
// remove not supported/permitted in this app
e.preventDefault();
}
function editingGantt(e) {
var jobId = e.task.title.split(':')[0];
var win = $("#utilityWindow").data("kendoWindow");
win.refresh({ url: "/BackendSchedule/_Jobs?jobId=" + jobId + "&source=gantt" });
win.setOptions({
title: "Edit Jobs",
width: 1000,
height: 600,
});
win.center().open();
e.preventDefault();
}
function databoundGantt(e) {
var gantt = $("#Gantt").data("kendoGantt")
var data = gantt.dataSource.data();
$.each(data, function (i,row){
var taskElement = $("div[data-uid=\"" + data[i].uid + "\"]");
if (row.percentComplete == 0) {
taskElement.addClass("color-green");
} else {
taskElement.addClass("color-red");
}
//alert(row.percentComplete);
});
}
</script>
Controller:
#region Gantt
[Authorize(Roles = "Manager, Administrator, Responsible Party")]
public ActionResult Gantt()
{
ViewBag.Title = "Manage Schedule";
return View();
}
public JsonResult GanttResources()
{
List<MessageModel> resources = new List<MessageModel>();
MessageModel resource = new MessageModel();
resource.Id = "0";
resource.Message = "green";
resources.Add(resource);
resource = new MessageModel();
resource.Id = "1";
resource.Message = "red";
resources.Add(resource);
return Json(resources, JsonRequestBehavior.AllowGet);
}
[Authorize]
public JsonResult Tasks([DataSourceRequest] DataSourceRequest request)
{
Jobs jobs = new Jobs();
var tasks = jobs.GetTasks();
return Json(tasks.AsQueryable().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
public JsonResult Dependencies([DataSourceRequest] DataSourceRequest request)
{
var dependencies = new List<DependencyViewModel> {
new DependencyViewModel { DependencyID = 100, PredecessorID = 0, SuccessorID = 0, Type = DependencyType.FinishStart }
};
return Json(dependencies.AsQueryable().ToDataSourceResult(request));
}
public ActionResult Resources()
{
return View();
}
And Core: (Note the information desired is found on the title1)
public List<TaskViewModel> GetTasks()
{
List<TaskViewModel> tasks = new List<TaskViewModel>();
Teams teamObject = new Teams();
IEnumerable<TeamModel> teams = teamObject.GetTeam();
int taskId = 0;
int parentId = 0;
bool teamChanged = true;
foreach (TeamModel team in teams)
{
teamChanged = true;
taskId++;
parentId = taskId;
TaskViewModel task = new TaskViewModel();
task.TaskID = taskId;
task.ParentID = null;
task.Title = team.Name + ": " + team.LeadName;
task.Expanded = true;
task.Summary = true;
task.Start = DateTime.Today.AddDays(-7);
task.End = task.Start.AddMonths(3);
tasks.Add(task);
foreach (JobModel job in getJobs().Where(j => j.TeamId == team.Id).OrderBy(j => j.PlanStartDate))
{
taskId++;
task = new TaskViewModel();
task.TaskID = taskId;
task.ParentID = parentId;
task.Title = job.Id /*+ ": " + job.ContactName + ": " + job.Phone + ": " + job.FullAddress + ": " + job.City + ": " + job.State*/;
task.Title1 = job.Id + ": <p>" + job.ContactName + ": </br>" + job.Phone + ": </br>" + job.City + ": </br>" + job.State;
task.City = job.City;
task.State = job.State;
task.Start = job.PlanStartDate;
task.End = job.PlanEndDate;
task.Expanded =true;
task.Summary = false;
if (job.IsComplete)
{
task.PercentComplete = 0.001M;
}
else
{
task.PercentComplete = 0;
}
tasks.Add(task);
}
}
return tasks;
}
public IEnumerable<ScheduleModel> GetSchedule()
{
foreach (JobModel job in getJobs())
{
yield return new ScheduleModel
{
JobId = job.Id,
Title = job.Company,
ContactName = job.ContactName,
Email = job.Email,
Phone = job.Phone,
Start = job.PlanStartDate,
End = job.PlanEndDate,
IsAllDay = true,
TeamName=job.Company,
TeamId=job.CompanyId,
TeamColour=job.TeamId,
};
}
}
Ok so it turned out to be really simple, I just added this and can add any item in the taskViewModel to make it show up
.Tooltip(t =>
t.Template("Contractor: #=task.ContactName #, Phone: #=task.Phone #"))

Opencart adding 3rd level category in filter module

i'm using a module for product filter,
In my admin backend i can able to set filter only for first and second level categories. I need to add 3rd level category too.
Below mentioned is my module controller file,
<?php
class ControllerModuleSuperCategoryMenu extends Controller {
private $error = array();
public function index() {
$this->data['current_version']='2.0.7';
//remove cache files
$this->cache->delete('product_filters');
$this->cache->delete('attribute_filters');
$this->load->language('module/supercategorymenu');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('supercategorymenu', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
}
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['tab_general'] = $this->language->get('tab_general');
$this->data['tab_settings'] = $this->language->get('tab_settings');
$this->data['tab_layouts'] = $this->language->get('tab_layouts');
$this->data['tab_contact'] = $this->language->get('tab_contact');
$this->data['entry_all_values'] = $this->language->get('entry_all_values');
$this->data['entry_list_number'] = $this->language->get('entry_list_number');
$this->data['entry_list_number_explanation'] = $this->language->get('entry_list_number_explanation');
$this->data['entry_pricerange'] = $this->language->get('entry_pricerange');
$this->data['entry_pricerange_explanation'] = $this->language->get('entry_pricerange_explanation');
$this->data['entry_set_vat'] = $this->language->get('entry_set_vat');
$this->data['entry_set_vat_explanation'] = $this->language->get('entry_set_vat_explanation');
$this->data['default_vat_price_range'] = $this->language->get('default_vat_price_range');
$this->data['default_vat_price_range_explanation'] = $this->language->get('default_vat_price_range_explanation');
$this->data['entry_manufacturer'] = $this->language->get('entry_manufacturer');
$this->data['entry_manufacturer_explanation'] = $this->language->get('entry_manufacturer_explanation');
$this->data['text_yes'] = $this->language->get('text_yes');
$this->data['text_no'] = $this->language->get('text_no');
$this->data['entry_count'] = $this->language->get('entry_count');
$this->data['entry_count_explanation'] = $this->language->get('entry_count_explanation');
$this->data['entry_ocscroll'] = $this->language->get('entry_ocscroll');
$this->data['entry_ocscroll_explanation'] = $this->language->get('entry_ocscroll_explanation');
$this->data['entry_nofollow'] = $this->language->get('entry_nofollow');
$this->data['entry_nofollow_explanation'] = $this->language->get('entry_nofollow_explanation');
$this->data['entry_track_google'] = $this->language->get('entry_track_google');
$this->data['entry_track_google_explanation'] = $this->language->get('entry_track_google_explanation');
$this->data['entry_ajax'] = $this->language->get('entry_ajax');
$this->data['entry_ajax_explanation'] = $this->language->get('entry_ajax_explanation');
$this->data['entry_order'] = $this->language->get('entry_order');
$this->data['entry_order_explanation'] = $this->language->get('entry_order_explanation');
$this->data['text_enabled'] = $this->language->get('text_enabled');
$this->data['text_disabled'] = $this->language->get('text_disabled');
$this->data['text_content_top'] = $this->language->get('text_content_top');
$this->data['text_content_bottom'] = $this->language->get('text_content_bottom');
$this->data['text_column_left'] = $this->language->get('text_column_left');
$this->data['text_column_right'] = $this->language->get('text_column_right');
$this->data['entry_layout'] = $this->language->get('entry_layout');
$this->data['entry_position'] = $this->language->get('entry_position');
$this->data['entry_status'] = $this->language->get('entry_status');
$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
$this->data['entry_value'] = $this->language->get('entry_value');
$this->data['entry_separator'] = $this->language->get('entry_separator');
$this->data['entry_examples'] = $this->language->get('entry_examples');
$this->data['entry_separator_explanation'] = $this->language->get('entry_separator_explanation');
$this->data['entry_values_explanation'] = $this->language->get('entry_values_explanation');
$this->data['text_none'] = $this->language->get('text_none');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
$this->data['button_add_module'] = $this->language->get('button_add_module');
$this->data['button_remove'] = $this->language->get('button_remove');
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/supercategorymenu', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['action'] = $this->url->link('module/supercategorymenu', 'token=' . $this->session->data['token'], 'SSL');
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['settings'] = $this->url->link('module/supercategorymenu/settings', 'token=' . $this->session->data['token'], 'SSL');
$this->data['modules'] = array();
if (isset($this->request->post['supercategorymenu_module'])) {
$this->data['modules'] = $this->request->post['supercategorymenu_module'];
} elseif ($this->config->get('supercategorymenu_module')) {
$this->data['modules'] = $this->config->get('supercategorymenu_module');
}
$this->data['settings'] = array();
if (isset($this->request->post['supercategorymenu_settings'])) {
$this->data['settings'] = $this->request->post['supercategorymenu_settings'];
} elseif ($this->config->get('supercategorymenu_settings')) {
$this->data['settings'] = $this->config->get('supercategorymenu_settings');
}
if (isset($this->data['settings']['track_google'])){
$this->data['settings_trackgoogle']=$this->data['settings']['track_google'];
}else{
$this->data['settings_trackgoogle']=0;
}
if (isset($this->data['settings']['list_number'])){
$this->data['settings_listnumber']=$this->data['settings']['list_number'];
}else{
$this->data['settings_listnumber']=7;
}
if (isset($this->data['settings']['nofollow'])){
$this->data['settings_nofollow']=$this->data['settings']['nofollow'];
}else{
$this->data['settings_nofollow']=1;
}
if (isset($this->data['settings']['ajax'])){
$this->data['settings_ajax']=$this->data['settings']['ajax'];
}else{
$this->data['settings_ajax']=0;
}
if (isset($this->data['settings']['order'])){
$this->data['settings_order']=$this->data['settings']['order'];
}else{
$this->data['settings_order']="OH";
}
if (isset($this->data['settings']['ocscroll'])){
$this->data['settings_ocscroll']=$this->data['settings']['ocscroll'];
}else{
$this->data['settings_ocscroll']=0;
}
if (isset($this->data['settings']['countp'])){
$this->data['settings_countp']=$this->data['settings']['countp'];
}else{
$this->data['settings_countp']=1;
}
if (isset($this->data['settings']['pricerange'])){
$this->data['settings_pricerange']=$this->data['settings']['pricerange'];
}else{
$this->data['settings_pricerange']=1;
}
if (isset($this->data['settings']['setvat'])){
$this->data['settings_setvat']=$this->data['settings']['setvat'];
}else{
$this->data['settings_setvat']=1;
}
if (isset($this->data['settings']['manufacturer'])){
$this->data['settings_manufacturer']=$this->data['settings']['manufacturer'];
}else{
$this->data['settings_manufacturer']=1;
}
if (isset($this->data['settings']['tax_class_id'])){
$this->data['tax_class_id']=$this->data['settings']['tax_class_id'];
}else{
$this->data['tax_class_id']="";
}
$this->load->model('localisation/tax_class');
$this->data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();
$this->load->model('module/supercategorymenu');
$this->data['categories'] = array();
$categories = $this->model_module_supercategorymenu->getCategories(0);
foreach ($categories as $category) {
if (isset($this->request->post['VALORES_'.$category['category_id'].''])) {
$this->data['category_attributes'][$category['category_id']]= $this->request->post['VALORES_'.$category['category_id'].''];
} else {
$this->data['category_attributes'][$category['category_id']] = $this->config->get('VALORES_'.$category['category_id'].'');
}
$children_data = array();
$children = $this->model_module_supercategorymenu->getCategories($category['category_id']);
foreach ($children as $child) {
if (isset($this->request->post['VALORES_'.$child['category_id'].''])) {
$this->data['category_attributes'][$child['category_id']]= $this->request->post['VALORES_'.$child['category_id'].''];
} else {
$this->data['category_attributes'][$child['category_id']] = $this->config->get('VALORES_'.$child['category_id'].'');
}
$results = $this->model_module_supercategorymenu->getCategoryAttributes($child['category_id']);
$attribute_data = array();
foreach ($results as $result) {
if (isset($this->data['category_attributes'][$child['category_id']]['attributes'][$result['attribute_id']])){
$attribute_checked=true;
$attribute_seperator=$this->data['category_attributes'][$child['category_id']]['attributes'][$result['attribute_id']]['separator'];
}else{
$attribute_checked=false;
$attribute_seperator="no";
}
$attribute_values=array();
$attribute_values = $this->model_module_supercategorymenu->getAttributeValues($result['attribute_id']);
//foreach ($res as $attribute_value){
//$attribute_values[key($res)]=$attribute_value;
//}
$attribute_data[] = array(
'attribute_id' => $result['attribute_id'],
'name' => $result['name'],
'checked' => $attribute_checked,
'separator' => $attribute_seperator,
'attribute_values'=> $attribute_values
);
}
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'],
'attributes' => $attribute_data
);
}
$results = $this->model_module_supercategorymenu->getCategoryAttributes($category['category_id']);
$attribute_data = array();
foreach ($results as $result) {
if (isset($this->data['category_attributes'][$category['category_id']]['attributes'][$result['attribute_id']])){
$attribute_checked=true;
$attribute_seperator=$this->data['category_attributes'][$category['category_id']]['attributes'][$result['attribute_id']]['separator'];
}else{
$attribute_checked=false;
$attribute_seperator="no";
}
$attribute_values_child=array();
$attribute_values_child = $this->model_module_supercategorymenu->getAttributeValues($result['attribute_id']);
//foreach ($res_child as $attribute_value_child){
//$attribute_values_child[key($res)]=$attribute_value_child;
//}
$attribute_data[] = array(
'attribute_id' => $result['attribute_id'],
'name' => $result['name'],
'checked' => $attribute_checked,
'separator' => $attribute_seperator,
'attribute_values'=> $attribute_values_child
);
}
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'],
'children' => $children_data,
'attributes' => $attribute_data,
//'valores_bd' => $this->data['category_attributes'][$category['category_id']]
);
}
$this->load->model('setting/extension');
if(in_array("ocscroll",$this->model_setting_extension->getInstalled('module'))){
$this->data['ocscroll']=true;
}else{
$this->data['ocscroll']=false;
}
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL,"http://opencart.tictachome.com/version/version.xml");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
$analizador=simplexml_load_string($output,null);
$this->data['version']['version']=$analizador->children()->version;
$this->data['version']['whats_new']=$analizador->children()->whats_new;
foreach($analizador->children()->other_modules as $other_modules){
$this->data['version']['modules'][]=array(
'name' =>$other_modules->name,
'version' =>$other_modules->version,
'url' =>$other_modules->url,
'manual' =>$other_modules->manual,
'price' =>$other_modules->price,
'resume' =>$other_modules->resume,
);
}
$this->load->model('localisation/language');
$this->data['languages'] = $this->model_localisation_language->getLanguages();
$this->load->model('design/layout');
$this->data['layouts'] = $this->model_design_layout->getLayouts();
$this->template = 'module/supercategorymenu.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
private function validate() {
if (!$this->user->hasPermission('modify', 'module/supercategorymenu')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}
?>
Did anyone know how to add the 3rd level category too..
Please share your suggestions.
Thanks,

JQuery Dynatree - search node by name

I would like to start using Dynatree on my page, however I will probably need searching my tree by name. Do you know maybe how to do this?
I needed to have not only matching nodes, but also the whole paths to these nodes. I wrote this functionality and it works for me.
Modifications for library:
var clear = true;
DynaTreeNode.prototype.search = function(pattern){
if(pattern.length < 1 && !clear){
clear = true;
this.visit(function(node){
node.expand(true);
node.li.hidden = false;
node.expand(false);
});
} else if (pattern.length >= 1) {
clear = false;
this.visit(function(node){
node.expand(true);
node.li.hidden = false;
});
for (var i = 0; i < this.childList.length; i++){
var hide = {hide: false};
this.childList[i]._searchNode(pattern, hide);
}
}
},
DynaTreeNode.prototype._searchNode = function(pattern, hide){
if (this.childList){
// parent node
var hideNode = true;
for(var i = 0; i < this.childList.length; i++){
var hideChild = {hide: false};
this.childList[i]._searchNode(pattern, hideChild);
hideNode = hideNode && hideChild.hide;
}
if(hideNode && !this._isRightWithPattern(pattern)){
this._hideNode();
hide.hide = true;
} else {
hide.hide = false;
}
} else {
// leaf
if (!this._isRightWithPattern(pattern)){
this._hideNode();
hide.hide = true;
} else {
hide.hide = false;
}
}
},
DynaTreeNode.prototype._isRightWithPattern = function(pattern){
if((this.data.title.toLowerCase()).indexOf(pattern.toLowerCase()) >= 0){
return true;
}
return false;
},
DynaTreeNode.prototype._hideNode = function(){
if(this.li) {
this.li.hidden = true;
}
}
Use:
$("tree").dynatree("getRoot").search(pattern);
There is currently no search function, but you could use something like this (not tested)
var match = null;
tree.visit(function(node){
if(node.data.title === "foo"){
match = node;
return false; // stop traversal (if we are only interested in first match)
}
});
alert("Found " + match);
I've done it this way
<style>
span.occurance a.dynatree-title{background-color:#3AFF22;}
</style>
DynaTreeNode.prototype.find = function (needle) {
needle = (needle || '');
if (needle.length >= 1) {
var occurs = [];
this.visit(function (node) {
$(node.span).removeClass('occurance'); //remove pervious findings
if (node.data.title.indexOf(needle) != -1) {
occurs.push(node);
node._expandPath();
}
});
for (indx in occurs) { // mark findings
$(occurs[indx].span).addClass('occurance');
}
} else {
$('span.dynatree-node.occurance').removeClass('occurance');
}
},
DynaTreeNode.prototype._expandPath = function () {
var path = [],
node = this;
while (node = node.getParent()) {
path.push(node);
}
for (indx in path) {
path[indx].expand(true)
}
}
usage:
[your selector].dynatree("getRoot").find('needle');
Thanks to #mar10 i made a small, simple function to search a node with title:
// If searchFrom is null, root is used
function seachFolderNodeWithName(name, searchFrom) {
if (name == null) {
return undefined;
}
if (searchFrom == null) {
searchFrom = jQuery('#tree').dynatree("getRoot");
}
var match = undefined;
searchFrom.visit(function (node) {
if (node.data.title === name) {
match = node;
return false; // Break if found
}
});
return match;
};

Resources