4

I need to create code pool in Magento. I need to know how to create code pool.

Can we create a custom code pool in Magento?

I created a module in Magento which can be used in community and local.

I also need that in other work. so i need how to create code pool in magento which name. should to be custom.

I want to create code pool in magento and that will be in app/code/ like

  • community
  • core
  • local
  • custom
4
  • i cant get you question clearly. Please update what do you want to do? Commented Nov 29, 2014 at 7:44
  • You dont need to create code pool, you can use the existing code pools such as community and local for custom modules. Commented Nov 29, 2014 at 8:05
  • why do you want another code pool? I don't see the purpose of it. Could you please explain why you need it for and how you intend to use it
    – Dexter
    Commented Nov 29, 2014 at 8:14
  • There is no confusion if it is custom module created by a company/team put that module in community or put in local. Commented Nov 29, 2014 at 8:35

4 Answers 4

3

To be honest, i don't get the point why you should do this. But anyways.

There are 3 codepools in magento:

  • local
  • community
  • core

once a class or file is not fount in local the autoloader checks up community, if there is no file, it tries to load it from core.

When developing a module using an external library, for example Varien, you can place the library inside the lib folder (placed in the magento root directory) and use it in every module. There are several restriction to these libraries e.g. the classname needs to folow the magento structure (class Namespace_Folder_Folder_File), or you can use the PSR0 Autoloader for namespaces to be able to load libraries like Elastica or something.

With this possibility you cann refactor you custom module and provide a library with the given functionality.

Solution:

But if you still need to build a custom codepool in Magento there are several parts to edit:

Mage.php - add you custom codepool to the include path:
/**
 * Set include path
 */
$paths = array();
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'custom';
$paths[] = BP . DS . 'lib';

Your classes will also have to follow the magento class structure as explained above. This will work (i tested it seconds ago) but with this "hack" nearly noone will use your module. Mage.php is the main file in every shop and it will be overwritten during an update.

So if you can use the suggestion with the lib-option it'll be the best way for everyone who will use your module in the future.

cheers

0

All solutions described here implies changing Mage.php. But this is not good solution.

If you look at the beginning of Mage.php you may notice following:

/**
 * Set include path
 */
$paths = array();
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'lib';

$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry('original_include_path'));

So to add your own codepoll you simply need to run in any part of magento you like (e.g. some event):

  1. Run php function get_include_path() http://php.net/manual/ru/function.get-include-path.php
  2. Parse the result as array with explode by separator ":"
  3. Add new item to array
  4. Again implode and run set_include_path()
0

This is easy to create custom code pool in Magento. Just follow the following step:

  1. Open Mage.php that is located in directory app/Mage.php
  2. Find include paths that were added as.

Code:

$paths = array();  
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'lib';

Edit this section to:

$paths = array();

$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'custom';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'lib';
-1

This is the answer from my Understanding for your question. In Magento There are three code pools,

core //magento module, not custom module
community //custom module but community based
local //custom module pool,you can create your module in this pool.

local is the pool for custom module or overwriting core module in Magento.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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