Magento - Ignore controller or action in ReferrerUrl - magento

I have a problem with redirectReferrer()
When I add a product in cart, I do it with ajax (call : http://wwwww.ww/quickview/product/add).
Until here, everything is ok.
But, if I want to remove product from my cart, the deleteAction() redirect me to http://wwwww.ww/quickview/product/add with the method $this->_redirectReferer(Mage::getUrl('*/*'));
Is it possible to ignore a whole Controller or just an Action in _redirectReferer, without any modification in the deleteAction() ??
I tried this Mage::getSingleton('customer/session')->setNoReferer(true);, but it not seems to work..
Thank you.
PS: Magento CE 1.9.3

I discovered that is inside my controller (and action), that the referrer is setted ...
I return in JSON:
$this->getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('checkout/cart/sidebar.phtml')->toHtml();
I think this is this part who cause my issue..

Related

Check to see if a page is called via Ajax in Laravel

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

Magento add to cart - on which page is the form submitted?

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

magento error message only displays after 2nd page refresh

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.

Magento - Partially overriding indexAction of OnePage controller

I need to partially override the indexAction of OnePage controller. I'm trying to add in a way to get direct to the review step on returning to onepage checkout - all other steps are completed at this point, it's just that Magento behaviour is to start again! It will mean changes to the onestep.phtml as well, but I haven't got the far yet!
My controller override is working fine. I can add a new action on the controller, say reviewStepAction, but if I have this as a simple override for testing, the standard onepage checkout is not displayed. I get blank page with just the standard sidebar:
public function reviewStepAction() {
parent::indexAction();
}
I've also tried copying and modify indexAction to my action function, but still not getting the onepage checkout to display. The final part of indexAction is:
$this->getOnepage()->initCheckout();
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->getLayout()->getBlock('head')->setTitle($this->__('Checkout'));
$this->renderLayout();
So I'm guessing it's not working because the URL is ../checkout/onpegage/reviewstep so it's trying to load a "reviewstep" layout and not finding one. How can I force reviewStepAction to finish off by loading the usual /checkout/onepage layout? I tred using Mage::getSingleton('checkout/opnepage) but that just crashed.
I can't just redirect to checkout/onepage at the end of my action because that would invoke the standard indexAction and I need to insert something between initCheckout and renderLayout.
Thanks.
The following works:
public function reviewStepAction()
{
$this->loadLayout(array('default','checkout_onepage_index'));
$this->getOnepage()->initCheckout();
...additional code...
$this->_initLayoutMessages('customer/session');
$this->getLayout()->getBlock('head')->setTitle($this->__('Checkout'));
$this->renderLayout();
}
Only point to note is that the body class is set to checkout-onepage-reviewstep instead of the usual checkout-onepage-index.

Cannot saveShippingMethod in Magento One Page Checkout

I am writing a custom Magento 1.5.0.1 one page checkout for my site following the instructions on this site:
http://inchoo.net/ecommerce/magento/magentos-onepage-checkout-in-a-nutshell/
In summary, I am calling these functions in order:
$checkout = Mage::getSingleton(‘checkout/type_onepage’);
$checkout->saveCheckoutMethod(‘guest’);
$checkout->saveBilling($billingAddress, false);
$checkout->saveShipping($shippingAddress, false);
$checkout->saveShippingMethod(‘flatrate_flatrate’);
$checkout->savePayment(array(‘method’=>’checkmo’));
// Extra part not on the site but saw it in the original magento onpage checkout controller
$checkout->getQuote()->getPayment()->importData(array(‘method’=>’checkmo’));
//
$checkout->saveOrder();
// Extra part not on the site but saw it in the original magento onpage checkout controller
$checkout->getQuote()->save();
//
The problem is that when the code is first run, the shipping method is not being set, I get a error saying that the shipping method was not set. However, just refreshing the page makes the order go through.
One solution was that right after setting the shipping method with saveShippingMethod, checking if it was set with:
Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getShippingMethod();
Which 100% of the time it is not, then redirecting it back onto the same page, which on the 2nd run the shipping method is set...
this seems to be such a stupid magento bug! any ideas on how to fix it with this redirection (i.e. page refresh)?
Maybe it is me not being extremely expert about magento, but I'm pretty sure you have to use setShippingMethod($method) instead of saveShippingMethod($method) when creating an order, you can check more here.

Resources