Load magento view via ajax? - magento

I have the folliwng file:
app/design/frontend/default/site/template/checkout/cart/cartheader.phtml
I want to load this in via ajax, so that when the cart is updated, we can trigger an ajax call to get the contents of this file and update the page on the fly.
Does anybody know how I can access this file via ajax or even just from my browser so I can see the contents?
Thank you

You need to create a new controller with methods from CartController.php this controller can be found in app/code/core/Mage/Checkout/controllers . The methods to add and remove items from cart should be changed to use ajax and return json. The json returned can have the session messages - global messages block and cart header block, maybe other blocks depending on all info you want to update.
app/design/frontend/default/site/template/checkout/cart/cartheader.phtml is from the enterprise theme and is the template for the block Mage_Checkout_Block_Cart_Sidebar. This template is set inside layout/checkout.xml
<block type="checkout/cart_sidebar" name="cart_sidebar" as="topCart" template="checkout/cart/cartheader.phtml">...</block>
To get it from a controller you can add it to the layout xml of that controller, or use:
$this->loadLayout()->getLayout()->createBlock('checkout/cart_sidebar')->toHtml();
But inside Enterprise, this block already loads using ajax.

Related

Magento newsletter subscribe does not display success or error messages

I'm trying to put a newsletter subscription in the footer of a new site, I have it displaying and posting but:
it does not redirect to a success page
it does send the confirmation notice
unverified subscribers do show up in the admin
clicking on the verification link in the email just goes to the magento home page but does confirm the subscription.
switching the theme back to default works [notices and success url work]
I'm placing the form in the footer using local.xml:
<reference name="footer">
<block
type="newsletter/subscribe"
name="newsletter"
template="newsletter/subscribe.phtml"/>
</reference>
The actual form is the default magento newsletter form with no changes.
How do I get it to show success & error messages on both subscription attempts AND on mail confirmation?
How do I get the confirmation link [in the email] to go to another page in magento other than the home page i.e. a success page or error page?
As I can see in this method \Mage_Newsletter_SubscriberController::newAction (which is called on this action)
You should check where actually in this method you end up. The best way would be to use debugger and set a breakpoint at the beginning of this method. Alternative way would be to use Mage::log as logging mechanism, so you can see where do you end up and why messages doesn't show. As I can see there are multiple outputs for session messages, like here $session->addSuccess($this->__('Confirmation request has been sent.'));
This function is used to redirect to the page that the request came from:$this->_redirectReferer();
You can replace that method call with $this->_redirectUrl($some_url);
Also, if you are overwriting some of the core files, it is always advisable to copy that file (with module structure) to app/code/local/, in order to keep Magento version maintainable.

Prestashop module admin panel with custom view

I need to know how to create a module on Prestashop with a custom view on admin. The documentation is very poor and I don't understand how to call a view with parameters passed by the controller. I'm using Prestashop version 1.6.
I already did these steps:
Created XML.
Created controller with constructor and install/uninstall.
Created table on DB and class.
Linked on admin menu my module.
When I go to my tab on admin panel I see a table with my db data. I need to load a custom tpl file where I can customize completely my page.
I have read so many guides and documentation (ufficial or not) but nothing clear.
Just follow the HTML and CSS in getCOntent() function in your main php file.
Whatever HTML and CSS return getContent() function will be view of your module in admin panel.
Just concentrate in getContent function of other existing module and you will get what you want.
I f you want to load a separate view than create it separate and load it in getContent() function.

Cart functionality in Magento from scratch

I'm fairly new to Magento and am setting up a new theme from scratch. I'm not using any of the standard Magento JS files until now and I've included jQuery and a js file for custom scripts.
Now I'm looking into recreating the Add To Cart functionality but standard wise this seems to call some js function which I do not have declared now (lacking the Magento JS files). I'd like to set it up on my own with an ordinary form submit.
Can anyone give me an example of how to execute the Add To Cart command for the product I'm currently viewing? Without the necessity of standard Magento JS files?
What Magento do for add to cart is it calls productAddToCartForm.submit function of javascript to validate all required field and if true then it submit product form.
So you can call your javascript method for form submit and add to cart.
Add to cart button comes from this file, so you can change onclick event here.
app\design\frontend\base\default\template\catalog\product\view\addtocart.phtml

Call Magento .phtml file via ajax

I have my custom magento plugin. I have the image slider in the product page. I want to call ths particular template(abc.phtml) file via ajax in the product page. Can somebody help me in this?
Thanks
Create such code in your controller (which will render AJAX call) action:
$html = Mage::getSingleton('core/layout')->createBlock('core/template')
->setTemplate('your_module/abc.phtml')->toHtml();
$this->getResponse()->setBody($html);

Block Method Calls in CMS Page

Is there any a way to call Block method calls in CMS page?
What I am trying to do is. I have a hyperlink in my CMS Page and I want to retrieve the email address of the customer to pass it as a get variable which another website will use.
e.g. In CMS page I have
(someother website link)
<a href="www.xyz.com?email=<?php $getCutomer->getEmail();?>&&name=<?php $getCutomer->getName();?>
I know we can't add php in CMS pages or block. I have just shown you as an example what I want to achieve.
So is there any way using XML or anything else?
Please Advise. Thanks
Yes as MagePsycho said, you will need to create phtml file for calling block method or getting dynamic data.
In .phtml file, it's simple just call $this->getCustomerEmail() or whatever method you wrote to get customer email.
Why can't you simply include the .phtml file in CMS page or Static block as:
{{block type="core/template" template="path/to/your-custom-template.phtml"}}
and you can now use any php code in that .phtml file.
Cheers!

Resources