2

My problem is that I have a Magento Enterprise Edition system and 4 different stores on it, so I have 4 different themes. One of those themes override Catalog and Checkout block on Mage/Code/Community folder and another theme override the same blocks on Mage/Code/local folder.

The system is taking by default the Catalog and Checkout blocks from Community folder, so the rest of the websites are taking this version of Catalog and Checkout by default, therefore, those websites aren't working well as they need the original version of those blocks.

Can anyone help me fixing this? I hope can be a way to "override" those blocks on each theme of something similar... I guess I'm not the first person with this problem but I didn't found any solution so far. Please, any help will be appreciated.

Thanks

  • I'm curious to know what changes you are effecting in your class rewrite. – benmarks Feb 28 '14 at 16:49
1

In a dream world, blocks should have nothing to do with the theme itself.
So you shouldn't need to change a block just because a theme requires it.
But this almost never happens.

My suggestion is not to copy the blocks in the local folder if you need some custom functionality. Most of the blocks can be rewritten. I have a hunch that this is the case for you.

Instead, create 2 different blocks (one for each theme) that extend the original block.

Let's say that you want to change the Mage_Checkout_Block_Cart.
For this create an extension. We'll call it Mycompany_Themes.
in the config.xml of your theme you should have this (among others).

<blocks>
    <mycompany_themes>
        <class>Mycompany_Themes_Block</class>
    </mycompany_themes>
</blocks>

Now create the 2 blocks you need.

app/code/local/Mycompany/Themes/Block/Checkout/Cart/Theme1.php

<?php
class Mycompany_Themes_Block_Checkout_Cart_Theme1 extends Mage_Checkout_Block_Cart {
   //do your magic in here
}

app/code/local/Mycompany/Themes/Block/Checkout/Cart/Theme2.php

<?php
class Mycompany_Themes_Block_Checkout_Cart_Theme2 extends Mage_Checkout_Block_Cart {
   //do your other magic in here
}

Now all you need to do is change the layout files of your themes and tell Magento to use you own block instead of the default one.
So search in checkout.xml any reference of <block type="checkout/cart"... and replace it with

<block type="mycompany_themes/checkout_cart_theme1" ...> <!-- for theme 1 -->
<block type="mycompany_themes/checkout_cart_theme2" ...> <!-- for theme 2 -->

You can even take it one step further and create an additional block in case you may need to add a single thing that should affect both themes

app/code/local/Mycompany/Themes/Block/Checkout/Cart/Abstract.php

<?php
abstract class Mycompany_Themes_Block_Checkout_Cart_Abstract extends Mage_Checkout_Block_Cart {
   //some general methods in here - leave empty for start if you have none.
}

And you can make your other 2 blocks extend this abstract block.

class Mycompany_Themes_Block_Checkout_Cart_Theme1 extends Mycompany_Themes_Block_Checkout_Cart_Abstract

class Mycompany_Themes_Block_Checkout_Cart_Theme2 extends Mycompany_Themes_Block_Checkout_Cart_Abstract
  • Wow Marius, that was amazing, incredible answer! I was totally lost and that's what I was looking for and perfectly explained. I'll try and let you know! Thanks thanks thanks! – Maria Feb 26 '14 at 13:05
  • Thanks so much for the answer! Very useful! And what about the Cms folder? It is also overridden on code/community/Mage/Cms/Block and code/community/Mage/Cms/Page and this theme hasn't got cms.xml file so I don't know exactly what to do. Can I copy the default cms.xml file and add it to the theme with the parameters pointing to the block.php and page.php files of the theme? Very annoying! Also, I have code/local/page overriding the default and if I delete that folder, the entire website stops working, it only shows a blank page, I think is because it doesn't find the layout. But I don't unders – Maria Feb 28 '14 at 15:13
  • @Maria I think you are confusing "themes" and "code pools". – benmarks Feb 28 '14 at 17:03
  • @benmarks One of the themes I installed added a new Code/Community/Mage/ folder, so this theme is overriding Catalog, Checkout, Cms and Page folders. And the other theme added a new Code/Local/Mage folder overriding Catalog and Checkout. I did what Marius told me with Catalog and Checkout classes but now I don't know what can I do with Cms and Page folders on Community folders. I understand what Code pools does, that´s why I don´t understand why deleting Code/Local/Page folder, the websites stop working; system should take Code/Core/Page classes as it didn't find that folder on local – Maria Mar 1 '14 at 23:20

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.