Hide certain Magento attribute filters - magento

I have some lines of PHP code that will prevent certain attribute filters to be shown within the layered navigation block (i.e. Price and Category). This way I need to add all the filters that I don't want to be shown by hand which takes a lot of time and isn't the best solution.
What I want is the filter attributes "Price" and "Category" to be shown and if the filtername is different, don't display that filter at all. This way the price and category filters are always displayed, and the other filters get hidden. I don't have to add all the filters by hand which I do not want to show up in the list.
My question is, what needs to change within the PHP code to make it work the way I just described?
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>
<?php if($_filter->getName() != "Price" AND $_filter->getName() != "Category"): ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>

Ah I see. Funnily enough I was working on something virtually identical yesterday and this works for me (I mean to the change to the IF statement);
<?php foreach ($_filters as $_filter): ?>
<?php if (Mage::helper('catalog')->__($_filter->getName()) == 'Price' || Mage::helper('catalog')->__($_filter->getName()) == 'Category'): ?>
<dt><?php echo Mage::helper('catalog')->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
<?php endforeach; ?>
Hopefully it will work for you too.

Related

In Magento: get static block if product has specific attribute

I am trying to call the cms block preorder_note IF the product has a value (doesn' matter what value) for the attribute preorder_note. But i cannot get it to work.
This is done on page template/catalog/product/view.phtml
<?php if ($_product->getAttribute('preorder_note')): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('preoder_short')->toHtml() ?>
<?php endif; ?>
What am I doing wrong?
I found the solution myself.
<?php $_howtouse = $this->getProduct()->getPreorder_note(); ?>
<?php if ($_howtouse): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('preoder_short')->toHtml() ?>
<?php endif; ?>

Remove attribute from layered filter based on parent category

On my magento site, each product sits in two parent categories. Basically, each product is in both "Shop by Product" and "Shop by Device", and then of course there are child categories in side of those. For example, case for a tablet will appear in Shop by Device > iPad, as well as Shop by Product > Tablet Cases.
Each product also has an attribute for "compatibility" and "product type." I would like to remove the "compatibility" filter from layered filters on the catalog page when shopping under "Shop by Device," and remove the "product type" filter when shopping under "Shop by Product"
Any suggestions?
put the code in start of layer.phtml in catalog/layer/view.phtml
$yes=0;
if(Mage::registry('current_catgeory')){
if(Mage::registry('current_catgeory')->getParentId()==$catid):
$yes=1
endif;
}
then filter showing position add
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
<?php endforeach; ?>
change
<?php foreach ($_filters as $_filter): ?>
if($yes==1 && $_filter->getName()==$Attributelabel){
//hide
}
else{
<?php if($_filter->getItemsCount()): ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
}
<?php endforeach; ?>

Magento product custom options to be positioned below the price

I would like my Magento product custom options to be positioned below the price. I tried moving the blocks in catalog.xml file but nothing worked.
I did flush all cache every time.
This can be done from within the manage product section in admin. Under design, set "Display Product Options In" > "Product Info Column"
This function can be found in
/app/design/frontend/your_package/your_theme/template/catalog/product/view.phtml
or, if it's not there, look in
/app/design/frontend/your_package/default/template/catalog/product/view.phtml
If the file is not present, then create it by copying from
/app/design/frontend/base/default/template/catalog/product/view.phtml
or, if you are on the Enterprise Edition, from:
/app/design/frontend/enterprise/default/template/catalog/product/view.phtml
Remember not to touch anything in the /app/design/frontend/enterprise/default/
The code responsible for showing prices is:
<?php echo $this->getChildHtml('tierprices') ?>
You have to move the code responsible for showing the options, that looks like this:
<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
</div>
<?php else:?>
<?php if ($_product->isSaleable() && $this->hasOptions() && $this->getChildChildHtml('container1') ):?>
<div class="options-container-small">
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
</div>
<?php else: ?>
<?php echo $this->getChildHtml('addto') ?>
<?php endif;?>
<?php endif; ?>
directly below the code that's responsible for prices. Remember that the code above is an example, it may look different in your template, so don't copy-paste it.
Anyway, the file responsible for showing prices is usually /app/design/frontend/your_package/your_theme/template/catalog/product/view/tierprices.phtml (with the same fallbacks as usual), but you shouldn't modify it in your case.
You can change them by edit template (.phtml) file:
app/design/frontend/{default}/{default}/catalog/product/view.phtml
Modify the template Or ovverride it in your theme !
/app/design/frontend/base/default/template/catalog/product/view.phtml
This is where the price is :
<?php echo $this->getTierPriceHtml() ?>
This means customer options showing between this if (){}
<?php if (!$this->hasOptions()):?>
So you can move them as you like in the template file ! or you can style them with CSS to put them at custom position !

what's those line meaning in magento?

<?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.

Magento - Display Attribute Admin Title

How do I modify the following code block so that it will display ‘Plant Genus’ instead of the text ‘[hide]’
The relevant code is at:
\app\design\frontend\enterprise\style\template\catalog\layer\view.phtml
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
<?php endforeach; ?>
Here is the attribute from the admin panel:
#Lucasnus - I dont think this is in the front end, but he has placed the attribute for us to see in a screen shot, the code he quoted is from the front end view.
However I think you are quite close to a solution, since this looks like a store attribute visibility issue.
In the admin panel if you change to the "Garden Store" scope, can you try to then change the attribute value to "Plant Genus" ?
If that does not work, maybe try the Main Website scope.
Do you have this problem with other products attributes?

Resources