Listing Categories in Magento - magento

I'm having a problem and getting an understanding of this will help me figure out Magento a bit more. I have a CMS page using 1column.phtml. I actually creating a vertical navigation system using 1column.phtml itself, not the CMS. The CMS portion of things is just being used to show some images. The design of the site dictates the layout which is why I am using a 1 column and putting the sidebar in there and not using the left.phtml file. Anyway, that's not the problem. I am trying to pull the main categories and don't quite get how to do that. I'd rather just put the code in the phtml file and not mess with the XML, but when I add the code I'm not getting anything back.
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
So I get nothing back. I also don't understand scope of these, so once I get this working, how would I pull only top level categories? Thanks!

I would try to get a collection of categories and see where that takes you.
$categories = Mage::getModel('catalog/category')
->getCollection();
This code will give you every single category. You can use addAttributeToSelect and addAttributeToFilter functions to furter narrow down your categories.
From there you can foreach through the categories to display them or what whatever you want to do with it.

Related

How to filter product based on specific arrribute in magento and call via cms page as well from controller

I need some tips to use product list functionality in my cms pages.
like in my cms page named "manufacture = apple" should show all products of apple manufacture .
same for other attribute like color, size etc .....
Thanks.
You need to create small module. I can't share complete code here, but sharing you a helpful link which I have earlier used and working fine.
Link:https://www.atwix.com/magento/products-list-cms/
Hope it will helpful!
create a template (test.phtml) under yourtheme/catalog/product and add the following code to your test.phtml
<?php
$arrParams = array_slice($this->getRequest()->getParams(),1);
$attribute = each($arrParams);
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter($attribute[0],$attribute[1]);
echo '<pre>';
print_r($collection->getData());
exit;
?>
than call this template to your cms page. Add the code below in content area of your cms page.
{{block type="catalog/product" template="catalog/product/test.phtml"}}
once you have the array of product than display it as per your requirement.

Configurable Option going berserk on Product Page in Magento

I am a novice in Magento and kinda stuck badly here.
My Theme is ready in Magento and I needed a Size selection on my Product Page. So I searched and found out that it is done by having Configurable Product. I did all the steps mentioned here http://www.magentocommerce.com/knowledge-base/entry/creating-a-configurable-product
Few minutes later, I did create a Size dropdown which made me felt that I am not a useless hobo after all; but then reality hit me. The dropdown somehow is showing itself at a very odd position and I don't know how to fix it.
This picture shows it all:-
You can see that it's gone below the image whereas I want it right next to the image. The fact that I am not even able to fix the CSS or front end makes me feel worse.
Hence my question is, how can I bring it back to senses or do some code fixes so that it is shown at the right place.
Magento has a strange way of rendering configurable options on a product page. Basically, when you create a configurable product, you have the option of selecting whether the options fall in container1 or container2 (great naming, eh?) You can adjust this in the product edit screen under Design > Display Product Options In.
However, a much easier solution is to move container2 above container1 in your catalog/product/view.phtml file as all configurable products default to Block After Info Column.
This is the code you're looking to move if you're using CE:
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>

Get magento subtotal from cart

I'm currently using this snippet to show the cart totals in the topcart of my Magento shop. My problem is that it's not always updating when products is put in cart, it's just showing 0$, especially configurable products. But when a second product is put in the cart, it's working again.
Am I missing something, should there be a "check" of some kind before this piece of code?
<?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?>
You can also try following code it works for me
<?php echo Mage::helper('checkout/cart')->getQuote()->getSubtotal() ?>
Make sure your top cart block is extending a relevant block type such as Mage_Checkout_Block_Cart_Sidebar. If you do, you will have access to useful functionality that will save you rewriting unnecessary code.
For example, if you extend Mage_Checkout_Block_Cart_Sidebar - you can call getSubtotal()
An alternative would be to use the following:
Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();
you can use this code:
$subtotals= Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();
echo $formattedPrice = Mage::helper('core')->currency($subtotals , true, false);
None of the above worked for me but I was able to get the subtotal using this:
$orderObj = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$orderSubTotal = $orderObj->getSubtotal();
echo $orderSubTotal;
This refers to the success.phtml page.

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.

product prices not updating in configurable products

I am looking at creating a configurable product that has various prices.
Having looked at this, it seems that when you select an option, that has another price, the price field of the product options section does not update.
I have provided an image below:
Image
You can see that I have selected a product option, Oxygen, which is £273. I was expecting the product price of the option to update to match this, but it doesn't.
Under the Associated Products section, I have added a fixed price for the associated products, but this still does not update the price.
I cannot believe that this isn't available out-of-the-box with Magento.
Has anyone ever noticed this before?
I have found This link
Which seems to suggest that it has been noticed before.
Does Simple Configurable Products fix this problem?
Many thanks
SCP will solve your problem - it takes the price from the child product. Unfortunately, this will not work too well if you are also using Custom Product Options with price differentials.
Depending on the complexity of your products you may want to go with normal Magento and a script to work out what the price variants are for the super attribute options. The array for the super attribute price options can be iterated over, master and child products checked against the attribute(s) that change, e.g. colours, and a new attribute array written out. It is a bit of code you will have to write yourself, but here is an article that covers the basics:
http://www.ayasoftware.com/content/magento-update-fly-super-product-attributes-configuration
worse, scp does not allow the customer to edit the choice. My Client insisted he could edit his choice so we had to develop for this using the JSON encoded script on the product view page instead.
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<?php $jason = $this->getJsonConfig(); ?>
<?php $uJason = json_decode($jason); ?>
<?php
if ($_product->getMsrp() > 0) {
$uJason->productMsrp = sprintf("%01.2f", $_product->getMsrp());
}
$jason = json_encode($uJason);
?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $jason ?>);
</script>
I think we had to change the code elsewhere but the above change allowed the msrp to update as well as the price.

Resources