Right now in opencart the system is limited to only showing 2 levels of categories. Does anyone know of a class to get all sub-categories and a full ul li tree?
For example: If you have ever used oscommerce it will show the full tree of sub-cats in the side category menu where as opencart is limited to only two levels.
The default code is like
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
$children_data = array();
if ($category['category_id'] == $data['category_id']) {
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach($children as $child) {
$filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
}
However it only goes two levels, I am looking for all levels to build out an accordion menu.
Further I am not looking for someone to do this, (unless you want), but maybe you can point me in the right direction or to an existing class that will achieve this.
You'll need to add each sub-level manually for a 3rd, for a 4th etc. There is no way to just get all of them in one shot.
There was an older stackoverflow thread with a solution on how to add a 3rd level. Perhaps it will work with your version of OC:
get third level category in opencart 2
You basically will need to edit the controller and tpl files for category. If that's too much for you, they sell an extension on their marketplace for it, too.
Related
I am pretty much below beginner level for REGEX/REGEXP and have hit a blocking point in a project I am working in, where I am trying to get the ids for posts that match the search criteria , but I want to restrict the search between 2 sub-strings. I am trying to figure out is how to write the REGEXP in the meta_query:
$args = array(
'post_type'=> 'custom',
'order' => 'DESC',
'posts_per_page' => 10,
'paged' => $page,
'meta_query' => array(
array(
'key' => 'key',
'value' => "title*".$search."*_title",
'compare' => 'REGEXP',
)
),
);
And an example of the field in the DB :
a:302:{s:5:"title";s:10:"Test title";s:6:"_title";s:19:"
Unfortunately none of the combinations I tried based on documentation of SQL REGEXP won't return any values and I am trying to understand how I can pull this off and would appreciate any input.
Also would rather stick to WP_Query for now even though an SQL LIKE "%title%{$search}%_title%" works perfectly , so an alternative solution would be how to set the compare to 'LIKE' and parse it '%' since that is not possible out of the box as the % get escaped I believe.
I'm developing a plugin that lets me add and delete custom table records. Adding and deleting records works fine.
I also want to be able to update the records. This is where I cannot figure out what I'm doing wrong.
Here is my update code if anyone can point me in the right direction (I'm currently focused on the "update selected record" script:
function url_update() {
global $wpdb;
$id = $_GET["id"];
$launchname=$_POST["launchname"];
$url1 = $_POST["url1"];
$url2 = $_POST["url2"];
$urluser = $_POST["urluser"];
$urlpwd = $_POST["urlpwd"];
$wpfirstname = $_POST["wpfirstname"];
$wplastname = $_POST["wplastname"];
$wpemail = $_POST["wpemail"];
$activated = $_POST["activated"];
//update selected record
if(isset($_POST['update'])){
$wpdb->update('launcher',
array(
'id' => $id,
'launchname' => $launchname,
'url1' => $url1,
'url2' => $url2,
'urluser' => $urluser,
'urlpwd' => $urlpwd,
'wpfirstname' => $wpfirstname,
'wplastname' => $wplastname,
'wpemail' => $wpemail,
'activated' => $activated
),
array( 'ID' => $id ), //this line fixed the issue
array('%d','%s','%s','%s','%s','%s','%s','%s','%s','%s'));
}
//delete
else if(isset($_POST['delete'])){
$wpdb->query($wpdb->prepare(
"DELETE FROM wp_tincan_launcher WHERE id = %d",$id
));
}
else{
//selecting row to update
$selected_record = $wpdb->get_results($wpdb->prepare(
"SELECT id,launchname,url1,url2,urluser,urlpwd,wpfirstname,
wplastname,wpemail,activated from launcher where id=%d",$id
));
foreach ( $selected_record as $s ){
$launchname=$s->launchname;
$url1=$s->url1;
$url2=$s->url2;
$urluser=$s->urluser;
$urlpwd=$s->urlpwd;
$wpfirstname=$s->wpfirstname;
$wplastname=$s->wplastname;
$wpemail=$s->wpemail;
$activated=$s->activated;
}
}
I think my code is correct, however, I would really appreciate some feedback that directly addresses my code.
EDIT: Thanks to Pekka for pointing out that I did not identify the error results.
The Error I'm getting from WP is "Notice: Undefined index: each column in the DB."
Best Regards
I resolved it myself by changing my update query to include a new line as follows: array( 'ID' => $id ), before the types line.
None of the links I was led to, not any of the generic advice I was provided was of any help what-so-ever.
I've edited the original code to reflect the complete working code.
opencart 1.5.5.1 how change on normal link? See on picture http://i.imgur.com/H9krDbT.jpg
link in administration order to edit items (admin/index.php?route=catalog/product/update&token=4d93b21563db6a6c5fe44b7c365c210b&product_id=54), this is bad, how change on normal link (index.php?route=product/product&product_id=54)
$action = array();
$action = array(
'text' => [[Pass_text_value]],
'href' => $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . [[Pass_product_id_here]] . $url, 'SSL')
);
See this is the only way you should pass actions like EDIT from the controller to template. The whole link will not be displayed but only the passed text.
If you are passing more than one instances to template then put these whole code inside your foreach loop and change $action = array( to $action[] = array(.
I have 4 columns in a datagrid. The manuals give examples on how to sort on a column derived from the database using the array('OrderByClause' => QQ::OrderBy(QQN::Pubs()->Name)
however, I want to sort on a calculated results $_FORM->getDistance($_ITEM)
What I have so far is this:
$this->dtgPersons->AddColumn(new QDataGridColumn('Row Number', 'CurrentRowIndex + 1) ?>'));
$this->dtgPersons->AddColumn(new QDataGridColumn('Pub Name', 'Name ?>', 'Width=200', //));
array('OrderByClause' => QQ::OrderBy(QQN::Pubs()->Name), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Pubs()->Name, false))));
$this->dtgPersons->AddColumn(new QDataGridColumn('Street', 'Address1 ?>', 'Width=200',
array('OrderByClause' => QQ::OrderBy(QQN::Pubs()->Address1), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Pubs()->Address1,
false))));
$this->dtgPersons->AddColumn(new QDataGridColumn('Distance from
Location', 'getDistance($_ITEM) ?>', 'Width=300'));
This following line works on columns that have a sort on them
$this->dtgPersons->SortColumnIndex = 2;
I am unsure about this. Try asking at the github page - http://github.com/qcubed/framework.
I want to display the currency list on the product description page. How can I do that?
I copied the code from header.tpl () and pasted it in the product.tpl but I get an error:
Notice: Undefined variable: currency in C:\xampp\htdocs\mysite.com\catalog\view\theme\mytheme\template\product\product.tpl on line 60.
I tried adding the following code in product.tpl.
<?php include(DIR_APPLICATION.'\view\theme\mytheme\template\module\currency.tpl');
but that did not work either. Please help as I want to get this working.
controller/common/header.php function index() add in to:
$this->data['mygetcurrency'] = $this->currency->getCode();
catalog\view\theme\default\template\common\header.tpl add in to:
<?php echo $mygetcurrency; ?>
//EUR
i guess this can be the easiest way.
<?php echo $this->currency->getSymbolRight($this->session->data['currency']) ?>
OR
<?php echo $this->currency->getSymbolLeft($this->session->data['currency']) ?>
The best will be to do like this
$this->load->model('localisation/currency');
$this->data['allcurrencies'] = array();
$results = $this->model_localisation_currency->getCurrencies();
foreach ($results as $result) {
if ($result['status']) {
$this->data['allcurrencies'][] = array(
'title' => $result['title'],
'code' => $result['code'],
'symbol_left' => $result['symbol_left'],
'symbol_right' => $result['symbol_right']
);
}
}
thanks
The $currency variable is built by the /catalog/controller/module/currency.php controller, which is normally called by /catalog/controller/common/header.php (using $this->children array).
To display this element in the product template, you'll need to call on this controller (and its view) using the $this->children array of the product controller (/catalog/controller/product/product.php). In opencart 1.5.4.1, it's around line 362
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header',
'module/currency' // Just add this line
);
Unfortunately, this will display the currency element at the top of the page by default, because this element's style is set to absolute positioning. You'll need to edit /catalog/view/theme/*/template/module/currency.tpl to make the HTML and CSS a bit more flexible.
you can use very simple code. add this in your controller file.
$data['currency-symbol'] = $this->currency->getSymbolLeft($this->session->data['currency']);
And now you can echo it in your related .tpl file using this
<?php echo $currency-symbol ;?>