I have a issue where the search results are being counted but not showing up in the content section.
I've tried re-indexing and caching. Also checked to make sure products are set as 'catalog, search'.
Not sure if its a bug in theme (Goetze, using template 4).
This will return no result which is good.
Whereas this shows that there are 23 products in the count but will not display them in grid/list.
Any help would greatly be appreciated.
<?php
$currentCat = Mage::registry('current_category');
if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
// current category is a toplevel category
$loadCategory = $currentCat;
}
else
{
// current category is a sub-(or subsub-, etc...)category of a toplevel category
// load the parent category of the current category
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
}
$subCategories = explode(',', $loadCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if($cat->getIsActive())
{
echo '<a class="parent-categories" href="'.$cat->getURL().'">'.$cat->getName().'</a>';
}
}
?>
Fixed this by commenting out all that code except:
$currentCat = Mage::registry('current_category');
And search seems to be working properly!
Related
I get cart items information using following code:
$cart_items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach( $cart_items as $items )
{
$items->getQty();
}
In above code $items->getQty() always return "float(1)" while more than 1 quantity add in cart for child product.
How to get correct quantity for child product?
Thanks in advance.
Finally I found my solution:
$cart_items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach( $cart_items as $items )
{
STATIC $qty='';
if($items->getProductType() == 'configurable') //configurable products
{
$qty = $items->getQty();
continue;
}
else // non-configurable product
{
if (!$items->getParentItem()) // product which has not parent product
{
$qty = $items->getQty();
}
}
echo $qty;
}
For simple products your code should work.
Try using a model call to see if it makes a difference. Also check sales_flat_quote table and see what items/quantity is found under the sales_flat_quote_item table and if they mismatch with the frontend display.
$oQuote = Mage::getModel( 'checkout/cart' )->getQuote();
// For all items.
$iTotalItemQty = $oQuote->getItemsQty();
echo $iTotalItemQty;
Also are you seeing this show up from a simple product with quantity > 1 or a different product type?
Did you tried getAllVisibleItems() instead of getAllItems()?
$cart_items = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
foreach( $cart_items as $items )
{
$items->getQty();
}
I have the following category setup in my magento store:
store root
|
bedroom kitchen bathroom
| | |
furniture furniture furniture
lighting lighting misc
misc
I need to be able to check if the category misc exists as a subcategory in my current category or not, and if so show a particular block.
So if i was in the kitchen category it would not show but in bedroom and bathroom it would.
How can i do this this check?
To get your sub-category misc
$currentCategoryId = 10;
$collection = Mage::getModel('catalog/category')->getCollection()
->addAttributeToFilter('is_active', 1) //only active categories
->addAttributeToFilter('parent_id', $currentCategoryId)
->addAttributeToFilter('name', 'misc');
To check if your collection contains at least 1 record in it:
if ($collection->getSize() > = 1) {
//'misc' sub-category exists
}
else {
//'misc' sub-category does not exists
}
Load you current category using and get its Id
$currentCat = Mage::registry('current_category');
$currentCatId = $currentCat->getId();
Load the 'misc' sub-category using
$_category = Mage::getModel('catalog/category')->loadByAttribute('name', 'misc');
$_categoryParentId = $_category->getParentCategory()->getId();
if( $currentCatId == $_categoryParentId){
//Do your stuffs
}
Though you have two categories with the same name misc, so you would want to laod category by url-key or parse through the multiple category array to test.
Try flollowing,
<?php
$categoryId = 5;
$categories = Mage::getModel('catalog/category')->load($categoryId)->getChildren();
$catAsArray = explode(',', $categories);
//you can have $catAsArray to check if it has subcategories
foreach($catAsArray as $child)
{
$_child = Mage::getModel( 'catalog/category' )->load( $child );
echo $_child->getName() . '<br />';
echo $_child->getUrl() . '<br />';
echo $_child->getDescription() . '<br />';
}
?>
Or the other way,
<?php
$categoryId = 5;
$_category = Mage::getModel('catalog/category')->load($categoryId);
if($_category->hasChildren())
{
}
?>
I have added this code in a .phtml file where I have the info of an additional checkout step I have created and where I want to set certain logic to be triggered by a category filter based on selecting the last children category for each item:
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($items as $item) {
$productId = $item->getProduct()->getCategoryIds();
$_category = Mage::getSingleton('catalog/category')->load($value);
$cartProductCatId = $_category->getChildrenCategory();
echo 'Category ID: '.$cartProductCatId.;
But, no way.
Hierarchy tree of the categories I have is:
1) Parent_categ_ID=1
1.1) Child_categ_ID=3
1.2) Child_categ_ID=4
2) Parent_categ_ID=2
2.1) Child_categ_ID=5
2.2) Child_categ_ID=6
The categories I want to filter are: ID=3 and ID=5.
I finally solved it in this way:
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$filter_cats = array(3,5);
$found_cat = false;
foreach($items as $item){
$categories_array = $item->getProduct()->getCategoryIds();
foreach($categories_array as $cat){
if( in_array($cat, $filter_cats) ){
$found_cat = true;
break;
}}}
I hope this is helpful for someone. Thanks!!
I have categories with 4 levels.
Example :
level0category --> level1category --> level2category -->lastlevel_level3cateogory
is it possible on lastlevel to display the categories that are in level2 and only? (on a block that i load a custom left.phtml)
I was thinking something with automatic category detection and not have to set cat_id=
Edit: this is what i was looking for, after mix of code from different sources.
<?php
$currentCat = Mage::registry('current_category');
if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
// current category is a toplevel category
$loadCategory = $currentCat;
}
else
{
// current category is a sub-(or subsub-, etc...)category of a toplevel category
// load the parent category of the current category
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
// #TODO enhance for more nested category levels to display sub-categories
}
$subCategories = explode(',', $loadCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if ($cat->getIsActive())
{
if ($currentCat->getEntityId() == $subCategoryId)
{
echo '<li style="display:none;">'.$cat->getName().'</li>';
}
else
{
echo ''.$cat->getName().' <br>'; }
}
}
?>
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter()
->addAttributeToFilter('level',2)
->addOrderField('name');
make sure this line is there
apply ->addAttributeToFilter('level',2)
I am working on a site where I am displaying a list of all the subcategories associated with the current category. The code below works fine for that, but I'd like to change the way the list of subcategories is sorted. Currently, it sorts by category ID. I'd like it to show up in whatever order the Magento user put the categories in in the admin (where they can drag-and-drop to change the category order). Appreciate any help!
<?php
$currentCat = Mage::registry('current_category');
if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
// current category is a toplevel category
$loadCategory = $currentCat;
}
else
{
// current category is a sub-(or subsub-, etc...)category of a toplevel category
// load the parent category of the current category
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
}
$subCategories = explode(',', $loadCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if($cat->getIsActive())
{
echo ''.$cat->getName().'';
}
}
?>
Try calling getChildrenCategories this will take into account the position of each category:
$loadCategory->getChildrenCategories()
EDITED
Unlike getChildren which returns a string of all category ids returns an array of Mage_Catalog_Model_Category so your code will need to be changed to take this into account.
From your code snippet above the following change should work. Note the call to getChildrenCategories() and the change in the foreach loop as each item should be a category object.
<?php
$currentCat = Mage::registry('current_category');
if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
// current category is a toplevel category
$loadCategory = $currentCat;
}
else
{
// current category is a sub-(or subsub-, etc...)category of a toplevel category
// load the parent category of the current category
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
}
$subCategories = $loadCategory->getChildrenCategories();
foreach ( $subCategories as $subCategory )
{
if($subCategory->getIsActive())
{
echo ''.$subCategory->getName().'';
}
}
?>