Managing Magento Footer Content - magento

I have a portion of page in footer.phtml whose content I want to change on each new page, according to different categories. How can I get this done, or can I access product attribute outside of the product page? Is this possible?
regards

You can do this by defining your own block, though the specifics depend on more detail about the requirement. Define a block that will output the footer content you want whenever you are on a page with the current category defined:
$category = Mage::registry("current_category");
if($category) {
// write your output here
}
$product = Mage::registry("current_product");
if($product) {
// write your output here
}
Note that it is generally bad practice to have your global footer change based on each page. At that point, it isn't a global footer any longer.
Thanks,
Joe

Related

Adding an image in place of product in listing page

I am looking to add one image in place of a product on a category listing page - one image occupying all the space which would normally be taken up by the product image, name, price etc. on the listing page. I am able to add a static block no problem, but can't quite figure this out. Is this possible with Magento's native functionality?
You can achieve this by just using css property background-image. if you want to add image in whole content in listing page then it parent div use background-image, if you want to give image in each product block in listing page then also use css.
You can simply override the phtml template and in the loop where the products are being shown, check for the id/sku of the product, for which you want to put a custom image. Then simply echo your custom image and continue with the loop.
Pseudo Code:
foreach (products as product)
{
if(product->sku == 'YOUR_PRODUCT')
{
echo CUSTOM_IMAGE;
continue;
}
//LEAVE THE OTHER PARTS OF TEMPLATE AS IT IS
echo product->name;
echo product->image; // and others
}

Magento: Getting the category description in a layout file?

I have created my own template file for category pages (like 2columns-left.phtml for example). In that file I want to display the description of the category I am in at some other place. How can I get the current categories description? I know its included in
$this->getChildHtml('content')
But its hard to get it from there. Is there another way?
Thanks!
There's always
$category = Mage::registry('current_category');
if ($category) {
$category->getDescription();
}
Ideally this would be encapsulated in a proper PHP method rather than used directly in the template.

How to change the product display order in magento

How can I change the product display order in the front end (grid or list) by setting some preferences from back-end? I guess it should be other than best value and name from the default Magento display order property.
I tried by creating a new attribute called display_order, and each product holds a value based on its value the product needs to shown in front end. However, it is not working. Please help me fix this.
You'll need to extend the Mage_Catalog_Block_Product_List block to provide your own functionality for the getProductCollection() method. Probably something along the lines of:
class ... extends Mage_Catalog_Block_Product_List {
function getProductCollection() {
parent::getProductCollection()->addAttributeToSort('display_order', 'ASC')
}
}
Then, of course, you'll have to update you layout xml file on your, presumably, custom controller (unless you want all of the product listing screens to act like this) to use your new block instead of the Magento default of catalog/product_list.
Why don't you use the Magento sorting thing ?
In your category, under Category Product you have the possibility to choose the sorting order in the last column. To do it through php, just make a custom script that you'll need to launch once.
$collection = 'Your product collection';
$result = array();
foreach ($collection as $product) {
$sort = 'Your way of calculating the desired sorting';
$result[$product->getId()]=$sort;
}
Mage::getModel('catalog/category')->load('your category id')->setPostedProducts($result)->save();
And that's it :)
To change the display order , first you need to set the default sort by option to position.This can be done from the magento admin configuration.After that you need to set position for all the products starting with the value 1.
I come across the following module which will make this task very easy, just by drag and drop the products from the manage categories itself.Please check the following extension
http://www.blackqubers.com/extensions/product-sorting-drag-and-drop.html
Hope this will helps you

Magento: How to tell if you're on a category page, or product page in .phtml file(s)

I am trying to program into my .phtml files an if statement if the guest is on a category list page, or on a product page.
For example this code:
<?= Mage::app()->getFrontController()->getRequest()->getRouteName(); ?>
Returns "catalog" whenever l'm on a page other than a CMS page.
Is there a way l can use a similar method to know if the user is looking at a root category, sub category or an individual product page?
Any help would be greatly appreciated!
It's been a while since I've dealt with frontend catalog pages, but give this a try.
Current versions of Magento register certain global variables (not PHP globals, but things global to the Magento system) on certain pages.
Calling the following
$category = Mage::registry('current_category');
$product = Mage::registry('current_product');
$product = Mage::registry('product');
will either return null if the objects haven't been set (i.e. you're on a page without a category or a product), or return category and product objects.
If a product object is returned you're on a product page.
If no product object is returned but a category object is, you're on a category page. Category objects have a method to getting the parent id
$category->getParentId()
A category without a parent id should be a top level category, categories with parent ids should be sub-categories.
That should give you what you need to identify where the current request is.
UPDATE: Coming back to this almost a decade later -- I likely would not rely on the contents of the registry alone to determine the page I'm on. Instead I'd use the full action name in combination with looking for the above the objects.
While Alan's answer will work, there is a more direct option, and you were actually on the right track with your code snippet... you just need to inspect the controller name rather than the module name:
<?php Mage::app()->getFrontController()->getRequest()->getControllerName(); ?>
That will return category or product based on their controllers being CategoryController.php and ProductController.php respectively.
This does assume that you've not installed any third-party modules that rewrite those controllers with their own.
I am not a big fan of checking if the current_category registry exists, because basically any controller could do this and it wouldn't necessarily mean it's a category. My way of doing it is a bit more robust:
$fullActionName = Mage::app()->getFrontController()->getAction()->getFullActionName();
if ($fullActionName == 'catalog_category_view') {
... //Category
}
elseif ($fullActionName == 'catalog_product_view') {
... //Product
}
I am afraid you are trying to do it the wrong way. I might be wrong, because you have not explained what is it exactly that you want to achieve, but I would use the layout xml to include your block on a product page with a parameter (say product-page="1") and similiarly on a category page (category-page="1").
Then you would be able to tell if you are on a product page or category page by examining those parameters inside your block:
if($this->getProductPage()) {
//this is a product page, do some stuff
}
elseif($this->getCategoryPage()) {
//this is a category page, do some stuff
}
Differentiating between main and subcategory pages might be more difficult, the first thing that comes to mind is analysis of the request variables, but that is certainly not the best approach.

Magento: placing block on custom template

We are creating a custom page in which we are making something of a product wizard and the final step, we want to pull in the product page, really the catalog/product_view block. Obviously we can create the block and set it in the page with the renderview method but the problem we are having is its only that block and none of its children, and since the view.phtml pulls in a ton of getChildHtml blocks nothing works.
I am thinking there has to be a way to place the product view block with all of its children in a custom non product page. Without having to create every single child block and their child blocks, is there a way to programmatically pull in all the blocks that are in an xml file like the catalog_product_view handle in catalog.xml and place it on another page?
The page we are trying to put it on is a category page using a custom template where we are doing a lot of PHP in the template file to do the wizard.
Have you tried something like this?
//save the product in the registry so the block knows which product to display
$product = Mage::getModel('catalog/product')->load($productId);
Mage::register('product', $product);
//get the block from the layout and render it to html
$Block = Mage::getSingleton('core/layout');
$product_view = $Block->createBlock('catalog/product_view');
$product_view->setTemplate('catalog/product/view.phtml');
$product_view->toHtml();
I've had partial success with this code (part of the product view block is displayed and then I get an error). Hopefully it will point you in the right direction.

Resources