How to capture POST on checkout onpage with Magento_Payment_Block_Info - magento

How to capture POST on checkout onpage with Magento_Payment_Block_Info?
class Ks_Gippayment_Block_Info extends Mage_Payment_Block_Info
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('ks/info.phtml');
}
public function getSomePostData()
{
//****direct get POST/GET data from onepage checkout
}

Try
public function getSomePostData()
{
//****direct get POST/GET data from onepage checkout
if(Mage::app()->getRequest()->getPost('firstname')){
}
}
see Zend Framework: Can i just get GET params?

You may use this method by using class
public function getSomePostData()
{
if(isset ($_POST['submit']))
{
$name=$_POST['firstname'];
/**like that**/
}
}
or You can pass as function from button click

Related

Laravel redirect if authorization failed using gates

In my application I am using gates to validate the authorization of the logged in user. I want the user to be redirected to dashboard, with a custom message, instead of showing the traditional 403 | This action is unauthorized. page.
Here is my code:
class SomeController extends Controller
{
public function index()
{
# access
if(!$this->authorize('some-role'))
{
session->set('message', 'message');
return redirect()->route(...);
}
...
}
}
Is this possible..?
Easy way inside controller check here:
if (Gate::denies('update-post', $post)) {
// The current user can't update the post...
}
Proper way.
There is app\Exceptions\Handler.php there is render method where you can set you custom exception NotAuthorizedException (laravel < 5.5):
if($exception instanceof NotAuthorizedException){
return redirect($exception->route());
}
If laravel > 5.6 you can add below code and redirect inside app\Exceptions\Handler.php the render method:
if ($exception instanceof AuthorizationException)

Codeigniter showing error when I try to resubmit form with csrf_protection set to true

My CI website has csrf protection.
$config['csrf_protection'] = TRUE;
So, when I resubmit form by refresh I am getting the following error.
The action you have requested is not allowed
Instead of showing this message, I want it to return to last page.
So, I try to override csrf_show_error() method by extending the CI_Security file.
This is my class located in application/core/My_Security.php
class MY_Security extends CI_Security {
public function __construct()
{
parent::__construct();
$this->load->library('user_agent');
}
public function csrf_show_error()
{
// show_error('The action you have requested is not allowed.'); // default code
// force page "refresh" - redirect back to itself
// a page refresh restores the CSRF cookie
if ($this->agent->is_referral())
{
redirect(site_url());
} else {
redirect($_SERVER['HTTP_REFERER']);
}
}
}
I am getting the following error
Call to a member function library() on a non-object
Insted of changing the core classes, I extended the MY_Securtiy class in core folder of application. and redirecting to past page.
File Location: application\core\MY_Security.php
class MY_Security extends CI_Security {
public function __construct()
{
parent::__construct();
}
public function csrf_show_error()
{
header('Location: ' . htmlspecialchars($_SERVER['REQUEST_URI']), TRUE, 200);
}
}
Thanks for your solution, but it seems better with a return code 302 by changing the request type of the new request to GET, regardless of the type employed in the original request (e.g. POST). The next refresh will not ask any question.

POST method is not work while creating API in codeigniter

I have created API for Login using POST method but it give me error
GET method is work.
Post data through postman
code of student_login method of contrller Api
class Api extends CI_Controller{
public function student_login()
{
$username=$this->input->post['vUserName'];
$password=$this->input->post['vPassword'];
$this->load->model('Api_model');
$result=$this->Api_model->get_login($username,$password);
if(!empty($result))
{
$response["error"]="true";
$response["message"]="You have been successfully login";
echo json_encode(array('result'=>$result));
die( json_encode($response));
}
else
{
$response["error"]="false";
$response["message"]="Invalid Username and Password";
die(json_encode($response));
}
}
}
Model :To load the data of table tbl_students
class Api_model extends CI_Model
{
public function get_login($name,$pass)
{
//echo $name,$pass;
$this->db->select('iStudentID,class,section,vDivision,vGrno');
$this->db->from('tbl_students');
$this->db->where('vUserName',$name);
$this->db->where('vPassword',$pass);
//$this->db->from('tbl_students');
return $this->db->get()->result_array();
}
}
Your Implementation is right, but you can't check the post method through your browser. Try some other tools like postman.

Magento calling parent function not working

I have a plugin: Simple Configurable Products. I've upgraded to 1.8.1 but have an issue with showing the price - it stops rendering the page.
I have found the line that's causing the issue:
parent::_toHtml();
The class that is calling that is as follows:
class OrganicInternet_SimpleConfigurableProducts_Catalog_Block_Product_Price
extends Mage_Catalog_Block_Product_Price
{
public function _toHtml() {
// Do some stuff
return parent::_toHtml();
}
}
So as I see it, the parent class should be: Mage_Catalog_Block_Product_Price. And the line that calls this should simply call the function _toHtml(). Taking this line out means it works, but returns no price. Ideally I need it to render the default/base price html.
Thanks in advance
Try calling it like this:
class OrganicInternet_SimpleConfigurableProducts_Catalog_Block_Product_Price
extends Mage_Catalog_Block_Product_Price {
public function _toHtml() {
// Do some stuff
return Mage_Catalog_Block_Product_Price::_toHtml();
}
}
Call the object by name instead of by parent::_toHtml()

MVC: Is it possible to override controller action?

A little background first as to why I need this. I am currently creating a CMS. If you imagine this CMS has a PageController which provides all the information a standard page needs, content, navigation etc.
Now the CMS can be amended for each client using it, and should a client require extra/different information in their pages I would like to override the default PageController with one tailored specifically for their needs.
This is what I have tried:
Base controller
namespace CMS.Core.Controllers {
public class PageController : Controller {
public virtual ActionResult DisplayHome() {
// Logic
return View();
}
}
}
Client specific controller
namespace CMS.ClientCore.Controllers {
public class PageController : Core.Controllers.PageController {
public override ActionResult DisplayHome() {
return Content("Client Home"); // Just for testing
}
}
}
Route
routes.MapRouteInLowercase(
"Home",
"",
new { controller = "Page", action = "DisplayHome" },
new[] { "CMS.Core.Controllers", "CMS.ClientCore.Controllers" }
);
The Error
The request for 'Page' has found the following matching controllers:
PCCMS.Core.Controllers.PageController
PCCMS.ClientCore.Controllers.PageController
The cause of the error is obvious, so is there an alternative method to override a controller/controller action?
You are approaching the problem in the wrong way.
Create a IContentProvider which is used by the PageController, and let the content provider figure out what content the current customer needs.

Resources