<?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><span><?php echo $this->escapeHtml($title); ?></span></h2>
<?php endif;?>
<?php echo $html; ?>
</div>
<?php endforeach;?>
<?php echo $this->getChildHtml('product_additional_data') ?>
what's those line meaning in magento?
foreach over each child (that is grouped by name detailed_info with method getchildhtml) and output the data from those blocks
get the html of product_additional_data block
This is the snippet of code from the catalog/product/view.phtml that displays Description, Custom Options, and other detailed product information in the front end view.
Related
I have a custom attribute for products in which I add a video URL.
I made this Embed video responsive using css.
Now I want to call the custom attribute on the product page, so it shows the video.
The file responsible for this is: description.phtml
I've tried the following:
?>
<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
<h2><?php echo $this->__('Details') ?></h2>
<div class="std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
</div>
<div class="std">
<?php echo $_product->getAttributeText('video') ?>
</div>
<?php endif; ?>
But I get the error:
Fatal error: Call to a member function getAttributeText() on a non-object in /data/web/public/app/design/frontend/base/default/template/catalog/product/view/description.phtml on line 40
The video does show however. I'm probably doing this all wrong. Can I fix this with a simple edit of the code, or do I have to use an entirely different approach?
Thanks.
<?php echo $this->getProduct()->getAttributeText('video'); ?>
Try this. Or on top of document add this
<?php $_product = $this->getProduct(); ?>
I have custom links in menu that shows categories in drop-down.
For that I made a file in catalog/navigation->mainmenu.phtml
(a custom file)
Now, I want to show categories after sorting it by name. please help me how can I sort collection of categories by name. I already set order of category in admin. But in front-end it show unsorted.
Code is:-
<?php $defaultcategory= Mage::app()->getStore()->getRootCategoryId();?>
<?php $mainchildren = Mage::getModel('catalog/category')->getCategories($defaultcategory);?>
<ul>
<?php foreach ($mainchildren as $subcategory) : ?> <?php // 2 level ?>
<?php if($subcategory->getIsActive()):?>
<li id="show_subcat" class="<?php if($i==1): echo 'first'; endif; ?>" >
<?php $childid=$subcategory->getId();?>
<?php $subchild = Mage::getModel('catalog/category')->getCategories($childid);?>
<?php foreach ($subchild as $subchildcategory) : ?>
<?php $path=$subchildcategory->getRequestPath()?>
<?php break;?>
<?php endforeach ?>
<a href="<?php echo $this->getUrl().$path; ?>">
<?php echo $name= $subcategory->getName().$subcategory->getEnable() ?>
</a>
</li>
<?php endif;?>
<?php endforeach; ?>
</ul>
You can try :
children = Mage::getModel('catalog/category')->getCategories($defaultcategory)
->addAttributeToSort('name', 'ASC');
or :
children = Mage::getModel('catalog/category')->getCategories($defaultcategory)
->setOrder('name','ASC);
$categories = Mage::helper('catalog/category');
$collection = $categories->getStoreCategories(false,true,false);
foreach($collection as $_category)
{
//Do something
echo $_category->getName();
}
use this code to get collection and follow this link for more detailIn magento - same code for getting all categories running well with sorted in localhost but not in web server
I'm using the AheadWorks blog extension for Magento, and my blog pages are working fine. But I want excerpts of my latest posts from certain categories to appear on my home page. I've successfully setup everything thus far by adding:
<block type="blog/blog" name="blog.latest" template="aw_blog/blog-home.phtml" />
to "layout.xml", by adding:
<?php echo $this->getChildHtml('blog.latest') ?>
to my home page's phtml file, and by creating "template/aw_blog/blog-home.phtml".
The problem is that I can't figure out how to limit what categories are shown. For example, you'll see in my "blog-home.phtml" file below that I'm trying to limit the posts to the "news" category. I've tried lots of solutions from other forums, but no matter what I do, I see posts from every category. Does anyone know what I need to add/take away from my code to limit the categories?
<?php $posts = $this->getPosts("news"); ?>
<div id="messages_product_view">
<?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?>
<?php echo Mage::app()->getLayout()->getMessagesBlock()->getGroupedHtml(); ?>
</div>
<?php $numberOfPosts = 1 ?>
<?php $renderedPosts = 0 ?>
<?php foreach ($posts as $post): ?>
<div class="postWrapper">
<div class="postTitle">
<h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>
</div>
<div class="postContent"><?php echo $post->getPostContent(); ?></div>
<?php echo $this->getBookmarkHtml($post) ?>
<div class="tags"><?php echo $this->getTagsHtml($post) ?></div>
<div class="postDetails">
<?php if ($this->getCommentsEnabled()): ?>
<?php echo $post->getCommentCount(); ?> <a href="<?php echo $post->getAddress(); ?>#commentBox" >Comments</a> |
<?php endif; ?>
<?php $postCats = $post->getCats(); ?>
<?php echo "<h1>" . $postCats[2] . "</h1>"; ?>
<?php if (!empty($postCats)): ?>
<?php echo Mage::helper('blog')->__('Posted in'); ?>
<?php foreach ($postCats as $data): ?>
<?php echo $data['title']; ?>
<?php endforeach; ?>
<?php else: ?>
<?php endif; ?></div>
<?php $renderedPosts ++ ?>
<?php if ($renderedPosts = $numberOfPosts) {
break;
}
?>
</div>
<?php endforeach; ?>
<?php //$this->getPages(); ?>
Following is the quick solution:
Go to aw_blog frontend template, default might be this app/design/frontend/base/default/template/aw_blog/menu.phtml
check and replace:
if ($posts = $this->getRecent():
with
$currentBlogCat = Mage::getSingleton('blog/cat');
if ($posts = $this->getRecent($currentBlogCat['cat_id'])):
Now open up /app/code/community/AW/Blog/Block/Menu/Sidebar.php
check for the below function:
public function getRecent()
add a parameters to it:
public function getRecent($currentCat=false)
Also, replace the following code block
$collection = clone self::$_collection;
if (array_key_exists('categories',$data = $this->getData();) && count(explode(',', $data['categories'])) == 1) {
with
$collection = clone self::$_collection;
$data = $this->getData();
if($currentCat>0)$data['categories']=$currentCat;
# Category fix #
if (array_key_exists('categories',$data ) && count(explode(',', $data['categories'])) == 1) {
Thanks!
the getProductCount() in the second level of category echo count print out 0, i try different way but i diddn't figure out like mage get collection etc, i didn'd find any solution at this question
<?php
$_category = $this->getCurrentCategory();
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$helper = Mage::helper('catalog/category');
?>
<?php foreach ($collection as $cat):?>
<?php
$cur_category = Mage::getModel('catalog/category')->load($cat->getId());
$_img = $cur_category->getThumbnailUrl();
?>
<div class="grid_4">
<div class="mineContent_grid_4">
<dl>
<dt>
<a href="<?php echo $helper->getCategoryUrl($cat);?>">
<?php echo $cat->getName();?>
<img src="<?php echo $_img?>" title="<?php echo $cat->getName();?>" width="173" height="208"/>
</a>
</dt>
<?php $childLevel2Category = Mage::getModel('catalog/category')->getCategories($cat->entity_id);
?>
<dd>
<ol>
<?php foreach ($childLevel2Category as $catLevel2) { ?>
<?php
$cur_category2 = Mage::getModel('catalog/category')->load($cat->getId());
$count = $cur_category2->getProductCount();
?>
<li> <?php echo $catLevel2->getName();?> <span>(<?php echo $count ?>)</span></li>
<?php } ?>
</ol>
</dd>
</dl>
</div>
</div>
<?php endforeach;?>
You have this code:
<?php
$cur_category2 = Mage::getModel('catalog/category')->load($cat->getId());
$count = $cur_category2->getProductCount();
?>
This loads $cur_category2 with $cat->getId(), which is your parent category and not the current category. I think you want this:
<?php
$cur_category2 = Mage::getModel('catalog/category')->load($catLevel2->getId());
$count = $cur_category2->getProductCount();
?>
Here's a snippet that should help you. All my snippet does is get the product count for the category. I hard coded a category ID of 4, but your code should work, getting the current category. You may want to isolate this code into a function to keep it simpler, then just reference it from your existing page. It essentially loads a collection of products, by category, filtering out products that aren't visible.
$_category = Mage::getModel('catalog/category')->load(4);
$collection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($_category);
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
echo $collection->count();
try this example
$categories = Mage::getModel('catalog/category')->load(2)->getChildrenCategories();
$productCollection = Mage::getResourceModel('catalog/product_collection');
$productCollection->addCountToCategories($categories);
var_dump($categories);
where 2 - category id
also check php class Mage_Catalog_Block_Navigation in Magento
Just wondering if anyone has any idea how to show comments on the customers printable order - http://www.mydomain.com/sales/order/print/order_id/48/
I can see the file that I need to edit is “/public_html/app/design/frontend/default/mytemplate/template/sales/order/print.phtml” but am unsure what code I need to add to display the comments.
FYI: We are using this extension to make the order comments box show up on the order page - http://www.magentocommerce.com/magento-connect/catalog/product/view/id/10860/. The order comments are successfully displayed on the order email but we need them be be displayed on the customers order pages as well.
Thanks for your help in advance :)
+1 for code_break, who answered this nicely. Here's my own version for completeness:
$orders = Mage::getModel('sales/order')
->getCollection()
->addFieldToFilter('status',array('pending','processing'));
foreach ($orders as $order) {
$orderComments = $order->getAllStatusHistory();
foreach ($orderComments as $comment) {
$body = $comment->getData('comment');
if (strpos(strtolower($body),'some text') !== false) {
// do something cool here...
}
}
}
Use as you wish. Hope it helps.
The last post used the getVisibleStatusHistory method of the order object, but the first comment entered on an order is never visible. There are several methods for grabbing the status history and setting it in the order object.
That being said we might want to list all of the comments that are marked as visible on front-ed and the first comment entered when the order is created. I've substitued your formatting with a <p> tag.
<?php $_history = $order->getAllStatusHistory(); ?>
<?php $_buffer = array(); ?>
<?php $_i=1; ?>
<?php foreach ($_history as $_historyItem): ?>
<?php // Ignore the visibility for the first comment ?>
<?php if ( $_historyItem->getData('is_visible_on_front') == 1 || $_i == count($_history) ): ?>
<?php $_buffer[] = $_historyItem->getData('comment'); ?>
<?php endif; ?>
<?php $_i++; ?>
<?php endforeach; ?>
<?php if ( count($_buffer) > 0 ): ?>
<p><?php echo implode( $_buffer, '</p><p>' ); ?></p>
<?php endif ?>
As you are asking especially for the oder comment from MageMaven OrderComment this would be the easiest solution:
<p><?php echo nl2br($_order->getCustomerNote()); ?></p>
Hey try adding this code I havent tested it but i have a feeling it will work for you:
<?php $_history = $_order->getVisibleStatusHistory() ?>
<?php if (count($_history)): ?>
<div class="order-additional order-comments">
<dl class="order-about">
<?php foreach ($_history as $_historyItem): ?>
<dd>
<span class='lowcase'><?php echo $_historyItem->getComment()?></span>
</dd>
<?php endforeach; ?>
</dl>
</div>
<?php endif?>