Custom blocks not being rendered - magento

I have developed a collections module for a clients Magento site. Among other things, this module pulls in product details (media, description, attributes) on the category listing page. The issue I am running into is that my blocks are not rendering on the clients site (Magento EE 1.8), even though everything works locally (Magento CE 1.6).
Developer mode has been activated, but I see no errors on the page, and I know that Magento is seeing the module as it correctly shows up in the admin under System > Configuration > Advanced.
We set the base block class name in app/code/local/Mycompany/Collections/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Collections>
<version>0.1.0</version>
</Mycompany_Collections>
</modules>
<global>
<blocks>
<mycompany_collections>
<class>Mycompany_Collections_Block</class>
</mycompany_collections>
</blocks>
</global>
</config>
We insert our blocks to the layout in app/design/frontend/enterprise/mytheme/layout/local.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_category_view>
<reference name="product_list">
<block type="mycompany_collections/collection" name="collection" template="collections/collection.phtml">
<block type="mycompany_collections/product" name="add-to-cart" template="collections/product/add-to-cart.phtml" />
<block type="mycompany_collections/product" name="description" template="catalog/product/view/description.phtml" />
<block type="mycompany_collections/product_attributes" name="attributes" template="catalog/product/view/attributes.phtml" />
<block type="mycompany_collections/product_media" name="media" template="catalog/product/view/media.phtml" />
</block>
</reference>
</catalog_category_view>
</layout>
The mycompany_collections/collection block extends Mage_Catalog_Block_Product_List and reloads the products to ensure we have fetched all the relevant data from the database.
class Mycompany_Collections_Block_Collection extends Mage_Catalog_Block_Product_List {
public function reloadProducts() {
// Fully reload each of the products in this category so that we have
// all the information required to display product details.
// TODO: find a more efficient way to grab all the info for all the
// products, as this would seem to add 1 (or more) additional
// query per product.
$reloaded = array();
foreach($this->getParentBlock()->getLoadedProductCollection() as $product){
$reloaded[] = Mage::getModel('catalog/product')->load($product->getId());
}
return $reloaded;
}
}
The mycompany_collections/product block extends Mage_Catalog_Block_Product_Abstract with custom methods to allow us to explicitly set the product on the block and return that product without pulling from the registry.
class Mycompany_Collections_Block_Product extends Mage_Catalog_Block_Product_Abstract {
private $_product = null;
public function _prepareLayout() {
// We don't need to do anything here.
}
// NOTE: Must be called before ->toHtml()
public function setProduct($product) {
$this->_product = $product;
return $this;
}
public function getProduct() {
return $this->_product;
}
}
Both the mycompany_collections/product_attributes and mycompany_collections/product_media blocks do the same get/set_product overrides for their equivalent abstract parent classes.
Inside our collection.phtml template, we call $this->reloadProducts() and iterate over the product list to display the product details and buy collection popups (these are js lightboxes that activate on click)
<?php
$_productCollection = $this->reloadProducts();
?>
<!-- Buy collection popup -->
<div id="buy-collection" class="no-display">
<h1>Buy Collection</h1>
<?php foreach($_productCollection as $_product): ?>
<div id="buy-collection-product-<?php echo $_product->getId(); ?>" class="product">
<div class="media"><?php echo $this->getChild('media')->setProduct($_product)->toHtml(); ?></div>
<?php /*
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(100); ?>" width="100" height="100" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
*/ ?>
<a href="<?php echo $_product->getProductUrl() ?>" ><?php echo $_product->getName(); ?></a>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart"><?php echo $this->getChild('add-to-cart')->setProduct($_product)->toHtml(); ?></div>
<?php else: ?>
<div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
<?php endif; ?>
<div class="details">
<div class="description">
<?php echo $this->getChild('description')->setProduct($_product)->toHtml(); ?>
</div>
<div class="attributes">
<?php echo $this->getChild('attributes')->setProduct($_product)->toHtml(); ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<!-- Product detail popups -->
<div id="product-details" class="no-display">
<?php foreach ($_productCollection as $_product): ?>
<div id="product-detail-<?php echo $_product->getId(); ?>" class="product">
<div class="media"><?php echo $this->getChild('media')->setProduct($_product)->toHtml(); ?></div>
<div class="description"><?php echo $this->getChild('description')->setProduct($_product)->toHtml(); ?></div>
<div class="attributes"><?php echo $this->getChild('attributes')->setProduct($_product)->toHtml(); ?></div>
</div>
<?php endforeach; ?>
</div>
To actually fire all this off, for any product category that we wish to display as collection we override the category.listing and product_list templates in the Custom Design tab of that category in the admin. These templates contain design changes, and product/list.phtml calls the collection block.
<reference name="product_list">
<action method="setTemplate">
<template>catalog/collections/product/list.phtml</template>
</action>
</reference>
<reference name="category.products">
<action method="setTemplate">
<template>catalog/collections/category/view.phtml</template>
</action>
</reference>
Inside product/list.phtml we call the collection block with a simple echo $this->getChildHtml('collection');. Nothing is returned on this line. No template, no PHP errors, nothing. As mentioned above, this all works beautifully in my local dev environment.
That's the overview of how things are setup. Here's what I have done to debug:
Using Alan Storm's Layoutviewer module, I have confirmed that my blocks are listed on ?showLayout=page, and the handle "catalog_category_view" is listed in ?showLayout=handles. However, when I print $this->getSortedChildren() in product/list.phtml the collection block is not listed.
If I replace the collection block in layout.xml with a super simple core/text block, it does render.
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_category_view>
<reference name="product_list">
<block type="core/text" name="collection"><action method="setText"><text>This is a test</text></action></block>
</reference>
</catalog_category_view>
</layout>
This led me to believe the problem was deeper in my own code, so I simplified and went totally basic… I removed the reloadProducts method from Mycompany_Collections_Block_Collection and reduced collections.phtml to a single line of text to see if something in the template or child blocks were causing an issue. Unfortunately this had no affect and I still got no output.
I'm really at a loss as to why this is not working. I first thought it may be a difference between the Enterprise and Community editions, but something as fundamental as the layout/block system is unlikely to differ between them. There clearly seems to be something missing, and I'm hoping someone may be able to point in the right direction.
Thanks!

Did you check Mycompany_Collections.xml available in /app/etc/modules section and codepool enabled?
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Collections>
<active>true</active>
<codePool>local</codePool>
</Mycompany_Collections>
</modules>
</config>

Related

how do I alter a link in the my account navigation column in magento?

im trying to alter the navigation links in the my account section of my magento site currently they look like this:
I turned on debug template paths so I can locate where it came from but it just sent me to navigation.phtml, which was just some php code the echos the links in a list form see below.
<div class="block block-account">
<div class="block-title">
<strong><span><?php echo $this->__('My Account'); ?></span></strong>
</div>
<div class="block-content">
<ul>
<?php $_links = $this->getLinks(); ?>
<?php $_index = 1; ?>
<?php $_count = count($_links); ?>
<?php foreach ($_links as $_link): ?>
<?php $_last = ($_index++ >= $_count); ?>
<?php if ($this->isActive($_link)): ?>
<li class="current<?php echo ($_last ? ' last' : '') ?>"><strong><?php echo $_link->getLabel() ?></strong></li>
<?php else: ?>
<li<?php echo ($_last ? ' class="last"' : '') ?>><?php echo $_link->getLabel() ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
My goal is simple to rename "My Wishlist" to "My Sample Request" any ideas on how to achieve this ?
If renaming is only the issue than it is very simple.
You just edit the name in the "app/design/frontend/base/default/layout/wishlist.xml".
you will search for below code.
<customer_account>
<!-- Mage_Wishlist -->
<reference name="customer_account_navigation">
<action method="addLink" translate="label" module="wishlist" ifconfig="wishlist/general/active"><name>wishlist</name><path>wishlist/</path><label>My Wishlist</label></action>
</reference>
</customer_account>
change the label "My Wishlist" to "My Sample Request".
This will work.But its not the best way to achieve this.First Override the "wishlist.xml" to your theme and then only make a change.
Hope this will help.
you dont need to do this from xml file , just open the
`app/locale/en_US/Mage_XmlConnect.csv
and around line 601 you wil see a "My Wishlist","My Wishlist"
you can change from there. if you will change in xml file than in multilangual site it will same for all languages. So change from translate file.
thanks
$this->getLinks() is heart of that template. It retrieves all links as an array and then loop through it and display each item. So the array returned by that code is actually constituted by another method addLink(). It normally use in layout files. My guess is, you need to alter that name in layout file.
File : app\design\frontend\<package>\<theme>\layout\customer.xml
You can see many code like this
<action method="addLink" translate="label" module="customer">
<name>account</name>
<path>customer/account/</path>
<label>Account Dashboard</label>
</action>
Here label is the part that you need to change.
So check for this code in customer.xml file. Find the code that generate "Wisthlist" link. Then change the label part according to your need

Removing Magento blocks through xml or phtml

I am starting out in magento theme development and have coded my local.xml to removed 2 blocks below.
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="header">
<remove name="currency" /><!--removes currency selector-->
<remove name="store_language" /><!--removes store language -->
</reference>
</default>
</layout>
This works but the template header.phtml has the block wrapped in divs that are now not needed. See below:
<div class="header-language-background">
<div class="header-language-container">
<div class="store-language-container">
<?php echo $this->getChildHtml('store_language') ?>
</div>
<?php echo $this->getChildHtml('currency_switcher') ?>
<p class="welcome-msg"><?php echo $this->getChildHtml('welcome') ?> <?php echo $this->getAdditionalHtml() ?></p>
</div>
</div>
My question is can I just remove the section from the template file instead of removing the block? Will this effect anything if the blocks are in the xml files but not being called up in any template phtml files?
Thanks :)
If the HTML you need to remove is referenced as a XML block then it is better to remove it from the XML using the <remove> node.
If the HTML to remove is not referenced as a XML block, removing it from the template directly is the only solution. Of course you should edit the template from your own theme and not the one from the base one.
if you remove befault store language then just comment out i header.phtml.
like this.
<?php echo $this->getChildHtml('store_language') ?>
Comment...
<?php **//**echo $this->getChildHtml('store_language') ?>

Magento - display product reviews on product view page

I am having difficulty placing the product reviews on the main product view at a specific location. I can load them in the content area, but not at the specific location I require (within some of the view mark-up).
I have a local.xml with the following in it:
<catalog_product_view>
<reference name="content">
<block type="review/product_view_list" name="product.info.product_additional_data" as="reviews" template="review/product/view/list.phtml"/>
</reference>
<catalog_product_view>
The above loads the reviews after all other content - as might be expected, due to content not being a templated block.
I have tried defining the blocks outside of the content reference, and placing this at the relevant point:
<?php echo $this->getChildHtml('reviews') ?>
For clarity, here is where I need the block to appear in view.phtml:
<div class="product-collateral">
<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
<div class="box-collateral <?php echo "box-{$alias}"?>">
<?php if ($title = $this->getChildData($alias, 'title')):?>
<h2><?php echo $this->escapeHtml($title); ?></h2>
<?php endif;?>
<?php echo $html; ?>
</div>
<?php endforeach;?>
<?php echo $this->getChildHtml('upsell_products') ?>
<?php echo $this->getChildHtml('product_additional_data') ?>
<?php echo $this->getChildHtml('reviews') ?>
</div>
Unfortunately, this doesn't output anything at all. I'm fairly new to Magento, and I'm at a loss how to achieve the above.
You can try leaving the code as in your example and include and use the attribute before, or after.
This allows you to position a block in regards to another block within that reference.
Ex: <block type="review/product_view_list" name="product.info.product_additional_data" as="reviews" template="review/product/view/list.phtml" before="product.description"/>

Call a block in another template

I just create a module name referral. Now I want to place the referral block to another module template file name success.phtml. Can it be done?
referral.xml(in referral module)
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_onepage_success>
<reference name="checkout.success">
<block type="referral/referral" name="referralCallLink"><action method="referralCallLink"></action></block>
</reference>
</checkout_onepage_success>
<!--block type="referral/referral" name="referralAddSession"><action method="referralAddSession"></action></block-->
</layout>
success.phtml
<?php if($hasBoughtMCash): ?>
<div> Your
<?php echo implode(', ',$hasBoughtMCash); ?>
purchase is successful.
</div>
<?php endif; ?>
<h2>Share in Facebook and Earn for Free MCash!</h2>
<?php echo $this->getChildHtml(); ?>
Referral.php(block)
public function referralCallLink() //success page
{
...
$collection7 = Mage::getModel('referral/referrallink')->getCollection();
$collection7->addFieldToFilter('customer_id', array('eq' => $cust_id));
$collection7->addFieldToFilter('grouped', array('eq' => $grouped));
foreach($collection7 as $data3)
{
$product = $data3->getData('product');
$link = $data3->getData('link');
$imageurl = $data3->getData('url');
//facebook
$title=urlencode('Shop, Save and Get Rewarded at MRuncit.com');
$url=urlencode($link);
$summary=urlencode('I just bought '.$product.' from MRuncit.com and earned some MReward Points!');
$image=urlencode($imageurl);
?>
<p>
<a href="http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');" target="_blank">
<img src="<?php echo $imageurl;?>" width="30">
I just bought <?php echo $product; ?> from MRuncit.com and earned some MReward Points!
</a>
</p>
<?php
}
}
Results
You should create the block as child of the success block in your layout XML:
<layout_handle_of_the_success_page>
<reference name="name_of_the_success_block_in_layout">
<block type="your/referral_block" />
</reference>
</layout_handle_of_the_success_page>
Then you can insert the following line in success.phtml:
<?php echo $this->getChildHtml('referral'); ?>
There are some names in the example XML that you have to replace with your own:
layout_handle_of_the_success_page - you will find it in the layout XML of the corresponding module. It should be in the form module_controller_action --> checkout_onepage_success
name_of_the_success_block_in_layout - also from the layout XML, look for the block with the success.phtml template and its name attribute --> checkout.success
your/referral_block - that's the class alias of the block that you want to insert in the form module/class --> referral/referral

I want add custom column for sidebar all page in Magento

I want add my custom sidebar next right column all page.
Please check this link: http://www.wildbuilder.com/images/Untitled-1-Recovered.png
(I explain using image.)
There are featured products in the mini sidebar.
I don't want include the mini sidebar into right column. next to right column :)
I already made featured-products.phtml at /catalog/product/ folder.
And I created cms block, featured_products and I put in this code
{{block type="catalog/product_list" category_id="4" template="catalog/product/featured-products.phtml"}}
And I added code at page.xml like this.
<block type="core/text_list" name="content" as="content" translate="label">
<label>Main Content Area</label>
<block type="cms/block" name="featured_products">
<action method="setBlockId"><block_id>featured_products</block_id></action>
</block>
</block>
Then I added code in 2columns-right.phtml at /template/page/ folde.
like this,
<div class="wrapper">
<?php echo $this->getChildHtml('global_notices') ?>
<div class="page">
<?php echo $this->getChildHtml('header') ?>
<div class="main-container col2-right-layout">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div class="main">
<div class="col-main">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
<div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div>
</div>
</div>
<?php echo $this->getChildHtml('before_body_end') ?>
</div>
<?php //my slidebar ?>
<div style="float:right;width:92px;vertical-align:top;background-color:#000;margin:-766px 110px 0 0;">
<?php echo $this->getChildHtml('featured_products') ?>
</div>
But my sidebar is not showing.
How Can I Do???
Please let me know.
Thank you.
Also, try the following in 2-columns-right.phtml
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId(featured_products)->toHtml() ?>
No no no. Never edit the 2col-right, left or any other ./page/ template file for a modification such as this. You should also not be making changes in page.xml
What you need to do is understand layout handles on Magento. As your change relates specifically to catalogue, you should edit
catalog.xml
Then within that file, you can utilise the layout handle - which means, it appears, by default, everywhere.
<default>
<reference name="right">
<block type="catalog/product_list" template="catalog/product/featured-products.phtml" name="featuredprods" before="-">
<action method="setCategoryId"><category_id>4</category_id></action>
</block>
</reference>
</default>
There is no need for a phtml modification, or a CMS block or an edit of page.xml

Resources