Magento 1.9 vertical menu issue - magento

i've stumbled on a relatively known issue, but i cant find the solution.
I am using magento 1.9 CE
I have found some code to show a vertical menu of the current categorie with its children, and on the homepage the root category and everything works fine except 1 little detail. The subcategories don't load in the order of the backend. It's important that the same order as how it is setup in teh backend loads. I have tried allot of variations, like getCChildrenCategories but then it results in a blnak page. I also found menu's that do work, but then when i visit the homepage, i get an error and the page turns blank.
This is the code i am using at the moment.
<section class="block-layered-nav custom-left-menu" role="navigation">
<div class="block-content">
<?php
echo "<dl id='narrow-by-list2'>";
$_category = $this->getCurrentCategory();
$subcatid = $_category->getId();
$parentCategory = Mage::getBlockSingleton('catalog/navigation')->getCurrentCategory()->parent_id;
$name = $_category->getName();
$root_category = Mage::getModel('catalog/category')->load($subcatid);
$subcategories = $root_category->getChildren();
if($subcategories != "")
{
echo "<span class='h3'>Categorie</span><ol>";
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
echo '<li><a href="'.$category->getURL() .'" title="'.$category->getName().'" />'.$category->getName().'</a></li>';
}
}
else
{
echo "<span class='h3'>Categorie</span><ol>";
$root_category = Mage::getModel('catalog/category')->load($parentCategory);
$subcategories = $root_category->getChildren();
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
echo '<li><a href="'.$category->getURL() .'" title="'.$category->getName().'" />'.$category->getName().'</a>';
}
}
echo "</ol>";
?>
</div>
</section>
Any help would be much appreciated. All i know is that, somewhere in this code its not calling the categories the right way, i also tried:
$currentCat = Mage::registry('current_category');
but this results in a blank homepage.
Here is a link to the dev enviremont: http://dev.smoldersbv.nl/schroeven-en-bouten.html
If you hover over the main navigation you see a different order, the correct order, then on the left menu.

This is normal $this->getCurrentCategory() get the current category = the category you are currently browsing.
On the home page you are not in a category, like on any other cms pages or even on the contact us page, ... (and there are lots more). So you have nothing in the current category which is obvious.

Problem solved,
The way of the requests where wrong therefor this menu is unable to produce the order of the backend so i ended up using a whole different mockup.
thnx for looking anyway.

Related

Magento Active Filters on Search Page

I want to implement active filters on my magento ecommerce site.
I have been successful in implementing it, but the issue is, the code works on only category pages and not search page
Here's the code that I'm using
<?php /*Create filter dependencies*/
$_activeFilters[] = array();
$_filters = Mage::getSingleton(‘Mage_Catalog_Block_Layer_State’)->getActiveFilters();
foreach ($_filters as $_filter):?>
<?php echo $this->stripTags($_filter->getLabel()) ?><a href=”<?php echo $_filter- >getRemoveUrl() ?>” title=”<?php echo $this->__(‘Remove This Item’) ?>”><?php echo $this->__(‘Remove This Item’) ?></a>
<?php endforeach; ?>
I'm using this code in toolbar.phtml. Any clue as in why its not working on search page. Any Solutions would be of great help.
Thanks,
Sushil
You can use this code for fetching filters on either category list page or search results page
<?php
if(Mage::registry('current_category')) {
$_filters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
} else {
$_filters = Mage::getSingleton('catalogsearch/layer')->getState()->getFilters();
}
?>
I have used this code in toolbar.phtml, to show removable filters below the toolbar, like flipkart does.
The problem is with this line:
$_filters = Mage::getSingleton(‘Mage_Catalog_Block_Layer_State’)->getActiveFilters();
This gets a singleton which only contains the necessary data when on a category page.
See this question for more details: Magento - How to add Layered Navigation to Advanced Search?

Magento: Category Lock/Warning or T&C

I wonder if there is a way to add a Warning/Advisory or Terms & Conditions (preferably) to a category or a landing page to warn users about adult content. On the shop I'm working on there is an "Adult Section" Category for Erotic Toys, Lingerie, cosplay, etc. and I need to warn users about such content before they access the section in case they're less than 18.
I've searched the web and only found paid extensions which I cannot afford. Does anyone know how to do this?
I'm using Magento CE 1.7.
Thanks,
EDIT:
Ok, so I've been trying to figure out how to do this and I just figured that the best way to do it would be to just create a Category Landing Page and adding a java script for T&C redirect to the page I want it to.
This is the code I would use for the Category Landing Page with blank content would be this.
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_collectionSize = $_categories->count() ?>
<div>
<?php $i=0; foreach ($_categories as $_category): ?>
<?php
$layer = Mage::getSingleton(‘catalog/layer’);
$layer->setCurrentCategory(Mage::getModel(‘catalog/category’)->load($_category->getId()));
$helper = Mage::helper(‘catalog/category’);
?>
Then I found a code snippet that would redirect the user to a page of my liking after clicking accept but I'm not sure how to implement it and/or if this is the best choice. Here's the code.
<form action="url-to-go-to" method="GET" onsubmit="return checkCheckBox(this)">
I accept: <input type="checkbox" value="0" name="agree">
<input type="submit" value="Continue">
<input type="button" value="Exit" onclick="document.location.href='BACKTOWHAT.html';">
</form>
<script type="text/javascript">
<!--
function checkCheckBox(f){
if (f.agree.checked == false )
{
alert("Please tick the box to continue");
return false;
} else
return true;
}
-->
</script>
Now I was thinking that it would be best to just create a simple CMS page and point the category on the top menu to that page and once they have agreed and clicked on continue, they could be taken to the actual category by simply pointing the 'onclick' to the URL of the actual category.
Not sure if this is the best way but it's the only way I could come up. The other way I thought of would've required me to take the "agreements" during checkout that already comes with magento and make an extension that would allow me to place it on any page and call the "Agreement ID" from the Sales/Terms and Conditions tab but I don't know how to actually do that, it was just a thought.
If anyone has a better solution, I'd be happy to hear it.
I would add some sort of JavaScript that shows a div over the top of the whole page, that will create a session cookie when you accept to watch the category. Otherwise, make a back() in the history navigation. This way you don't need another page, just JS.
On another note, could you please post the extensions you found that do this?

magento tracking pixel

There are two variables which are required in the tracking pixel which needs to be placed on category, product info, cart and confirmation page.
I've managed to get the Prod list and Prod working, however, the second two are causing me problems.
I can echo out the sku in the cart, however, the products are configurable products so it's duplicating the sku in the output. The code I'm using is below:
<?php
// $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();foreach($items as $item) { echo ''.$item->getSku().' ';}
?>
How do i change this to just display the one configurable SKU?
The second element is the Category name that the product exists in, Any one got any ideas on that? I've tried multiple variations but they've either broke the page or returned nothing.
Any help would be appreciated. If someone could also give me examples of how these would work on the confirmation page as well, that would be great.
Thanks for your help.
Check for the products visibility (simple products attached to a configurable would not be visible):
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($items as $item) {
if ($item->getProduct()->isVisibleInSiteVisibility()) {
echo ''.$item->getSku().' ';
}
}
With regards to the category name, a product can appear in multiple categories so im not sure how you want to handle that. Also, there is a concern that you are beginning to duplicate code across several template files. You will want to consider moving this all out to a block.
Anyway, to get the category names that the product belongs to here is at least one method of doing this...
$categoryCollection = $item->getProduct()->getCategoryCollection()
->addAttributeToSelect('name');
foreach($categoryCollection as $category) {
echo $category->getData('name') . "<br/>";
}

how not to show category name in magento breadcrumb?

I am working with a magento website. I have used a featured category to display homepage slider products. So when I click on the product it shows featured as a category in the breadcrumb.
Would it be possible not to show featured in the breadcrumb ? I want category name in the breadcrumb for the rest of categories .
Thanks
Ab
actually not getting your question but you can get some idea from here:
in page/html/breadcrumb.phtml file near line 34-36 change, $_crumbInfo['label'] to $_crumbInfo['title']
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['title']) ?></strong>
then in catalog/block/breadcrumb.php add 2 lines after
$path = Mage::helper('catalog')->getBreadcrumbPath();
$currentCategory = Mage::registry('current_category');
$metaname = $currentCategory['name'];
and change foreach loop like
foreach ($path as $name => $breadcrumb) {
$breadcrumb['title'] = $metaname;
$breadcrumbsBlock->addCrumb($name, $breadcrumb);
$title[] = $breadcrumb['label'];
}
and check it,
hope you get some idea..
Why no simpler than that?
Try to use CSS. Your category will have an automatic and specific class for it. For example:
<li class="category4">
<strong>ARCHERY HUNTING</strong>
</li>
In this piece of code, I have a category that I created, called "Archery hunting". The code auto-created the class="category4", So, only write on your CSS:
.category4 strong { display: none; }
And it will hide only that category.
Instead of using
$_product->getProductUrl()
to fetch URL, use this:
$_product->unsRequestPath()->getUrlInStore(array('_ignore_category' => true))
Then you need to unset last visited category id at the end of your featured block:
Mage::getSingleton('catalog/session')->setLastVisitedCategoryId('');
This is all because key part for forming breadcrumbs is the following code:
$categoryId = $params->getCategoryId();
if (!$categoryId && ($categoryId !== false)) {
$lastId = Mage::getSingleton('catalog/session')->getLastVisitedCategoryId();
if ($product->canBeShowInCategory($lastId)) {
$categoryId = $lastId;
}
}
basically, current category is determined by either URL params (hence the modified URL call), or through the session object (hence the removal of last visited category id)
so, to recapitulate, in your Featured block, instead of regular productUrl call, use the one I provided, and at the end of your featured product block listing, remove the lastVisitedCategoryId using the code I gave you

Retrieve product custom media image label in magento

I have a custom block loading products on my front page that loads the four newest products that have a custom product picture attribute set via:
$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getModel("catalog/product")->getCollection();
$_productCollection->addAttributeToSelect('*');
$_productCollection->addAttributeToFilter("image_feature_front_right", array("notnull" => 1));
$_productCollection->addAttributeToFilter("image_feature_front_right", array("neq" => 'no_selection'));
$_productCollection->addAttributeToSort('updated_at', 'DESC');
$_productCollection->setPageSize(4);
What I am trying to do is grab the image_feature_front_right label as set in the back-end, but have been unable to do so. Here is my code for displaying the products on the front end:
<?php foreach($_productCollection as $_product) : ?>
<div class="fll frontSale">
<div class="productImageWrap">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image_feature_front_right')->directResize(230,315,4) ?>" />
</div>
<div class="salesItemInfo">
<p class="caps"><?php echo $this->htmlEscape($_product->getName());?></p>
<p class="nocaps"><?php echo $this->getImageLabel($_product, 'image_feature_front_right') ?></p>
</div>
</div>
I read that $this->getImageLabel($_product, 'image_feature_front_right') was the way to do it, but produces nothing. What am I doing wrong?
Thanks!
Tre
It seems you asked this same question in another thread, so to help others who might be searching for an answer, I'll anser it here as well:
I imagine this is some sort of magento bug. The issue seems to be that the Magento core is not setting the custom_image_label attribute. Whereas for the default built-in images [image, small_image, thumbnail_image] it does set these attributes - so you could do something like:
$_product->getData('small_image_label');
If you look at Mage_Catalog_Block_Product_Abstract::getImageLabel() it just appends '_label' to the $mediaAttributeCode that you pass in as the 2nd param and calls $_product->getData().
If you call $_product->getData('media_gallery'); you'll see the custom image label is available. It's just nested in an array. So use this function:
function getImageLabel($_product, $key) {
$gallery = $_product->getData('media_gallery');
$file = $_product->getData($key);
if ($file && $gallery && array_key_exists('images', $gallery)) {
foreach ($gallery['images'] as $image) {
if ($image['file'] == $file)
return $image['label'];
}
}
return '';
}
It'd be prudent to extend the Magento core code (Ideally Mage_Catalog_Block_Product_Abstract, but I don't think Magento lets you override Abstract classes), but if you need a quick hack - just stick this function in your phtml file then call:
<?php echo getImageLabel($_product, 'image_feature_front_right')?>
Your custom block would need to inherit from Mage_Catalog_Block_Product_Abstract to give access to that method.
You could also use the code directly from the method in the template:
$label = $_product->getData('image_feature_front_right');
if (empty($label)) {
$label = $_product->getName();
}

Resources