Moving Magento "Add to Cart" button to new file not working - magento

I want to move Add to cart button from view.phtml file to 2columns-right.phtml file and I am cant make it work. What I did is that I copied <?php echo $this->getChildHtml('addtocart') ?> from view.phtml file to 2columns-right.phtml and it does not appear at all. I did Flush Magento cache too but nothing again.
Any suggestions on how to make this work?

You should get familiar with magento layout system. To make possible <?php echo $this->getChildHtml('addtocart') ?> work in 2columns-right.phtml this block should be declared as child block of root block (the root is the block that is rendered with 2columns-right.phtml). Actually, I don't see much sense in moving add to cart to other template, because addtocart.phtml itself is just a button that submits whole form that is located at catalog/product/view.phtml. If you take it out of there it won't work.

First of all i agree with nevermourn you can not get childhtml if you havn't declared it. But you can use
<?php echo $this->getLayout()->createBlock('catalog/product_view')->setTemplate('catalog/product/view/addtocart.phtml')->toHtml(); ?>
By using this in 2columns-right.phtml you will get addtocart.phtml for sure.

in order to call add to cart button by using
<?php echo $this->getChildHtml('addtocart') ?>
on the page you desire in layout/local.xml
<yourModule_YourController_yourAction>
<reference name="content">
<block type="catalog/product_view" name="product.info.addtocart" as="addtocart" template="catalog/product/view/addtocart.phtml"/>
</reference>
</yourModule_YourController_yourAction>

Related

Magento - have custom 'Footer Links' static block on all Checkout pages

I have added some custom header/footer phtml files to my Magento installation, the footer uses an static block called 'Footer Links' - this is a HTML block added via the Magento 'CMS' section.
It is possible to have some logic which 'hides' or disables this block on any checkout page?
One way to do it would be via the local.xml in /app/design/frontend/yourpackagename/yourthemename/layout/local.xml. The handles that you need to add depend on how your checkout process is configured. Here is some example code to get you started:
<checkout_cart_index>
<remove name="footer">
</checkout_cart_index>
<checkout_onepage_index>
<remove name="footer">
</checkout_onepage_index>
This is removing the entire footer block, but you can use it to remove any block name that you have. Alan Storms layoutviewer module is great for figuring out what the layout handles are: http://alanstorm.com/layouts_blocks_and_templates.
Hi i have a custom code to disable the footer links block in checkout page add this code in footer.phtml file
<?php $page_route=Mage::app()->getRequest()->getRouteName(); ?>
<?php if($page_route !='checkout'){ ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('footer_links')->toHtml() ?>
<?php } ?>
And comment or remove this code in cms.xml file
<block type="cms/block" name="cms_footer_links" before="footer_links">
<action method="setBlockId"><block_id>footer_links</block_id></action>
</block>

How to add topLinks to a cms page in magento

The answer is probably out there as a combination of several posts but I am not very good at Magento yet so I have to ask anyway:
I would like to have the topLinks inserted into a cms page.
I tried <?php echo $this->getChildHtml('topLinks') ?> but that does not work, it just shows the code as text on the page.
I tried {{block type="core/template" name="top.Links" as="topLinks" template="page/template/links.phtml"}} but nothing shows up.
I did successfully add the search form to the cms page with {{block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"}} so I figured I probably just have the block type wrong or something.
What did I do wrong?
TL;DR: Well...You can't.
Why?:The topLinks block is a "container" block of type page/template_links. This is just added in the layout, but other layout handles or blocks add links to it. For example this part of xml in the customer.xml layout file
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action>
</reference>
adds the My account link to it. There are others.
In conclusion the topLinks block does not have meaning on it's own. It is just a placeholder that can e modified by other blocks.
When a cms page is rendered the layout is already loaded parsed, so the block you add cannot be modified anymore by other blocks or layout files.
You can hardcode put top links in your cms pages like this..
<ul id="nav">
<li class="level0 parent"><span>My Account</span></li>
<li class="level0 parent"><span>My Wishlist</span></li>
<li class="level0 parent"><span>My Cart</span></li>
<li class="level0 parent"><span>Checkout</span></li>
<li class="level0 parent"><span>Log In</span></li>
</ul>
#Marius Thanks, I learned something new there. I am still struggling with understanding the intricate details of Magento's structure but I'm working on it.
#chirag I tried that but php does not work directly in cms pages so it tries to link to http://mymagentopage/<?php echo $this->getUrl('customer/account')?>. I can of course link directly to http://mymagentopage/customer/account but for a few links I would miss functionality:
"Login" changing to "Logout" when logged in and logging the customer out instead of going to the account screen.
"Cart" changing to "Cart(2)" when product is added to the cart.
etc (I don't use wishlist)
Is there a way to regain this functionality?
I found this snippet that does it but it's php which won't work in cms pages:
<?php if (Mage::getSingleton('customer/session')->isLoggedIn()==0): ?>
<?php echo $this->__('Log In') ?>
<?php else: ?>
<?php echo $this->__('Log Out') ?>
<?php endif ?>I would also be happy with a solution to enable me to use php in cms pages, I am the only admin anyway.
EDIT
I found a working solution:
I created a new phtml file containing the above mentioned snippet. I created a new folder 'customphp' in my template folder and saved it there as test.phtml.
In the cms page I added a block: {{block type="core/template" name="whatever_unique-name-i-want" template="customphp/test.phtml"}}
Tada!
This is where I got the idea: http://www.magentocommerce.com/boards/viewthread/439880/

Static block at the end of the page Magento

Move the static block at the end of the page. I searched a lot for solution. But, no luck.
I tried swapping of echo in catalog/category/view.phtml. But it did not work.
<?php echo $this->getCmsBlockHtml() ?> <?php echo $this->getProductListHtml() ?>
I do not want to use css to move the block at the end of the page, It creates other alignment issues.
How to go about this problem?
you can use
before and after attributes but only work in one of two cases
When you insert into a core/text_list block
When your template block calls getChildHtml without any paramaters
When you do like this
<reference name="root">
<block type="core/template" name="your_block" before="content" template="page/html/your-block.phtml"/>
</reference>
you're telling Magento
Hey Magento, put the example_block inside the root block.
those blocks are being explicitly rendered.
<?php echo $this->getChildHtml('example_block') ?>
However, there's two cases where order matters. First, if you call
<?php echo $this->getChildHtml() ?>
hope this will sure help you.
swapping of echo work in magento. I will be :-
<?php elseif($this->isMixedMode()): ?>
<?php echo $this->getProductListHtml() ?>
<?php echo $this->getCmsBlockHtml() ?>
Please check the theme, where you are editing
file. File Path should be:- app/design/frontend/default/your theme/template/catalog/category/view.phtml

Trying to build an AJAX cart in Magento, configuration options not showing

PROBLEM:
I'm trying to build an AJAX cart in magento, but I can't seem to fetch the chosen configuration option(s) of configurable products. I believe am invoking the the right method ($this->getOptionList()) to get them. It should return an array with options and labels, but it returns nothing!! To be clear, they are showing up in the normal cart.
EXPLANATION:
The short story of how I'm doing it:
I use the Cart Controller of the Mage_Checkout module, but I change the template to something very minimal (using layout updates in the current theme), and a custom module with a router defined in it.
Long story:
I have created a module MyNameSpace_Checkout in which I have defined a router that binds the frontName 'ajaxcart' to the controllers in the Mage_Checkout module.
Now in the local.xml file of my current theme I put the following layout updates under the 'ajaxcart_cart_index' handle:
<ajaxcart_cart_index>
<reference name="root">
<action method="setTemplate">
<template>ajaxcart/cart/index.phtml</template>
</action>
<block type="checkout/cart" name="checkout.cart" template="ajaxcart/cart/show.phtml" as="cart"></block>
</reference>
</ajaxcart_cart_index>
My template ('ajaxcart/cart/show.phtml') is being used, so this worked pretty well. I tested it when I went to http://domain.com/ajaxcart/cart
index.phtml:
<?php echo $this->getChildHtml('cart'); ?>
show.phtml:
<?php foreach($this->getItems() as $_item): ?>
<?php $_renderer = $this->getItemRenderer($_item->getProductType())->setItem($_item); ?>
<?php /* render an item */ ?>
<?php endforeach; ?>
Seeing as $this in this context refers to the Cart Block of the Mage_Checkout module, and digging around in the method getItemHtml() of this class (its superclass actually) I found that the block object per item in the cart is retrieved using the second line in the show.phtml sample above ($_renderer).
Does anyone know why information is missing? The whole reason I'm using the original controller is that it is probably doing some essential stuff, but it's still not working!!
Thanks in advance.
I found the problem myself, the layout updates (local.xml of the current theme) were the problem:
<action method="addItemRender">
<type>configurable</type>
<block>checkout/cart_item_renderer_configurable</block>
<template>checkout/cart/item/default.phtml</template>
</action>
I took another look at checkout.xml of the base/default theme and it sported some addItemRender (layout xml) methods in the cart/checkout block under the checkout_cart_index handle. Specifically for my problem, the above element was missing and that messed up the rendering of a configurable product item in the cart. A special type of block object needs to be loaded that actually has the (PHP) method getOptionList().

looking to show product reviews in sidebar on product page magento

I'm looking to show the most recent reviews for a product (maybe 3 or 4) in the sidebar on that products page in magento.
Showing the first 10 or 15 words of the review, the star bar and a link to the reviews page to see all the reviews..
any advice or pointers greatly appreciated,
Thanks,
Johnny
As ElGabby said, creating a extension would be the way to go.
But you can do this by editing your current layout.
Go to the file catalog.xml in /app/design/frontend/default/[your theme]/layout/ or /app/design/frontend/base/[your theme]/layout/
find the section:
<catalog_product_view>
in there you proberly have a section like:
<reference name="right">
in that section add:
<block type="review/product_view" name="right.rewiev" template="review/rightbar.phtml" />
the section in my example look like this:
<reference name="right">
<block type="review/product_view" name="right.rewiev" template="review/rightbar.phtml" />
<block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
</reference>
save the file and create a new file in:
/app/design/frontend/default/[your theme]/design/review/rightbar.phtml
content of that file would be something like:
<?php $collection = $this->getReviewsCollection(); ?>
<?php if(count($collection) > 0):?>
<?php foreach ($collection as $rating):?>
<?php echo $rating->title //title of the rewiev?>
<?php echo $rating->detail //content of the rewiev?>
<?php echo $rating->created_at //data rewiev is created?>
<?php endforeach;?>
<?php endif;?>
I would create an extension.
Using layout.xml place your block that should extend core/template block in left/right sidebar of the product page
Within that block class you should have methods that will retrieve from the database the reviews you wish to display. So say for instance you would need a method getReviews()
In the template call $this->getReviews() and iterate the result and display the reviews as you would like. The star bar might be a bit of a hassle but if you look at other template files where they are used you should be able to get the gist of it :)
HTH :)

Resources