Update Change Password Page For Default And Other Groups - opencv3.0

I am using opencart V 3.0.3.0
I want to check if customer group id = default, then show him change password form and allow to change password. Else show table with links to other platforms on my website to change password.
Table with links to other platforms for password change is done by me and it is visible on change password page as expected.
But I not getting how to check customer group id and show form to change password ? which files from catalog/controller and catalog/model needed to change and what can be code on password.twig
e.g. code in password.twig
{{ if customer_group_id==1}} // 1 = default
code to show change password form
{{ else }}
show my created table with links to other platforms on my website.. (it is done and working as expected right now )
{{ end if }}

So after some search, I did it successfully.
Giving solution for others who may needed it
in catalog/controller/account/password.php added
if ($this->customer->isLogged()) {
$data['customer_group_id'] = $this->customer->getGroupId();
} elseif ($this->config->get('config_customer_group_id')) {
$data['customer_group_id'] = $this->config->get('config_customer_group_id');
}
after line 12 i.e.
$this->load->language('account/password');
And in catalog/view/theme/default/template/account/password.twig
added
{% if (customer_group_id=='1') %}
// Your needed code
{% else %}
// another needed code
{% endif %}
after
<h1>{{ heading_title }}</h1>

Related

Auth::user on Laravel with different table

I have two additional column for login with different tables. So, I used 3 tables for login with output like this:
When I want to use username its simply write it like this {{ Auth::user()->username }} so I get value KASIR WEB. But it not work with kd_lokasi and kd_shift. Where I should register it? Or how I can get kd_lokasi and kd_shift value and paste it on view? Thank you for helping me.
Table :
$kd_lokasi = DB::table("tb_kasir_lokasi")->where("vTampil", 1)->get()
->pluck("nm_lokasi", "kd_lokasi");
$kd_shift = DB::table("tb_kasir_shift")->where("vTampil", 1)->get()
->pluck("nm_shift", "kd_shift");

Laravel 7,8- Using AND or OR Operator in #if... #endif does not work

I have a Laravel project where some users are to be shown some data based on their Roles.
Say There are some roles in a list like r001,r002,r003,r004
Suppose I want to show add button to users with roles r002,r004
Here is my blade file
#if($userrole == '002' || $userrole == '004' )
<button>Add Data </button>
#endif
The end result is, it shows that button to everyone, even if their role is different.
How can I overcome this limitation ?
Check $userrole value using {{$userrole}} in your blade file, If $userrole has value r005 than you have to write like
#if($userrole == “r002” || $userrole == “r004” )
<button>Add Data </button>
#endif

Opencart unable to display variable sent from controller in view

I am having difficulty getting a variable to display on the product page in Opencart. I have added a SQL query to catalog/model/catalog/product.php file as below:
public function getLargeItems($product_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "oc_product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id=17 AND (text LIKE '10lt' OR text LIKE '30lt' OR text LIKE '50lt')");
return $query->row;
}
I then added the following to the catalog/controller/product/product.php file:
$large_items = $this->model_catalog_product->getLargeItems($product_id);
Finally I added the following to the /catalog/view/theme/mytheme/template/product/product.tpl page:
<?php if ($large_items) { ?>
<h1>Tree</h1>
<?php } ?>
And it returns Undefined variable: large_items in /catalog/view/theme/mytheme/template/product/product.tpl
I am at a bit of a loss now. Is anyone able to see by my code why its unable to pull the variable from the controller?
I've tried simplifying it by adding $large_items = "Hello" to the controller to see if I can echo this on the view page however it still cant see the variable.
The version of Opencart is 2.3.0.2
Thank you for your time.
I managed to resolve this by doing two things:
Removing oc_ from the query as the prefix is already defined, I was however only able to notice this after discovering that controller changes dont get picked up without clearing the cache in the admin panel > modifications > click the blue refresh button.
I was then able to see the broken query in the php logs.
The issue was my shoddy code, but I hope that the cache refresh information is useful to others if they get stuck.
Thanks
First you must remove oc_ from "oc_product_attribute WHERE product_id =... because prefix is already defined like " . DB_PREFIX . ".
Next you not properly defined $large_items in your controller. must be:
$data['large_items'] = $this->model_catalog_product->getLargeItems($product_id);
then you can get it on your .tpl like $large_items or in .twig {{ large_items }}
in twig your code should be:
{% if large_items %}
<h1>Tree</h1>
{% endif %}
Good luck

Sort array by email in Twig

I have an array of users that I'm looping trough to display on a page.I want to sort the users by their email, but I cant figure out how to do this, I've read trough som of the other questions, but cant get them to work. Any ideas?
{% for group in person.teachers %}
{{person.img}}
{{person.name}}
{{person.description}}
{{person.email}}
{% endfor %}

Display categories

I have my website working on social engine, I have a Main page named as articles.tpl, and in that I have a sub-page named as article.tpl, article.tpl is used to show the entire article, and articles.tpl is used to show topics of articles not the content,
My concern is with articles.tpl(pretty confusing articles and article)
In articles.tpl, 3 articles title, author of article and date is displayed, but I also want to display the category of that article,
For that I tried the following code,
$article_category = "";
$parent_category = "";
$article_category_query = $database->database_query("SELECT articlecat_id, articlecat_title, ".
"articlecat_dependency FROM se_articlecats WHERE articlecat_id='".
$rc_article->article_info[article_articlecat_id]."' LIMIT 1");
if($database->database_num_rows($article_category_query) == 1) {
$article_category_info = $database->database_fetch_assoc($article_category_query);
$article_category = $article_category_info[articlecat_title];
if($article_category_info[articlecat_dependency] != 0) {
$parent_category = $database->database_fetch_assoc(
$database->database_query("SELECT articlecat_id, articlecat_title".
" FROM se_articlecats WHERE articlecat_id='".
$article_category_info[articlecat_dependency]."' LIMIT 1"));
}
}
$smarty->assign('article_category', $article_category);
and in articles.tpl file I called it in this way
<span class="tahoma11_blue">| {$article_category}</span>
But when I check I get nothing, that space is blank, I am just able to see
|
How can I display the category?
i think you have to change
$smarty->assign('categories', $categories);
to
$smarty->assign('article_category', $article_category);
(in your example, you assign the (apparently empty) php variable $categories to the smarty variable categories. then, in the template, you use a smarty variable article_category - which never got assigned)

Resources