Best way for creating dynamic sidebar section in Symfony 1.4 - view

I have few frontend modules which has own sidebar menu link. I want to create those links in actions class of module:
public function preExecute()
{
$items['plan/new'] = 'Create Plan';
$items['plan/index'] = 'Plans Listing';
$this->getResponse()->setSlot('sidebar', $items);
}
Slot file sidebar.php
#apps/frontend/templates/sidebar.php
<?php slot('sidebar') ?>
<ul>
<?php foreach($items as $url => $title) : ?>
<li><?php echo link_to($url, $title) ?></li>
<?php endforeach ?>
</ul>
<?php end_slot() ?>
layout.php:
<?php if (has_slot('sidebar')): ?>
<div id="sidebar"><?php include_slot('sidebar') ?></div>
<?php endif ?>
but my output is Array, how can I render my slot?

You seem to be mixing slots and partials. In your action, you set your slot to an array, later you call include_slot, and the string representation is Array, that is correct.
You should pass items via $this->items = $items, then in your action see if isset($items) is true, and call include_partial("sidebar", array("items" => $items)) if neccesary. This will look for a file called _sidebar.php.
For more detailed information of how this stuff works, read the Inside the View Layer: Code fragments part of the sf1.4 book.

Related

Show Joomla article tags in override of newsflash module

We would like to create an override for the Joomla newsflash module which should be able to display the individual Joomla article tags on the frontend:
"tag 1, tag 2, tag 3 etc.."
RokSproket from rockettheme.com is able to achieve exactly that output. But we would like to have the same result with the newsflash module. We currently have the following code saved in our new _item.php override. There is no error message on the frontend but also no tags are visible. Any help is much appreciated.
<?php if ($params->get('show_tags', 1) && !empty($item->tags)) : ?>
<?php $item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $item->tagLayout->render($item->tags->itemTags); ?>
<?php endif; ?>
Here's how we've solved that question:
<?php
$itemtags = (new JHelperTags)->getItemTags('com_content.article', $item->id);
$taglayout = new JLayoutFile('joomla.content.tags');
$tags='';
if( !empty($itemtags) )
$tags = '<div class="itemtags">'.str_replace(',','',$taglayout->render($itemtags)).'</div>';
?>
<?php echo $tags; ?>

what is the difference between the functions getAddUrl and getAddToCartUrl?

I have found two function returning the exactly same value.
getAddUrl in \app\code\local\Mage\Checkout\Helper\Cart.php
getAddToCartUrl in \app\code\local\Mage\Catalog\Block\Product\Abstract.php
what is really the difference between these two?as I am adding an add to cart button in my block.
Which function should I use?
Consider the example below
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><?php echo $this->__('Add to Wishlist') ?></li>
<?php endif; ?>
<?php if($_cartUrl=$this->getAddToCartUrl($_product)): ?>
<li><span class="separator">|</span> <?php echo $this->__('Add to Cart') ?></li>
<?php endif; ?>
getAddUrl can fetch you URL of the helper you associate it with, eg: wishlist, compare, etc.
but getAddToCartUrl will only get you the add to cart URL for the product passed to it.
I hope it clarifies things for you
Does your block inherit the Mage_Catalog_Block_Product_Abstract class? If so you should use the getAddToCartUrl method of the block.
Otherwise you should use the helper, there is no neat way of calling a block method without creating the block in this case a product block.
The difference between these two functions is that the getAddToCartUrl (Mage_Catalog_Block_Product_Abstract) will return product view page URL if product has required options.
And getAddUrl (Mage_Checkout_Helper_Cart) will always return url for add product to cart.

Subcategory list with Magento Flat Catalog

I'm using the code below to get a list of categories on the same level as the current page (by listing the subcategories of this category's parent). It works great when Flat Categories are off. Once I enable Flat Categories, the H2 works correctly, but the list changes to display the root's subcategories instead of this page's parent's subcategories. What am I doing wrong, and why does it act this way?
<?php
$_category = $this->getCurrentCategory();
$parentCategoryId = $_category->getParentId();
$collection = Mage::getModel('catalog/category')->getCategories($parentCategoryId);
$helper = Mage::helper('catalog/category');
$parentCategory = Mage::getModel('catalog/category')->load($parentCategoryId);
?>
<h2><?php echo $parentCategory->getName(); ?></h2>
<ul>
<?php foreach ($collection as $cat):?>
<?php if($_category->getIsActive()): ?>
<li <?php
if ($cat->getId() == $_category->getId()) {
echo 'class="current"';
}
?>>
<?php echo $cat->getName();?>
</li>
<?php endif; ?>
<?php endforeach;?>
</ul>
Yes, I've flushed the cache and indexes.
I don't completely know why ->getCategories($id) is not "flat-safe", but using Stefan's suggestion helped me find an alternate method for this instead.
My new lines at top look like this:
$_category = $this->getCurrentCategory();
$parentCategoryId = $_category->getParentId();
$helper = Mage::helper('catalog/category');
$parentCategory = Mage::getModel('catalog/category')->load($parentCategoryId);
$collection = $parentCategory->getChildrenCategories();
... which works regardless of 'flat catalog' on or off.

Magento - Unable to display custom options

I'm using a module for displaying grouped configurable products and all options are showing except custom options. They are displaying on the configurable product page but that's it. I'm trying to use the code in app\design\frontend\blank\blank\template\catalog\product\view\options.phtml in my custom configurable.phtml but $_options is showing up null. Here is the code used to retrieve $_options
<?php $_options = Mage::helper('core')->decorateArray($this->getOptions()) ?>
<?php if (count($_options)):?>
and after the javascript
<?php foreach($_options as $_option): ?>
<?php echo $this->getOptionHtml($_option) ?>
<?php endforeach; ?>
</dl>
<?php else: echo dlkghflghf;?>
<?php endif; ?>
The dlkghflghf is displaying so i know $_options is not showing up. Any suggestions?
Your custom configurable.phtml is a template of what block? You can use a block that extends Mage_Catalog_Block_Product_View_Options or you can set your own method for options like the method from Mage_Catalog_Block_Product_View_Options, you also need to have a method getProduct():
public function getOptions()
{
return $this->getProduct()->getOptions();
}

MAGENTO getting the descriptions from a sub category

Hi I'm new to magento and have been trying to set up a static block that displays a list of sub categories within a category. I've been succesfull a grabbing the sub-category images and names, but for some reason I can't seem to get the descriptions to show.
Here's the code can't anyone explain why it won't work and how I can fix it?
I've commented out a few lines because I was trying different things to get it to work.
helper('catalog/output');
$category = $this->getCurrentCategory();
getCurrentChildCategories();
?>
<?php foreach ($_categories as $_category): ?> <?php echo
$this->htmlEscape($_category->getCategoryDescription());?>
<?php if($_category->getIsActive()): ?>
<div class="subcategory-image">
<a href="<?php echo $_category->getURL()
?>" title="htmlEscape($_category->getName())
?>">
</a>
<?php /* echo "Find this item->" */ ?>
</div> <div class="sub-category-container">
<h2><a href="<?php echo $_category->getURL()
?>" title="htmlEscape($_category->getName())
?>">htmlEscape($_category->getName())
?>
getURL() ?>"
class="moreLink">[MORE...]
getDescription() ?>-->
getDescription()):
?>
categoryAttribute($_category, $_description, 'description'); ?>
-->
This is one of those cases where Varien decided that they should call "load" on the data collection before returning it when that really isn't necessary and makes the utility function utterly useless.. If you trace the code down for Mage_Catalog_Block_Navigation->getChildrenCategories() you will eventually find this in Mage_Catalog_Model_Resource_Eav_Mysql4_Category:
public function getChildrenCategories($category)
{
$collection = $category->getCollection();
/* #var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
$collection->addAttributeToSelect('url_key')
->addAttributeToSelect('name')
->addAttributeToSelect('all_children')
->addAttributeToSelect('is_anchor')
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren())
->setOrder('position', 'ASC')
->joinUrlRewrite()
->load();
return $collection;
}
The next to last line ->load(); means that the query is executed and the collection is loaded so it is too late to modify the query. So what you will want to do is copy and paste that in place of calling getChildrenCategories and then add the additional attributes you want to use like so:
$_categories = $category->getCollection()
->addAttributeToSelect(
array('url_key','name','all_children','is_anchor','description')
)
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren())
->setOrder('position', 'ASC')
->joinUrlRewrite()
;
Now the collection will include the description attribute so that getDescription() will work. Notice that you do not need to call load(), it happens automatically when you start using the iterator (the foreach loop triggers this). This is why it is pointless for the load() call to be included in that function because otherwise you could have just added one line below the function call:
$categories->addAttributeToSelect('description');
But instead you have to copy the contents of the function to tweak the query.
Change:
$_category->getCategoryDescription()
To this:
$_category->getDescription()

Resources