Magento LiteMage Cache - Excluding a block from caching - magento

I have a Magento site with LiteMage cache on.
My website share a common header at every pages. In the header, I have the following code, which checks to see if a customer is logged in to show either "Account" if logged in or "Log in" otherwise.
My problem is that, when a customer is logged in, it still shows "Log in" in some pages but "Account" at some other pages.
I believe this problem is related to my cache, how do I fix this?
How do I set to exclude this particular block from caching in LiteMage, if this is how it should be fixed.
The following code is the relevant part of the codes I have at my header.phtml
<?php
//check the user is logged on or not
if (! Mage::getSingleton('customer/session')->isLoggedIn()){
//if user logged on show the logout link - add this code within anchor tag
echo ''.$this->__('Log In').'';
}
else{
//if user is not logged on yet show the login link - add this code within anchor tag
echo ''.$this->__('Account').'';
}
?>

You need to identify which block contains this code. Like in default magento sample data, the login link is inside "top.links", and that block is hold punched. Try not to use the full header for it, the smaller the scope, the faster it is. Once you know the block name, you can add that in the "customized block name for top links".

Related

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.

Seblod: How to make url redirection happen only if the captcha is verified?

Using Seblod I created a form where users can enter their name, email id and captcha. They can view next page only when they fill this correctly. To go to next page, I gave url redirection feature (site form->configuration).
But now page redirects to next page even if user enters wrong captcha. How to make the redirection happen only when entered captcha is correct?
There will be an if statement for the captcha so that if it's correct, it moves on, else nothing happens and the captcha resets.
The code to redirect the user after submitting the form will need to go inside the if statement.
Open recaptchalib.php and go to line 184, where you will see the following:
if (trim ($answers [0]) == 'true') {
$recaptcha_response->is_valid = true;
//Redirect Code
}
Where I have added the comment, try adding in your redirect code

Displaying a cms page from within a template file

I'm trying to display a home page for logged in users and a different home page for non logged in users. Up until now i've been using the standard homepage with the url key 'home' as my homepage. I've created a new cms page with the url key 'home1' which will be for non logged in users.
I'm able to output some content from the non logged in users page but if I add a table and insert images using the wysisyg then the image src is stripped when i go to view the page. It's only displaying text at the moment, if I hard code the images its fine but i need to be able to use the wysiwyg.
Both pages are using the empty.phtml template file.
Inside this template file i have the following code
# Check if user is logged in and output the standard home page
if($this->helper('customer')->isLoggedIn()) {
echo $this->getChildHtml('content');
}
else
{
# Load cms page for non logged in users then output the content
$model = Mage::getModel('cms/page')->load('home1','identifier');
echo $model->getContent();
}
there's probably a much better way of doing this so if anybody knows it then I'd appreciate your input.
Thank you
Try to show the both content from Magento Static Blocks instead using two cms pages.
if($this->helper('customer')->isLoggedIn())
{
// Static Block Content for Logged in Customers
echo $this->getLayout()->createBlock('cms/block')->setBlockId('logged_in_customers')->toHtml();
}
else
{
// Static Block Content for Non-Logged in Customers
echo $this->getLayout()->createBlock('cms/block')->setBlockId('non_logged_in_customers')->toHtml();
}

Loading a page from url does not work, but page work when I click Refresh

I have a URL that displays a customer list like this:
http://domain.com/pls/apex/f?p=724:2:820875406836801:::::
The list of customers are displayed with the title being linked to Page3 & request has CustomerId
When I click the URL http://domain.com/pls/apex/f?p=724:3:21712451478201::NO:RP,3:P3_CUSTOMER_ID:82, Page 3 is loaded correctly with details of selected customer. But the "Update" and "Delete" action buttons never work.
But, if I click the browser refresh button and then try to perform an update or delete, it works.
I don't know where I could be going wrong. Can someone give me hints?
I am not using BRANCH_TO_PAGE_ACCEPT in my URL link definition.
It looks like you have the session ID hardcoded in the URL on page 2:
http://domain.com/pls/apex/f?p=724:2:820875406836801:::::
The session ID is 820875406836801, whereas:
http://domain.com/pls/apex/f?p=724:3:21712451478201::NO:RP,3:P3_CUSTOMER_ID:82
The session ID has mysteriously been changed to 21712451478201. I'm not sure, but I suspect that you've hardcoded the session ID in your report on page 2. This has the effect of causing a new login session to be created when page 3 is opened (and maybe this is why the update/delete buttons don't work - but you haven't told us what the error message is so I'm not sure); refreshing the page may be restoring the session.
If I'm right, what you need to solve this issue is to use the session variable (&SESSION.) in your report on page 2 instead of hardcoding it, e.g.:
http://domain.com/pls/apex/f?p=724:3:&SESSION.::NO:RP,3:P3_CUSTOMER_ID:82
The issue was with the way the url was created. First of all, I should not set only 1 thing (Title) to be a url. It should be the entire div. Like below.
<li><div style="">
<a href="f?p=&APP_ID.:2:&SESSION.::NO::P2_PK_PROJECT_ID:#LINK#" rel="external">
<h3>#TITLE#</h3>
<p><strong>#BOLD_TEXT#</strong></p>
<p>#PLAIN_TEXT#</p>
</a></div>
</li>
A report row template with the above code was created. This template is used in my Customers List page. Now each customer is a link (Title, Name, etc). The link href is also hard-coded. Note that I am passing ProjectID:#LINK# #LINK# refers to a value like 1, 2 etc
Now clicking this, loads page 2 correctly and Apply Changes & Delete button are now clickable.

How to move the estimate shipping block to a CMS page in Magento?

I'm trying to move the 'Estimate Shipping' block, that usually sits in the Cart, to a CMS page.
I've successfully moved the form, however, upon clicking the 'Estimate..' button, I get redirected to the Cart.
I've tried changing
action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>"
to the cms page url:
`action="getUrl('delivery/estimatePost') ?>"`
and also a general:
action="<?php echo $this->getUrl('*/*/estimatePost') ?>"`
but then I just get a 404.
You should keep action="getUrl('checkout/cart/estimatePost') ?>" or otherwise you will need to create a different controller action which generate a different block content to allow to display in your cms block but it's not so easy as you try to do.
The string checkout/cart/estimatePost means module/controller/action, if you change that of course he won't find your page. That's why you need to develop a solution more complex with a mix of controller and based on the block classes used while the action estimatePost is called.

Resources