Get category same as admin category positions position - magento

I'm trying to change the order of specific categories using a php script. The script below runs fine, and I'm seeing the position change values in catalog_category_entity, but order is unaffected in the admin, and in the front.

Please use drag and drop from admin
And reindex than flush cache

are you using your script like this ?
<?php
$_categories = $this->getStoreCategories();
?>
<?php foreach ($_categories as $_category) : ?>
<li class="<?php if($_category->getId() == $this->getCurrentCategoryId()) echo "active"; ?>">
<?php echo $_category->getName(); ?>
</li>
<?php endforeach; ?>
if not use it like this.

Related

sort collection of category by name

I have custom links in menu that shows categories in drop-down.
For that I made a file in catalog/navigation->mainmenu.phtml
(a custom file)
Now, I want to show categories after sorting it by name. please help me how can I sort collection of categories by name. I already set order of category in admin. But in front-end it show unsorted.
Code is:-
<?php $defaultcategory= Mage::app()->getStore()->getRootCategoryId();?>
<?php $mainchildren = Mage::getModel('catalog/category')->getCategories($defaultcategory);?>
<ul>
<?php foreach ($mainchildren as $subcategory) : ?> <?php // 2 level ?>
<?php if($subcategory->getIsActive()):?>
<li id="show_subcat" class="<?php if($i==1): echo 'first'; endif; ?>" >
<?php $childid=$subcategory->getId();?>
<?php $subchild = Mage::getModel('catalog/category')->getCategories($childid);?>
<?php foreach ($subchild as $subchildcategory) : ?>
<?php $path=$subchildcategory->getRequestPath()?>
<?php break;?>
<?php endforeach ?>
<a href="<?php echo $this->getUrl().$path; ?>">
<?php echo $name= $subcategory->getName().$subcategory->getEnable() ?>
</a>
</li>
<?php endif;?>
<?php endforeach; ?>
</ul>
You can try :
children = Mage::getModel('catalog/category')->getCategories($defaultcategory)
->addAttributeToSort('name', 'ASC');
or :
children = Mage::getModel('catalog/category')->getCategories($defaultcategory)
->setOrder('name','ASC);
$categories = Mage::helper('catalog/category');
$collection = $categories->getStoreCategories(false,true,false);
foreach($collection as $_category)
{
//Do something
echo $_category->getName();
}
use this code to get collection and follow this link for more detailIn magento - same code for getting all categories running well with sorted in localhost but not in web server

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 !

Magento: display multi-selection as a list with unique ID' s so list item can be changed to an image using CSS

I figured out how to display my custom multiselection attributie as a list but havent been able to figure out how to add an ID or class to every list item. This would allow me to display an image using CSS instead of text.
Hope you guys can help me. By the way, this is the code I use to display my custom attribute "rating" as a list:
<?php if($_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)): ?>
<ul><li><?php
$_comma = ",";
$_list = "</li><li>";
echo str_replace($_comma,$_list,$_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)) ?>
</li></ul>
<?php endif; ?>
</div>
Without knowing the exact format of the return of your function, I can't be 100% sure, but I think this would do the trick:
<div>
<?php if($_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)):?>
<ul>
<?php $i=0?>
<?php foreach(explode(',', $_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)) as $value) : ?>
<li id="value_<?php echo $i?>"><?php echo $value ?></li>
<?php $i++ ?>
<?php endforeach ?>
</ul>
<?php endif; ?>
</div>
It would probably be a little easier to just modify your return to give you back an array, but if the return is a comma separated list and not easy to change, then explode should do the trick.

Magento view related products in list.phtml

I have the following requirement;
I want to show a products configured related products on the category listing page (list.phtml).
I figured I could make some call on the list.phtml inbetween the for each loop for each product using the [b]$_product[/b] variable but I can't seem to populate the relatedProductCollection
sorry new to all this is it even possible.
<?php foreach ($_productCollection as[b] $_product[/b]):?>
<li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?>last<?php endif; ?>" >
<div class="product-shop">
<div class="f-fix">
<?php $product->getRelatedProductCollection(); ?>
</li>
<?php endforeach; ?>
$product has been used to call the getRelatedProductCollection function.
but,
In that foreach loop you have taken it as $_product.
Can you see the difference ??
Underscore is missing. This is taken from your code. Make the variable same in both the places and try.

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