Custom Page in Opencart 3 - php

I am not a coder and have followed the instructions that are available to create a custom page in Opencart 3.0.3.8 under PHP 8 using localhost.
The structure is:
admin\controller\addproduct\addproduct.php
admin\model\addproduct\addproduct.php
admin\language\addproduct\addproduct.php
admin\view\template\addproduct\addproduct.twig
I have tried hard to find the problem, but with no error reports I cannot discover why the page does not load properly. I intend to add more specific coding for my neds once the page is working properly.
Any help appreciated.
Subbie
I have used an ocmod to create the admin menu item.
The ocmod creates the menu item and it appears on the admin menu as expected.
The Users Administration boxes in the system appear and permissions are granted in both panels.
All pages load without errors.
However when clicking the menu button the page reports:
“You do not have permission to access this page, please refer to your
system administrator.” The link is seen as –
http://localhost/public_html/admin/index.php?route=admin\view\template\addproduct\addproduct&user_token=BY81QNSZHHlvjChht62y28S0WnBVSCg3
Any help to solve the issue appreciated.
Below are the various pages that have been created.
Controller:
<?php
class ControllerAddproductAddproduct extends Controller {
public function index() {
$this->load->language('addproduct/addproduct'); // calling Add Prodduct Page language
$this->document->setTitle($this->language->get('heading_title')); // set title from Add Prodduct Page language
$this->load->model('addproduct/addproduct'); // calling Add Prodduct Page model
$data['information_total'] = $this->model_addproduct_addproduct->getTotalInformationsOnAddproductAddproduct(); // calling model method
// breadcrumbs
$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('heading_title'),
'href' => $this->url->link('addproduct/addproduct', 'user_token=' . $this->session->data['user_token'], true)
);
// calling header, footer and column_left for our template to render properly
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('addproduct/addproduct', $data)); // send our $data array to view
}
}
Language:
<?php
// Heading
$_['heading_title'] = 'Add Product Page';
// Text
$_['text_custom_block'] = 'Product Page Block';
$_['text_total_informations'] = 'Total informations:';
Model:
<?php
class ModelAddproductAddproduct extends Model {
public function getTotalInformationsOnAddproductAddproduct() {
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "information");
return $query->row['total'];
}
}
Twig:
{{ header }}{{ column_left }}
<div id="content">
<div class="page-header">
<div class="container-fluid">
<h1>{{ heading_title }}</h1>
<ul class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
<li>{{ breadcrumb.text }}</li>
{% endfor %}
</ul>
</div>
</div>
<div class="container-fluid">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-thumbs-up"></i> {{ text_custom_block }}</h3>
</div>
<div class="panel-body">{{ text_total_informations }} {{ information_total }}</div>
</div>
</div>
</div>
{{ footer }}
OCMOD:
{{ header }}{{ column_left }}
<div id="content">
<div class="page-header">
<div class="container-fluid">
<h1>{{ heading_title }}</h1>
<ul class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
<li>{{ breadcrumb.text }}</li>
{% endfor %}
</ul>
</div>
</div>
<div class="container-fluid">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-thumbs-up"></i> {{ text_custom_block }}</h3>
</div>
<div class="panel-body">{{ text_total_informations }} {{ information_total }}</div>
</div>
</div>
</div>
{{ footer }}

This has been solved elsewhere. The issue was a link in the OCMOD. Tghis is the correct code.
'href' => $this->url->link('addproduct/addproduct', 'user_token=' . $this->session->data['user_token'], true),

I don`t understand why your link so strange...
The correct link must like that:
https://yourdomain.loc/admin/index.php?route=addproduct/addproduct&user_token=BY81QNSZHHlvjChht62y28S0WnBVSCg3
My recommendation:
Copy standard module in extension folder, understand how it`s work and after all of that try to write module with custom path.

Related

Symfony redirect to a part of page

I have a symfony page composed of 3 parts ( and i'm using tags to display each part) by navigation menu here is the navigation menu.
<ul class="nav nav-tabs centered">
<li class="active">
{{ 'fiche_pharmacie'|trans }}
</li>
<li>
{{ 'Mon équipe'|trans }}
</li>
<li>
{{ 'Configuration_automate'|trans }}
</li>
{# <li>
{{ 'Services'|trans }}
</li> #}
</ul>
After that i call 3 twig pages to display each page content.
<div class="tab-pane" id="fiche_patient">
{{ include(':prof/Entreprise:indexdetails.html.twig') }}
</div>
<div class="tab-pane" id="my_team2">
{{ include(':prof/Entreprise:my-team.html.twig') }}
</div>
<div class="tab-pane" id="config">
{{ include(':prof/Entreprise:config.html.twig') }}
</div>
My probleme is after submit i would like to display config.html.twig page.
In my controler i tried :
return $this->redirect($this-> generateUrl('entreprise_index'.'#config'));
but it doesn't work
Any one of you have an idea ?
The correct syntax for what you are trying to do there is:
return $this->redirect($this->generateUrl('entreprise_index').'#config');
You can use redirectToRoute()
$yourRouteParams = array('param1'=>1);
return $this->redirectToRoute('entreprise_index', $yourRouteParams);
You can send the tab name as a parameter to twig. And, in the template, set the active tab according to that parameter.

OctoberCMS - Overridden Blog Component (Rainlab Blog) Multiple Usage in Same Page

I am new to OctoberCMS and I am stuck now, I am facing issue to use my custom blog posts component (which overrides Rainlab blog posts) in the same page multiple times.
Say I have created an alias of default blogPosts to postLists and I defined my custom HTML structure and it is working well, no issues.
Now what I want is to use the postLists post structure in my page for three different categories and here I am stuck because when I pass variable to component like this - { % component 'postLists' categoryFilter='news' %} it does not work for the category filter and if I select a category from drag drop component UI it becomes global categoryFilter setting for the page.
This is my requirement.
My postList component code:-
{% set posts = __SELF__.posts %}
{% for post in posts %}
<div class="col-sm-6">
<div class="row">
<div class="col-sm-4 col-4 content_body_img">
<a href="{{ post.url }}">
{% if post.featured_images.count > 0 %}
<img class="media-object" src="{{ post.featured_images.first.getThumb(108, 108) }}" />
{% else %}
<img class="media-object" src="http://placehold.it/108x108" />
{% endif %}
</a>
</div>
<div class="col-sm-8 col-8">
<p>{{ post.title }}</p>
<!--location_date-->
<div class="location_date">
<ul>
<li><i class="fa fa-calendar"></i><span> {{ post.published_at|date('j F, Y') }}<span></li>
<li><i class="fa fa-map-marker"></i>Dubai</li>
</ul>
</div>
<!--location_date end -->
</div>
</div>
</div>
<!--content_body_img end -->
{% else %}
<div class="col-sm-6 col-6 col-lg-3">{{ noPostsMessage }}</div>
{% endfor %}
Please help me, any help will be very much appreciated.
Thanks Sanny
This is static Approach - I will post dynamic Approach as well give me some time
Best and possibly easy solution will be ( in case you just intend to show posts ) is to add 3 Post List component with Different Category filter option for each tab.
It should do your work
make sure this is optimal solution if you just need to show lists nothing else.

Showing all subcategories when click on main category in Laravel

I'm trying to make function where when I click on main category name should load new page and display all subcategories if there are some.
So far I have this in my route
Route::get('/subcatView/{categoryId}', ['uses' => 'CategorySingleProducts#showSubCats']);
This is button in my index view where I click to load sub-cats
{{ $category_menu['category_name'] }}>
This is from my controller
public function showSubCats($categoryId) {
$subcats = SubCategories::where('category_id', '=', $categoryId)->first();
return View::make('site.subcategory', [
'subcats' => $subcats
]);
}
and subcategory blade
#foreach($subcats as $i => $subcategory)
<div class="col-md-4">
<div class="panel panel-default text-center">
<div class="panel-heading">{{ $subcategory['sub_cat_name'] }}</div>
<div class="panel-body min-h-230">
<img src="{{ $subcategory['sub_cat_image'] }}" alt="{{ $subcategory['sub_cat_name'] }}" />
</div>
<div class="panel-footer">
<div class="row">
<div class="col-sm-6 text-right">
View More
</div>
</div>
</div>
</div>
</div>
#endforeach
In sub_category table I have column category_id which is equal to main category id.
When I open the page now I don't get anything for sub categories. no sub_cat_name, sub_cat_image... nothing. Just empty html style
Your subcats query in the controller should request get (an array) not first (single object).
$subcats = SubCategories::where('category_id', '=', $categoryId)->get();

Relational variables are null while trying to print them in twig file on an AJAX call

I'm working on a wordpress plugin using herbert. I have two controllers, the one (ClientController) which is called via panel and the second one(TimelineController) is an API controller for saving new data on the time line and is called via AJAX request using routes.
Here are my two controllers
ClientController
public function edit(Http $request)
{
$client = $this->clientsRep->find($input["id"]);
$timeline = $client->timeline;
return view('#AdminViews/edit.twig',compact('client', 'timeline'));
}
TimelineController
public function store(Http $request)
{
if($request->ajax())
{
if (is_user_logged_in())
{
$class = ucfirst($request->get('type'));
$c = 'Testing\\HelpedClasses\\TimelineLib\\'.$class;
$activity = new $c();
$activity = $activity->saveActivity($request);
if (is_array($activity))
{
$type = $activity["type"];
$activity = Activities::find($activity["activity_id"]);
$returnHTML = herbert('twig')->render('#AdminViews/edit/timeline_partials/timeline-row.twig', [
'activity' => $activity,
]);
return new JsonResponse(['success' => true, 'html' => $returnHTML, 'type' => $request->get('type'));
}
}
}
}
Here are the Models with their relations
class Client extends Model
{
public function timeline()
{
return $this->hasOne('Test\Models\Admin\Timeline', 'timeline_client_id', 'ID');
}
}
class Activities extends Model
{
public function clientNote()
{
return $this->hasOne('Test\Models\Admin\Notes', 'notes_timeline_activities_id', 'ID');
}
}
Here are the views
edit.twing
<div class="wrap">
<h1>Edit: {{client.clientMeta.name.value }} {{client.clientMeta.name.lastname }}</h1>
<div class="postbox ">
<ul class="nav nav-pills">
<li class="active">Account</li>
<li>Activity</li>
</ul>
<div class="inside">
<div class="tab-content clearfix">
<div class="tab-pane active" id="1a">
{% include '#AdminViews/edit/edit.twig' %}
</div>
<div class="tab-pane" id="timeline">
{% include '#AdminViews/edit/timeline.twig' %}
</div>
</div>
</div>
</div>
</div>
timeline.twig
<h3>Activity</h3>
<div class="timeline row">
<div class="col-sm-12 col-md-4 col-md-push-8">
Add Note <i class="fa fa-sticky-note"></i>
</div>
<div class="col-sm-12 col-md-8 col-md-pull-4 timeline-section">
{% if timeline is not null %}
<ul class="timeline">
{% for activity in timeline %}
{% include '#AdminViews/edit/timeline_partials/timeline-row.twig' %}
{% else %}
<li class="empty-list">Looks like you have no addresses added.</li>
{% endfor %}
</ul>
{% else %}
<p class="empty-list">Looks like you don't have any timeline yet for this customer.</p>
{% endif %}
</div>
</div>
timeline-row.twig
<li>
<div class="direction-l"><span class="time-wrapper"><span class="time">{{activity.updated_at}}</span></span></div>
<div class="direction-r">
<div class="flag-wrapper">
<span class="flag">
{% include '#AdminViews/edit/timeline_partials/timeline-row-'~ activity.timeline_meta_key ~ '.twig' %}
</span>
</div>
</div>
</li>
and here is a sample of activity.timeline_meta_key value: timeline-row-note.twig
<span class="timeline-key"> <i class="fa fa-bell-o"></i>{{activity.timeline_meta_key}}</span>
<div class="clearfix"></div>
{% if activity.clientNote %}
<p class="note-subject">{{activity.clientNote.notes_subject}}</p>
{% endif %}
{% if activity.clientNote %}
<p class="note-desc">{{activity.clientNote.notes_description}}</p>
{% endif %}
Now if I call the ClientController it shows me fine the values {{activity.clientNote.notes_subject}} and {{activity.clientNote.notes_description}}
If now I call the TimelineController is not printing the variables that I already mentioned, I did a dd() in the twig file and it says that the variable is null, but if I do dd() before
$returnHTML = herbert('twig')->render('#AdminViews/edit/timeline_partials/timeline-row.twig', [
'activity' => $activity,
]);
and after Activities::find($activity["activity_id"]); the two variables have the correct value. Does anyone knows why is not showing me the values of the relation activity.clientNote in the twig files if I'm do an ajax call?
Thank you

Phalcon volt include another volt

so I have this volt code:
views/administrator/index.volt
{{ content() }}
{% set user = session.get('user') %}
<br />
<div class="row">
<div class="col-xs-12 col-md-12 col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" href="#container_userForm">
<span class="glyphicon glyphicon-asterisk"></span>
<b style="color: green;">New user</b>
</a>
</div>
<div id="container_userForm" class="panel-collapse collapse">
<div class="panel-body">
{% include "administrator/" ~ user['role'] ~ "-form-user.volt" %}
</div> <!-- end panel body -->
</div>
</div>
</div>
</div> <!-- end row -->
views/administrator/moderator-form-user.volt
exist and has some content.
but when I run the code, I have this error
View '/var/www/html/phalcon-dash/app/config/../../app/views/administrator/moderator-form-user.volt' was not found in the views directory
I took out the user['role'] and use {% include "administrator/moderator-form-user.volt" %}, it works normally (user['role'] = 'moderator')
can anyone explain to me why it happens and how to work around it, I'll need to implement more roles in the future, and I don't want to have multiple if-else in volt
Update
This is the answer to the problem
Volt not including file if path is concatenated
Have you tried it with partial?
{{ partial("administrator/" ~ user['role'] ~ "-form-user") }}
I'm guessing something is not right with views directory. Could you check it out as well?
From your controller, you can try this to get your views directory;
$this->view->getViewsDir()
Try to use the slash. Your include probably looks for a folder "administrator" inside of a folder "administrator", where index.volt is.
{% include "/administrator/" ~ user['role'] ~ "-form-user.volt" %}

Categories