Adding extra field on opencart checkout - php

I'm using opencart v.1.5.1 How do I add extra text area on opencart checkout page?
I've added Step 6 using photoshop, how do I code that on opencart?

I don't know about your programming background, but you need to be a little bit more than familiar with PHP, AJAX, JavaScript and of course MySQL, you should also know about the MVC architecture. If you think you have enough knowledge of those then here is what you need to do:
Create a controller class and name it lets say "remarks"
class ControllerCheckoutRemarks extends Controller {
public function index() {
// Your code
}
}
add the code you need to process the data, you can get some ideas by looking at "checkout/guest/shipping" controller class. What you need is quite similar to what that class does.
if you need to interact with the database in order to process the data then you need to create a Model class in the same route under the Model folder and write your functions in it. again you can get the idea from other model classes. But I don't think you need this, probably you want to add this information to your order, in order to do that you should modify the Order class, both Controller and the Model !
Finally you need to create a template file for it, once again open the template file for "checkout/guest/shipping" and see how they did it, then you create your own.
For the controller and model classes make sure you name them properly.
There is one more thing you need to do, The controller class for the step 5 sets the redirect to the next step which by default is the Confirmation. Change this line and make it redirect to your section and do the same thing for the new section and redirect it to Confirm:
url: 'index.php?route=checkout/shipping'
I can only guide you what to do, how to do it is your job :D If you are a programmer then I don't think you'll have any problem with it. if you're not i guess you'll need someone to do it for you :)

Related

codeigniter, views are never called directly, can someone explain

I just started to use codeigniter. I need to know the explanation of
Views are never called directly.
Is it mean that i can not use $this->load->view('My_view') into another view?
I created a project in core php and decided to convert into codeigniter. In my project a page has different section so i created a main file recipes.php in views. I also created a folder where i put different section files to include in recipes.php. In my controller i loaded recipe view, it showed the recipe page then inside recipes view i used $this->load->('categorymenu'). It worked fine. I didnt pass any data since this section contains simple html. But im confused that it is not a right way of loading views.
So please can someone explain in detail. Am i doing the right thing or is there another way of doing it.
I also loaded the view in controller and passed to main view in controller which also worked perfect. But as i mentioned im not sure which is the right approach. My apology if this is a stupid question.
As you are naive to Codeigniter no question asked by you is stupid.
Now the answer of your question is that,
You can load a view inside another view and it is absolutely acceptable as there will be some cases when you have to put header in all pages of the web site, that time you have to load the view in another view.
Second is that the correct way to load the view is in the controller. As the controller is the mediator between the model and view. if you want some data of database to be displayed in your page you have to get that data through the function created in the model and then after you can load the view in controller and can pass the data in that.
This is code of controller
public function temp()
{
$data['recs']=$this->my_model->my_function(); //getting data to pass in view
$this->load->view('my_view',$data); //load the view
}

Where to place common code in Phalcon-based site that is called each page load

I have code that I want to run on every page load, such as looking up menu items, looking up the users details etc. These will be displayed on partial views that make up the main view.
Where do I place this code so that it can fill my partial views with each page load? I know I can just add the code to the top of the partial view itself, but this doesn't really follow the MVC pattern.
Is there a function that is always called that I can hook into in my base controller?
You can create a base viewmodel for the repeated code and make other viewmodels inherit from it.
...such as looking up menu items, looking up the users details etc
You're a bit unclear about the type of information you want to load: in case the info is a view-component then indeed you should create a base-view and inherit from it or include it (composition) in any other view.
But, in case it is "user-information" - the data should live in a model-component that again, may live as "base-model" object that is included in other model components.

CakePHP: Use function from Plugin Controller in Main Controller

This should be simple but I've spent over an hour trying to figure it out so thanks for your help.
I've got a CakePHP plugin, Usermgmt, with a controller located here:
./app/Plugin/Usermgmt/Controller/UsersController.php
I'm trying to call a function, userIdFromUsernameAndPassword(), in that controller from one of my main controllers using something like:
$userID = $this->UsersController->userIdFromUsernameAndPassword( 'user#host.com','pass' );
What do I need to import/include/initialize to be able to get this working?
I've tried various import statements such as App::uses('UsersController', 'Usermgmt.Controller'); at the top of my file, but haven't gotten anywhere.
Thanks!
Short answer: Use OOP and extend the other controller. Also get an understanding of MVC. You are not supposed to use a method of a controller inside another controller, in CakePHP this should be done as a component. They can be shared between controllers. Check the CakePHP Book.
Also the name of the plugin and the method name indicate that this is a bad plugin. This sounds like somebody did not know about the Auth component of CakePHP. Again, check the book for the AuthComponent. You want a custom authentication adapter.
If the user is logged in you can get its id by calling $this->Auth->user('id'). Read the chapter about Auth. If you want a properly done user plugin check out: CakeDC Users

CakepPHP: help with the cakephp comments plugin

Hi I'm trying to use the CakePHP comments plugin found here http://cakedc.com/downloads/view/cakephp_comments_plugin but the instructions are really hard to follow. I've managed to add comments but it's displaying the commentWidget that's not working.
I'm getting confused at this part i think
To work properly, the component needs
a specific variable to be set in every
action using it. Its name should be
either
Inflector::variable(Controller::$modelClass)
or Comments::$viewVariable should be
set to other name of this view
variable. That variable should contain
single model record. for example you
need to have next line in you view
So far I've created the comments table, added it to the pluging and components arrays and added the following code to the controller:
public function beforeFilter() {
parent::beforeFilter();
$this->passedArgs['comment_view_type'] = 'flat';
}
I added the route
Router::connectNamed(array('comment', 'comment_view', 'comment_action));
And also the Comments.CommentWidget as a helper in my controller.
I'm just wondering if anyone has used this plugin before and can help me out?
thanks,
Jonesy
You're right - the documentation is really confusingly worded. However, if I understand correctly, what it wants is a copy of the record of the piece of data the comment will be attached to passed to the view the comments will render on.
So say you're making an event page, and you want people to comment on the event. You need to send to the view a variable called "event" with a copy of the base data for that event.
From their example they show: $this->set('post', $this->Post->read(null, $id));
For your event, you'd do something like $this->set('event', $this->Event->read(null, $id_of_event));
The Comment view probably needs this data for hidden fields so it can populate it with the model name and the event id.

Data from multiple models in one view (web page)

I'm new to the MVC pattern but have been trying to grasp it, for example by reading the documentation for the CakePHP framework that I want to try out. However, now I have stumbled upon a scenario that I'm not really sure how to handle.
The web site I'm working on consists of nine fixed pages, that is, there will never exist any other page than those. Each page contains something specific, like the Guest book page holds guest book notes. However, in addition, every page holds a small news box and a short fact box that an admin should be able to edit. From my point of view, those should be considered as models, e.g. NewsPost and ShortFact with belonging controls NewsPostController and ShortFactController. Notice that they are completely unrelated to each other.
Now, my question is, how do I create a single view (web page) containing the guest book notes as well as the news post box and the short fact? Do I:
Set up a unique controller GuestBookController (with an index() action) for the guest book, so that visiting www.domain.com/guest_book lets the index action fetch the latest news post and a random short fact?
Put static pages in /pages/ and in let the PagesController do the fetching?
< Please fill in the proper way here. >
Thanks in advance!
It sounds like you need to look into elements, or else you may be able to embed this into the layout - but its neater to use an element if you ask me, keep the things separate.
http://book.cakephp.org/2.0/en/views.html#elements
These allow you to have create small views that you are able to embed into other views.
You may also need to put some logic into the AppController (remember all other controllers extend the app controller) to load the data required for these views. The beforeRender function should be useful for this - its one of the hook functions cakephp provides, so if you define it on a controller, its always called after the action is finished before the view is rendered.
Something like this in your AppController should help:
function beforeRender() {
$this->dostuff();
}
function doStuff() {
// do what you need to do here - eg: load some data.
$shortfacts = $this->ShortFact->findAll();
$news = $this->NewsPost->findAll();
// news and shortfacts will be available within the $shortfacts and $news variables in the view.
$this->set('shortfacts', $shortfacts);
$this->set('news', $news);
}
If there are models you need in the app controller for use within this doStuff method, then you need to define them within uses at the top of the AppController
class AppController {
var $uses = array('NewsPost', 'ShortFact');
}

Categories