Tuesday, January 19, 2010

Display 'template hints' in 'default config'

Problem: Display 'template hints' and 'bloc hints' in 'default config'
Posible solution
If you want this option displayed for 'default config' also, just edit the app\code\core\Mage\Core\etc\system.xml file.
Look for something like this
<template_hints translate="label">
<label<Template Path Hints</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>20</sort_order>
<show_in_default>0</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</template_hints>
replace
<show_in_default>0</show_in_default>
with
<show_in_default>1</show_in_default>
and clear the cache
Do the same for this section

<template_hints_blocks translate="label">
<label>Add Block Names to Hints</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>21</sort_order>
<show_in_default>0</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</template_hints_blocks>
Be careful. When you enable these 2 from 'default config' you will also see template hints and block hints in the admin section.

Monday, January 18, 2010

Avoid empty meta-title for products (for biostall)

Problem: in case the meta-title is not filled in for a product the title should replace it

Possible solution:

Create a new method in the product model (Mage_Catalog_Model_Product) class called getMetaTitle();
function getMetaTitle(){
if (!$this->getData('meta_title')){
$this->setMetaTitle($this->getTitle());
}
return $this->getData('meta_title');
}

A list of all the products in the website (for travelingwilly)

Problem: a list of all the products in the website.

Possible solution:

The easiest (less code) solution is to create a category called 'All' an put all the products in that category(beside the category that they belong to).
The second method implies some code.
Create the Mage_Catalog_Block_Product_All class and put it in a file located here (app/code/code/Mage/Catalog/Block/Product/All.php)
<?php
class Mage_Catalog_Block_Product_All extends Mage_Catalog_Block_Product_List
{
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('status', 1)
->addAttributeToFilter(array(array('attribute'=>'visibility', 'eq'=>"4")));
$this->_productCollection = $collection;
}
return $this->_productCollection;
}
}
?>

After this create a CMS page. and in it's content put the following
{{block type="catalog/product_all" template="catalog/product/list.phtml"}}
In the "Layout" field (from the 'Custom design' tab) select '2columns-left' (or any other design just don't leave it to 'empty')
Save and that's it.
If the page you just created has the identifier ('all-products') and is enabled you will see a paginated list of all your products here:
http://www.yoursite/all-products (or http://www.yoursite/{YOUR STORE CODE}/all-products if you have store codes in the url)

I know that this is not 100% clean because you need to add some code in the core. This is no problem, you can add this also in the local folder.

EDIT: I forgot to close a curly bracket at the end of the class. Thanks To John (see who John is the comments below) I fixed it.

Display CMS Blocks on product description (for Mattse)

Problem: add static block to product description

possible solution

You can add a new method to the product model.
function getDescription(){
$processor = Mage::getModel('core/email_template_filter');
$html = $processor->filter($this->getData('description'));
return $html;
}

In this way you can use the same {{block}} and {{skin}} sections just like the static blocks and pages and e-mail templates.

Wednesday, January 13, 2010

how to display number of items in cart and cart total (for elmuchoprez)

Problem: how to display number of items in cart and cart total?
Possible solution

To display items in cart do this:
$this->helper('checkout/cart')->getSummaryCount();
or
Mage::helper('checkout/cart')->getSummaryCount();
And for the total:
Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();
This will display only the total amount for the products.
If you want the grand total (including shipping & handling) do this:
Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal();

Tuesday, January 5, 2010

Show customer group in order e-mail (for redbeetstudio)

Problem: Show customer group in order e-mail.
http://www.magentocommerce.com/boards/viewthread/71736/

Possible solution
In order for this to work in the e-mail template:
{{var order.getCustomerGroupName()}}
you have to create a method in the Order model (overwrite it or edit the core at your own risk).
function getCustomerGroupName(){
$group = Mage::getModel('customer/customer_group')->load($this->getCustomerGroupId());
if ($group->getId()){
return $group->getName();
}
return '';//or any default value if the customer is not in a group or is a guest
}