OPENCART search by model in featured module - opencart

in opencart when edit my featured module, and add new product, my search is by name, and not by model...
it is possible search by product model?? and not by name
this happens in all modules that need to add a product

You don't need to do much more just edit below file only:
\opt\lampp\htdocs\opencart\admin\view\template\module\featured.tpl
on Line no.121
url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent(request.term),
You need to just
url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_model=' + encodeURIComponent(request.term),
you need to filter_model as parameter which you will be type

Related

Rails 4 Dynamically Generate an Extra Public-Facing URL on Create

I have a Rails app that stores stock photos in each project. Upon creating a project, I want the app to not only create the url for the project that we will view internally, which is projects#show,i.e. /projects/4 but I also want it to create another URL that we can show to the client that will be a little different. It will allow the to approve the photos, etc. I want the url to be something like /projects/st53d where the end of the url will be a random number generated with random_string = SecureRandom.urlsafe_base64(5)
This way, I can pass this url to the clients and they can view all the photos in the project and approve the ones they want us to use, but cannot change or view the other internal stuff we have on the standard product show page
Currently, I have added a client_url column to the Project model and I was thinking of generating the random number within the Project#create method and then saving it to the project's client_url column. This way I can loop through all client urls and make sure I did not generate a duplicate. But I cannot figure out how to do the route creation part.
i have yet to do the part where I check if it is random but I know how to do that, just not the route creation.
I was thinking I needed to create a new method which I named show_client and somehow create a route for that in my config/routes.rb file
class ProjectsController < ApplicationController
before_action :authenticate_user!, only: [:show,:index]
def create
#project = Project.create(project_params)
#project.creator = current_user.email
require 'securerandom'
random_string = SecureRandom.urlsafe_base64(5)
#project.client_url = random_string
#project.save
redirect_to #project
end
def show_client
#project = Project.find(params[:id])
#photos = #project.photos
end
This seems like more of a roles issue. You could check out something like CanCanCan. If you only need two kinds of users, you could also just add a boolean column for admin to your user table. The url extension doesn't seem to matter in the scope of your problem. If you want to use a different view for the visiting the user show page, something in the show action like:
unless current_user.admin?
redirect_to client_show(current_user.id)
end
I was able to figure it out.
I created the client_url column in the database and upon creating a project, in the create method of the projects_controller, I generated a random base64 number and assigned it to project.client_url
in routes.rb i did:
get 'projects/clients/:client_id' => 'projects#clients', as: 'projects_client'
in my projects_controller.rb:
def clients
#project = Project.where(client_id: params[:client_id])
end
then the link to that route is:
<%= link_to 'Client Version', projects_client_path(#project.client_url) %>

How to load catalog model in admin controller

I am using Opencart Version 2.1.0.1, how to load frontend model in admin controller,
i have a model function which tells external booking id
class ModelShippingParcelled extends Model {
public function getParcelledBooking($order_id) {
$query = $this->db->query("SELECT booking_id FROM " . DB_PREFIX . "parcelled WHERE order_id = '" . (int)$order_id . "'");
return $query->row;
}
I want to load this model in admin controller. What is the best way to do this?
Should I rewrite this model in admin too? But I don't want to rewrite the same function. If there is a good way please suggest!
Well, there is one ugly trick to achieve what you want. Example if you want to use the frontend's catalog/product model from your admin controller, then you can:
require_once DIR_CATALOG . "model/catalog/product.php";
$product = new ModelCatalogProduct($this->registry);
This will work also when you want to use the admin model from the frontend controller, just change the require statement.
I also needed to call a function from catalog/model inside admin/model (without copying). Requiring a function occured to be imposible in php.
But I figured out that I can move the function into system/library, for example in /system/library/cart/cart.php.
Albeit cart functions is never called in admin it occured to be possible. So I called it like
$this->cart->functionName($params)
To make sure function is still working in catalog I made replacement via shell like
find catalog -type f -print0 | xargs -0 sed -i '' -e 's/this->model_catalog_filter->functionName/this->cart->functionName/g'
I suggest that you make a copy of the model in the admin folder.
And if you are sure which functions you are gonna use copy only them.

Opencart 1.5.x (may be 2.0), how to put first/last name on any template (not registered user)

Checkout page.
Not registered user.
I need to put first/last user name on custom template (this is custom payment tpl of some small bank).
I now, how do it for registered users, it is easy:
$this->data['firstname'] = $this->customer->getFirstName();
But how to do it for not registerd user?
I can't put first/last name.
Presumably your template will only be displayed after they have placed their order but the order is still in the session?
If this is the case, you can get their details from the payment details (or shipping details depending on which one you want) in the session cookie.
So it would be something like:
$this->data['firstname'] = $this->session->data['guest']['payment']['firstname'];
This is true too:
echo ($this->data['firstname'] = $this->session->data['guest']['firstname']);
echo ($this->data['lastname'] = $this->session->data['guest']['lastname']);
echo ($this->data['email'] = $this->session->data['guest']['email']);
echo ($this->data['telephone'] = $this->session->data['guest']['telephone']);

tagsinput gem in active admin

I'm creating a web application where I've used the active admin gem. Suppose, i've a model named Category with fields names. Now, in my names field i want to insert multiple values by comma separated. And it will look like this. That's why i've used the tagsinput gem. But its not working.
Anyone have any idea how do I do this?
I would do next.
Add to active_admin.js
//= require jquery.tagsinput
$(selector).tagsInput({
'autocomplete_url': url_to_autocomplete_api,
'autocomplete': { option: value, option: value},
'height':'100px',
'width':'300px',
'interactive':true,
'defaultText':'add a tag',
'onAddTag':callback_function,
'onRemoveTag':callback_function,
'onChange' : callback_function,
'removeWithBackspace' : true,
'minChars' : 0,
'maxChars' : 0 //if not provided there is no limit,
'placeholderColor' : '#666666'
});
Add to active_admin.css.scss
*= require jquery.tagsinput
Make sure that you have an action in controller that would create new category. Check if you have it in your routes.rb and that will be your
'autocomplete_url': url_to_autocomplete_api
I didn't try to do all these step. But I think I should give you some ideas.
If that wouldn't work I would add js and css files to my assets directly from tagsinput
If you choose go this way you may need add your js and css to initializer/assets.rb
Rails.application.config.assets.precompile += %w()
I hope it helps.

Load dynamic HTML to display custom template

I own a small website that display to the users an html template (with css). Each user can change the template (customizable).
By default i have a template i copy everytime to a new user or if i get nice template (high rates) users can choose it.
instead of copying the template over and over, is there an easy way for me to create 1 template and then when the page load, it shows on the user page and then he can interact (ajax calls, href links etc...)
for example:
new user logged for the first time, the "user license agreement" shows then he click accept and his page shows up. this "home" page has forms, links, images etc... using a default template. that is the one i want to load dynamically instead of copying this template to each users.
why: i found HTML error in the page and now i need to copy this template to 127 users ... which is a pain.
i am using LAMP
thanks
yes using jQuery!
$('#divID').load('pathToHTMLTemplate') is your answer as long as you have the html file stored on same domain :)
This will fetch the html template using ajax and append its content to the div you want. It can also be 'body'.
Here is the documentation which should tell you everything you need to.
Once the template is loaded you can load the user specific data using ajax or any app server you are using. .load function provides a callback:
$('#divID').load('pathToHTMLTemplate', function(){
// now the template is loaded and you can maniupulate it further or load user specific data
});
It sounds to me (just going off of your post) that you have a directory somewhere with a bunch of files "user1.html", "user2.html" or something similar. All of these are either the same or similar, since they're basically the same template.
My recommendation:
Have a database table (or a flat file, but I recommend a database table) that maps a user ID (or name, however you have them arranged) to a template. For example, if user1 and user2 use template_default.html, but user3 uses template_popular.html, you would have the following in your database:
name|template
user1|template_default.html
user2|template_default.html
user3|template_popular.html
Then in whatever code is currently deciding which page to show the user, change it to pull the user's chosen template out of the database and display that instead. So then you only have 1 or 2 pages instead of 127.
If the user is allowed to make edits to their template, that could be stored as metadata in the table as well, then you could use substitution parameters to add it into the template.
Example:
MySQL table:
CREATE TABLE user_templates (
`user` varchar(100),
template varchar(100)
);
Upon receiving a new user:
INSERT INTO user_templates(`user`,template) VALUES("<username>","default_template.html");
Upon user choosing a new template:
UPDATE user_templates set template = "<new template>" WHERE `user` = "<username>";
Upon user loading the user's page (this done in php):
$template = "default_template.html";
$query = "SELECT template FROM user_templates WHERE `user` = \"" . mysql_real_escape_string($username) . "\"";
$result = mysql_query($query,$databaseHandle);
if ($result && mysql_num_rows($result) > 0) {
$template = mysql_result($result,0,"template");
}
// 1st way to do it
$pageToLoad = "http://www.someserver.com/templates/$template";
header("Location: $pageToLoad");
// 2nd way, if you want it embedded in a page somewhere
$directory = "/var/www/site/templates/$template";
$pageContents = file_get_contents($directory);
print "<div id=\"userPage\">$pageContents</div>";
I assume you mean that you have an HTML file that is customized for each user (look, feel, etc):
User1-theme.html
User2-theme.html
User3-theme.html
User4-theme.html
User4-theme.html
Then you would have a file that has all of your ajax calls, links, etc that you want for each user:
User-Controls.html
What you need to do is
Ensure jQuery is downloaded and included on each of your User Theme Pages.
Add this code snipplet to each of your User Theme Pages:
$("#myDiv").load("User-Controls.html")
(where #myDiv is the div ID on the template page that you want to load the controls into
and User-Controls.html is the path to the html file containing the controls you want to load