I need to know one thing regarding magento add-to-cart feature. On the product page there is a form which submits your command if you want to buy that product. I need to know the php page that's receiving and parsing the submitted data.
The action attribute of the form has a strange URL so I can't really see which php page is doing the job. (ie http://www.mysite.com/index.php/checkout/cart/add/uenc/aHR0cDovL3d3dy5wdWxzZWlyYXZpcnR1YWwuY29tLmJyL3Y4L25vdmEvaW5kZXgucGhwL3B1bHNlaXJhLWlkZW50aWZpY2FjYW8vcHVsc2VpcmFzLXBlcnNvbmFsaXphY2FvLWVtLXByZXRvL3B1bHNlaXJhcy1kZS1pZGVudGlmaWNhY2FjYW8tZW0tdHl2ZWsuaHRtbA,,/product/12/ )
The above URL hit:
app\code\core\Mage\Checkout\controllers\CartController.php
And function name is: public function addAction(), around 170 line
Hope it will help!
Take a look at the code inside:
app/code/core/Mage/Checkout/controllers/CartController.php
Related
From the research I've done this code should work. But for some reason I keep getting the error that the page is not found. Maybe it's because it's going though my Main_controller?
public function privacy($page='privacy') {
$this->load->view($page);
}
The VIEW:
Privacy Policy<span class=""></span>
The idea is have the privacy popup from anywhere I would want to link to it. Right now I have to put the text on the same page and then link to it through the id="myModal-privacy".
Thanks for any and all input.
The codeigniter url convention is: "mysite.com/controller/function/id. see docs
your link contains a hashtag, which is not working as id like you intend, change it to the CI-convention like this:
Privacy Policy<span class=""></span>
which will now send in the url myModal-privacy as id and you'd load this page in the controller:
$this->load->view('myModal-privacy');
In your question controller name is Main_Controller and in the view, you are using main.
If you are not defining route then use same controller name to call the function
Privacy Policy<span class=""></span>
Did you forget to add a question mark?
Correct Code
Privacy Policy<span class=""></span>
Currently my users must get the visit form given by Route::get then fill it in to get back a result view given by Route::post. I need to create a shareable link such as /account/search/vrm/{vrm} where {vrm} is the VRM that is usually filled in on the form page. This VRM then needs to redirected to Route::post as post data. This needs to be done by my controller. How can I do this in my controller?
Routes:
// Shows form view
Route::get('/account/search', 'User\AccountController#getSearch')->name('account.search');
// Shows result view
Route::post('/account/search', 'User\AccountController#runSearch');
// Redirect to /account/search as POST
Route::get('/account/search/vrm/{vrm}', function($vrm) { ???????? });
POSTs cannot be redirected.
Your best bet is to have them land on a page that contains a form with <input type="hidden"> fields and some JavaScript that immediately re-submits it to the desired destination.
You can redirect to a controller action or call the controller directly, see the answer here:
In summary, setting the request method in the controller, or calling a controller's action.
Ps: I don't want to repeat the same thing.
For those who comes later:
If you are using blade templating engine for the views, you can add '#csrf' blade directive after the form starting tag to prevent this. This is done by laravel to prevent cross site reference attacks. By adding this directive, you can get around this.
return redirect()->route('YOUR_ROUTE',['PARAM'=>'VARIABLE'])
This is an extension from a post I made a few days ago: Change a page without refreshing - Laravel / Ajax
Basically, I'm trying to replicate the URL Structure of Soundcloud where you can click on a link, it'll load the content without refreshing the page however if you land directly on that page, it won't replicate design and effecitvely break.
I've been thinking of ways on how I can check in Laravel if the page is requested via Ajax or has been landed on without an Ajax call.
What's happening at the moment is that when I call the page, the view has a master template that's extended thus creating duplicate master templates on the one view.
I was thinking if I done something like
#if(!Request::ajax())
#extends('masterlayout')
#endif
It would work but tried and no luck.
Any help as always is greatly appreciated!
Thanks
Looks like #extends directive is always executed even in falsy if
You can add an empty layout and perform check like this:
#extends(Request::ajax()? 'layouts.empty' : 'layouts.master')
and you need add only this in layout empty.blade.php:
#yield('content')
or you can add ajax check in the master layout
#if(!Request::ajax())
// all layout code
#else
#yield('content')
#endif
You can check that in your controller action.
public function index(Request $request)
{
if($request->ajax()){
return "This is an AJAX call!";
}
return "Not an AJAX call...";
}
Thanks for all the answers, I eventually got this fixed by using #if(!Request::ajax()) on section that didn't need to be shown when the page was loaded via ajax.
Thank you again! :D
here's the situation:
I have a page generated from a custom post type in Wordpress.
This page has a custom metabox with a "thank you" message.
In this page there is a contact form generated with Contact Form 7.
What I would like to archive is that when someone submits the post, a ajax function replaces the form with the content in the metabox.
Now the content in the metabox has also some script (tracking codes) that I don't want to load before the the form is submitted.
Any suggestions?
Thanks in advance!
It is possible to do what you want but since you are using CF7 it requires quite a lot of customisation.
It would be way easier to achieve the desired result if you could hardcode the php form into the page.
Let me know if that's an option for you and maybe I can give you an hand.
I have an observer watching the event sales_quote_item_set_product. In it, i am checking some conditions to make sure the item is still available. If it is not, i run this code:
Mage::helper('checkout/cart')->getCart()->removeItem($item->getId())->save();
Mage::getSingleton('message/session')->addError($item->getName() . ' is no longer available.');
The problem I'm having is if an item becomes unavailable and a guest is on a product view page, the cart says the item is in the cart, but the total for the cart is updated to reflect the product being removed. Also the error message is not displayed. If you go to another page or refresh the product view page the error message will display and the number of items in the cart will be correct.
So my thought is i need to run this code earlier in the execution cycle, but i have no idea what event i should be observing, or if i shouldn't be using an observer at all. I tried using sales_quote_load_after, but that caused a recursion error somehow. Can anyone tell me when/where i should run this code?
Another wild thought is could it be because i'm using database sessions instead of the file system?
The problem was that the error was being added after the messages block was rendered. I fixed it by adding a redirect to the cart page after the error was added.
$request = Mage::app()->getRequest();
if($request->getModuleName() != 'checkout' && $request->getControllerName() != 'cart' && $request->getActionName() != 'index') {
Mage::app()->getResponse()->setRedirect(Mage::getModel('core/url')->getUrl('checkout/cart/index'))
->sendResponse();
exit;
}
You didn't mention it, but this sounds like you're running code during an AJAX request. When you say
Mage::getSingleton('message/session')->addError($item->getName() . ' is no longer available.');
You're adding an error to Magento's session object. Every time a Magento page renders, it checks the session object for errors, and displays them all. This allows multiple developers to add multiple errors to the session, redirect Magento back to the original form.
This doesn't work during an ajax request, because (typically) the rendering process is skipped in lieu of a JSON object or simple, errorless HTML chunk being rendered (leaving the errors in the session).
Knowing what the full request cycle looks like (what's ajax, what's not) would help someone come up with a more concrete answer to your question.