work fine in default opencart checkout
example..
$this->model_setting_event->addEvent('custom_name', 'catalog/view/theme/default/template/checkout/payment_method/after', 'event_function');
$this->model_setting_event->addEvent('custom_name', 'catalog/controller/checkout/payment_method/save/after',
'event_function');
$this->model_setting_event->addEvent('custom_name', 'catalog/model/checkout/order/addOrder/before', 'event_function');
how can i make it work with journal3 one checkout page?
opencart 3.0.2.0
There are 2 approaches, you can choose either one to implement based on which approach is more applicable to your situation:
Replace the view file before rendering the output
Modify the html through the output
I assuming you already know how to register an event, following
example just demonstrate how to implement the approach. Leave me a
comment to let me know if you not sure how to register an event.
1. Replace the view file before rendering the output
Create an event script: catalog/controller/event/my_event.php
/* before */
public function beforeLoadCheckoutView(&$route, &$args) {
/*
if the view route is 'journal3/checkout/checkout',
aka: 'catalog/view/theme/journal3/template/journal3/checkout/checkout.twig'
*/
if ($route == 'journal3/checkout/checkout') {
/*
replace the view file 'journal3/checkout/checkout' with your own view file
aka: 'catalog/view/theme/journal3/template/journal3/checkout/my_checkout_page.twig'
*/
$route = str_replace('journal3/checkout/checkout', 'journal3/checkout/my_checkout_page', $route);
}
}
Create your own checkout page view: catalog/view/theme/journal3/template/journal3/checkout/my_checkout_page.twig
<div>
I have replace the original view with this!
</div>
Result:
2. Modify the html through the output
Create an event script: catalog/controller/event/my_event.php
/* after */
public function modifyCheckoutPageHtml($route, &$args, &$output) {
/*
if the view route is 'journal3/checkout/checkout',
aka: 'catalog/view/theme/journal3/template/journal3/checkout/checkout.twig'
*/
if ($route == 'journal3/checkout/checkout') {
/* replace the title with your own title */
$output = str_replace('<h1 class="title page-title">Quick Checkout</h1>', '<h1 class="title page-title">I have changed this title!</h1>', $output);
}
}
Result:
now I am suffering from new problem
I can do some code when user click this button(繼續===continue)in default 6step checkout through
$this->model_setting_event->addEvent('name','catalog/controller/checkout/payment_method/save/after', 'function');
but in journal3 one step checkout do not have that button.
Related
This is the code in contollers
public function transactionsAction()
{
$ModelLayout = new Pteb_System_Model_Layout_Backend();
$ModelLayout->LoadLayout();
$Block = $ModelLayout->SetContentBlock( 'transactions-block', 'Pteb_System_Block_Cms' );
$Block->setTemplate('user/transactions/results.phtml');
$ModelLayout->ShowLayout();
}
/* this is the content to display on the page,
currently it displays without any template*/
$Block->setTemplate('user/transactions/results.phtml');
/* the template for the content above resides in the same folder as it is, with the name form.phtml. I replaced results.phtml with form.phtml in the above code but it displays the design only not the content.
Basically the form.phtml contains table structure with table heading while the results.phtml contains rows of contents.*/
How do I tell this results.phtml to use form.phtml as a template?
Can you try to go to this block:
Pteb_System_Block_Cms
and add the following setTemplate script:
public function __construct()
{
parent::__construct();
$this->setTemplate('abc/abc.phtml');
}
I am trying to add custom button on top of post type page like this image
Is there any filter or action I can use to add custom button there?
Thanks
I found a way to get it done but I am not very happy with this procedure. Please add your answer if you find better way. Mean while, this might be of help.
add_action('admin_head-edit.php','addCustomImportButton');
I only need this on edit page, so I am using admin_head-edit.php action, but you can use admin_head or some other (not very specific requirement)
/**
* Adds "Import" button on module list page
*/
public function addCustomImportButton()
{
global $current_screen;
// Not our post type, exit earlier
// You can remove this if condition if you don't have any specific post type to restrict to.
if ('module' != $current_screen->post_type) {
return;
}
?>
<script type="text/javascript">
jQuery(document).ready( function($)
{
jQuery(jQuery(".wrap h2")[0]).append("<a id='doc_popup' class='add-new-h2'>Import</a>");
});
</script>
<?php
}
Digging into WordPress core code i did not find any hook or any filter for that buttonm you can also see that code from line no 281 to line number 288 . But you can add your button here according to this filter.
add_filter('views_edit-post','my_filter');
add_filter('views_edit-page','my_filter');
function my_filter($views){
$views['import'] = 'Import';
return $views;
}
Hope it helps you.
If you are using the class WP_Lists_table (and you should) then this is the right way to do it:
add_action('manage_posts_extra_tablenav', 'add_extra_button');
function add_extra_button($where)
{
global $post_type_object;
if ($post_type_object->name === 'shop_order') {
// Do something
}
}
The accepted answer is sadly still the only one that works.
But as the admin heading changed since it was answered, the correct script should now be :
jQuery(jQuery(".wrap .page-title-action")[0]).after('Import');
Unfortunately there is no hook called after showing the "Add New" button.
The closest possible place to add anything without using javascript is below the title and "Add new" like this:
In my example I added a button to my custom post type "Event" using the hook "edit_form_top":
add_action('edit_form_top', 'add_custom_button');
function add_custom_button($id){
if ($post->post_type != 'event') return false;
echo('<button>Custom button</button>');
}
The answer of Touqeer Shafi got me in the right direction, I needed to add a button at the top of my table view for a custom post type (book), I only had to change the post part in the views_edit-post to make it work:
add_action('views_edit-book', function($id) {
echo('Another new book');
});
Now in 2022 with WP 5.9.1, I combined answers from Geza Gog and Tameroski, and it works great:
add_action('edit_form_top', 'my_import_button');
function my_import_button(){
?>
<script type="text/javascript">
jQuery(document).ready( function($)
{
jQuery(jQuery(".wrap .page-title-action")[0]).after('Import');
});
</script>
<?php
}
I am building a Joomla 2.5 component and have a bit of trouble getting the Delete button to function properly. Here is a sample code from the view.html.php file:
if ($canDo->get('core.delete'))
{
JToolBarHelper::deleteList('You Really Wanna Delete that', mycomponentname.delete, 'JTOOLBAR_DELETE');
When I select an item from a dropdown list and click to delete I get the following pop-up:
You Really Wanna Delete that
The problem with this is when I click the option to verify the deletion from the pop-up I am redirected to a 500 error message and the item is not deleted.
Now when I review the Joomla documentation here:
http://docs.joomla.org/JToolBarHelper
I see that JToolBarHelper is defined in administrator/includes/toolbar.php. So I went for a visit over to review the deleteList info there. I see the following code:
public static function deleteList($msg = '', $task = 'remove', $alt = 'JTOOLBAR_DELETE')
{
$bar = JToolBar::getInstance('toolbar');
// Add a delete button.
if ($msg) {
$bar->appendButton('Confirm', $msg, 'delete', $alt, $task, true);
} else {
$bar->appendButton('Standard', 'delete', $alt, $task, true);
}
}
So I have attempted to adjust my script by changing the second parameter $task = 'remove' to read as remove rather than mycomponentname.delete as follows:
JToolBarHelper::deleteList('You Really Wanna Delete that', 'remove', 'JTOOLBAR_DELETE');
This will eliminate the 500 error, but the item is not removed. What am I missing here? My guess is that it has something to do with improperly configuring the mycomponentname.delete function.
PS- I should add that the 500 error states:
Layout default not found
There is only one problem you have. You don't need to put the component name on to the button task. You need to put controller name instead of component name.
if ($canDo->get('core.delete'))
{
JToolBarHelper::deleteList('You Really Wanna Delete that', 'controllerName.delete', 'JTOOLBAR_DELETE');
}
For example :
JToolBarHelper::deleteList('delete', 'hellos.delete','JTOOLBAR_DELETE');
Hope this helps you.
in the controller i have :
$paginator = Zend_Paginator::factory($mdlPost->getPosts($this->moduleData->accordion, 'name ASC'));
if(isset($params['cities'])) {
$paginator->setCurrentPageNumber(intval($params['cities']));
}
$paginator->setItemCountPerPage(4);
$this->view->posts = $paginator;
in the view's i have some thing like this :
if ($this->posts != null) {?>
<div id="cities_accord" class="news">
<?php echo $this->partialLoop('partials/post-min.phtml', $this->posts); ?>
</div>
<?php echo $this->paginationControl($this->posts,
'Sliding',
'public/pagination_cont.phtml');
}
the partial/post-min.phtml
<?php
$color = array(1=>'spring',2=>'summer',3=>'autumn',4=>'winter');
?>
<div id='<?php echo $color[$this->partialCounter] ?>' class="accordion_post">
<?php
$link = Digitalus_Uri::get(false, false, array('openCity' =>
$this->id));//$color[$this->partialCounter]));
?>
<h1 class="accordion_post_title"><?php echo $this->title ?></h1>
<p><?php echo $this->teaser ?> <i>read more</i></p>
</div>
the pagination_cont.phtml taken from this link zend ( http://framework.zend.com/manual/en/zend.paginator.usage.html )
will show links that will pass params to the controller to fetch the corresponding whole page which is working alright for now
but i want to change this so that i will be able ajaxify the returned ( i.e. only a single paginated value rather than reloading the whole page ) results how can i do that using jquery and what should i change ..
** EDIT: it would be nice to have a fail-save ,if possible, for browsers(users) that disabled javascript to see the same thing by reloading the page (i.e. keeping the current status for if(javascript_not_enabled ))**
This is what I've done in the past.
First, setup the AjaxContext action helper to enable the html context on your controller action.
Add a .ajax.phtml view that just contains the section of markup that may be replaced via AJAX as well as the pagination control links. You can probably just copy this out of your normal view. Replace that section in your normal view with something like
<div id="reloadable-content">
<?php echo $this->render('controller/action.ajax.phtml') ?>
</div>
This will ensure that your initial and any non-AJAX requests will still include the right content. The <div> id is purely for referencing the loadable block in JavaScript.
Also make sure you include your JS file (using headScript) in the normal view only.
Now, in your JS file, unobtrusively add the appropriate event binding to the paginator links. As you'll be replacing the pagination control section in order to reflect the correct current page and other links, it's probably best to do this using the jQuery live binding. I'm also assuming you'll wrap the pagination control with some kind of identifiable element (<div class="pagination-control"> for example)
$('.pagination-control').find('a').live('click', function(e) {
var link = $(this);
$('#reloadable-content').load(link.attr('href'), { format: 'html' });
return false;
});
Keep in mind that in using this method, you will lose the ability to navigate the paged requests using the normal back / forward browser buttons. You will also lose the ability to bookmark pages directly (though you could always provide a permanent link to the current page as part of the AJAX loaded content).
You can use something like the jQuery history plugin if you're really concerned but that will require more client-side work.
Another caveat is that the above will only work with pagination links. If you want to use a form with dropdown page selection, you need to add another event handler for the submission.
GOT IT and big Thanks to #Phil Brown :
in the controller int() change the response type to json
class NewsController extends Zend_Controller_Action
{
public function init()
{
$contextSwitch = $this->_helper->getHelper('contextSwitch');
$contextSwitch->addActionContext('list', 'JSON')
->initContext();
}
// ...
}
public listAtcion() {
// .............
$paginator = Zend_Paginator::factory($mdlPost->getPosts($this->moduleData->accordion, 'name ASC'));
if(isset($params['cities'])) {
$paginator->setCurrentPageNumber(intval($params['cities']));
}
$paginator->setItemCountPerPage(4);
$post = array();
foreach($paginator as $post ) {
$post[] = $post;
}
$this->view->post = $paginator;
#TODO //add a check here for non-ajax requests (#improvment)
$this->view->posts = $paginator;
}
in one of the views (most probably in the pagination_cont.phtml) on the pagination controller add the ajax links
<?= $this->ajaxLink (
$this->url('cities'=>$this->page_num),array('id'=>'div_id','complete'=>'js_method(json_data)','method'=>post) ,array('format'=>'JSON'));
and add a JavaScript function of js_method(json_data) to modify the div with id = 'div_id' with a json data
function js_method(json_data) {
var content = parse.JSON(json_data);
$('#div_id').html('');
//fill it with the reposnse content some thing like $('#div_id').append(content);
}
I dont understand what the layout is, in the view. I asked a question previously on the subject of templating in PHP, but I still dont quite understand. I assume that you create a general layout for the site and then include each specific view within that layout.... I would like to know how to go about doing this. Also, are should the templates be made using just html, because I also looked at these things called helpers.... I'm just confused on the View part of the MVC, and the actual templates and how they're made. I learn best with examples, If you guys have any.
Also, a more important question, lets say I had a form that a user saw only if he was logged in, would I control that in the view, or in the controller?
So Would i do
in the controller
include 'header';
if(isset($_SESSION['userID'])){
include 'form';
}
include 'footer';
or
in the template
<html>
<?php if(isset($_SESSION['user_id'])): ?>
<form>....</form>
<?php endif;?>
</html>
EDIT
So, is there an include statement from within the layout to see the specific view template? how so?
a layout is whatever you have around your main content area. Usually on a normal website it would be any sidebar,header,footer. Most of MVC framework provide the layout to avoid to repeat those parts in all views.
You can imagine if like you have two view cascaded
you actual view is rendered, this content is saved
the layout view (all the items around the content) are rendered and your content is included in that output
for your login question actually your would have to do both
on the controller and the view
$this->view->isLogged = isset($_SESSION['userID']);
in the view
<?php if($isLogged): ?>
<form>....</form>
<?php endif;?>
I hesitate to answer this question only because of the religious fervor that surrounds it.
To get a really good understanding of the issues behind the general concepts see This Wiki Discussion Page This is the discussion page around the wiki MVC article.
Here is the rule of thumb I like to follow (BTW I use CodeIgniter and it kind of sounds like you are too):
The "view" should have virtually no logic. It should only be HTML (in the web world) with peppered PHP that simply echos variables. In your example you would break out the form into its own view and the controller would determine if was loaded or not.
I like to look at it this way: The view should have no concept of where the data comes from or where it is going. The model should be view agnostic. The controller meshes data from the model and provides it to the view - and it takes input from the view and filters it to the model.
Here is a quick and dirty (untested - but it should get the point across) example:
Theapp.php (The App controller)
class Theapp extends Controller
{
var $_authenticated;
var $_user;
var $_menu; // array of menus
function __construct()
{
session_start();
if (isset($_SESSION['authenticated']) && $_SESSION['authenticated'])
{
$this->_authenticated = $_SESSION['authenticated']; // or some such thing
$this->_user = $_SESSION['user'];
}
$this->_menu = array("Logout", "Help", "More");
parent::__construct();
$this->loadView("welcome"); // loads primary welcome view - but not necessarily a complete "html" page
}
function index()
{
if (!$this->_authenticated)
$this->loadView("loginform");
else
{
$viewData['menu'] = $this->_menu;
$viewData['user'] = $this->_user;
$this->loadView("menu", $viewData);
}
}
function login()
{
/* code to authenticate user */
}
function Logout() { /* code to process Logout menu selection */ }
function Help() { /* code to process Help menu selection */ }
function More() { /* code to process More menu selection */ }
}
welcome.php
<h1> Welcome to this quick and dirty app!</h1>
All sorts of good HTML, javascript, etc would be put in here!
loginform.php
<form action"/Theapp/login" method="post">
User: <input id='user' name='user'>
Pass: <input id='pass' name='pass' type='password'>
<input type='submit'>
</form>
menu.php
Hi <?= $user ?>!<br>
Here's your menu<br>
<? foreach ($menu as $option) { ?>
<div class='menuOption'><a href='/Theapp/<?=$option?>'><?=$option?></a></div>
<? } ?>
Hope this helps.
If your not using a framework, then a simple way to have a layout and a view can be like so:
<?php
function layout($layout_params) {
extract($layout_params);
# Remember: $layout_content must be echoed for the view to be seen.
ob_start();
include "layout_page.php";
$html = ob_get_contents();
ob_end_clean();
return $html;
}
function view($view_params) {
extract($view_params);
ob_start();
include "home_page.php";
$html = ob_get_contents();
ob_end_clean();
return $html;
}
#
# The variable $parameters is extracted and $params becomes a variable in the view as an array,
# $logged_in is also now avaiable in the view
#
$parameters = array("params" => array("name" => "joe"), "logged_in" => false);
$view_content = view($parameters); # => Returns the HTML content for home_page.php
# Now we need the layout content to include the view:
# The layout file will expect a variable called $layout_content to be the html view.
# So we need to set $layout_content to be $view_content
$parameters["layout_content"] = $view_content;
# We no longer need $view_content so we can unset the variable
unset($view_content);
# When $paramters is extracted it will have $layout_content as a variable:
$layout_content = layout_view($paramters); # => Returns the HTML content for the layout_page.php
# Now send the results to the browser
echo $layout_content;
?>