2

I am new to Magento, I have already build website and I need to do some imrovements on it.

I want to create custom minicart on my website's header. What would be the approach to do this

  • Thats hard for beginners. You have to edit the header template. You could just insert the whole code there or you create your own template and put it in the layout file in the correct block then add a reference to this block in the template of the header on the correct position and edit your new template, this would be much cleaner but requires more knowledge of magento. But just to give you an idea. – Black Feb 26 at 18:15
  • Is it that difficult? I thought I will call phtml in header.phtml file and do some coding in it. Where can I learn to code on magento? can you guide me please? – Asim Ali Feb 26 at 18:18
  • Yes you can also just edit the header.phtml file and add your code, but this is not considered clean. But since you are a beginner, you can do it and improve it later if you get better. If you want to learn how to code magento, then I recommend you to buy some good magento developer books or find some tutorials. Unfortunately I only know german books. – Black Feb 26 at 18:22
  • Thanks @Black that is very helpful. If you can add your suggestions in answer, then I can mark your answer as correct. – Asim Ali Feb 26 at 18:45
1

Yes you can just edit the header.phtml file and add your code, but this is not considered clean. But since you are a beginner, you can do it and improve it later if you get better. If you want to learn how to code magento, then I recommend you to buy some good magento developer books or find some tutorials. Unfortunately I only know german books.

The clean way would be to create your own design. Then create your own template file and insert a reference to it in the header.phtml so that your template gets loaded exactly where you put it, you can do it like this:

<?php echo $this->getChildHtml('your_own_block_name'); ?>

But before you can do this, you have to create a layout file and insert your own block on the right section. You can choose the already existing block type checkout/cart_minicart which is in app\code\core\Mage\Checkout\Block\Cart\Minicart.php.

E.g. app/design/frontend/company/designname/layout/local.xml

    <reference name="header">

        <!-- add mini cart to the header : new template -->
        <block type="checkout/cart_minicart" name="your_own_block_name" 
            <action method="setTemplate">
                <template>page/header/mini_cart.phtml</template>
            </action>
        </block>
    </reference>

The block type allows you to access all methods from the block class Mage_Checkout_Block_Cart_Minicart (and its parents) which is in app\code\core\Mage\Checkout\Block\Cart\Minicart.php, you can also just use the block type core/template. Browse the core code in app/code/core there you can find all blocks. You can also create your own blocks in your own extension. But rule #1: Never change the core files! Otherwise it will be a mess and you can't upgrade magento anymore.

  • 1
    Thanks for your support. you saved the day :) – Asim Ali Feb 27 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.