Class-Mappings - Overwrite pimcore models (since 1.3.2)

Skip to end of metadata
Go to start of metadata

Usage Example

Since version 1.3.2 it's possible to map a custom class to a pimcore model. That means that you can use your own classes inside pimcore, but an example will be more explanatory: 

// define a custom class,  for example:
class My_Product extends Object_Product {

    public function myCustomGetter () {
        return true;
    }
}

// and optionally a related list

class My_Product_list extends Object_Product_List {

    public function myCustomGetter () {
        return true;
    }
}

Now create a mapping.
To do so, create a xml in /website/var/config/classmap.xml containing a simple mapping: 

<?xml version="1.0"?>
<zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">
    <Object_Product>My_Product</Object_Product>
    <Object_Product_List>My_Product_List</Object_Product_List>
</zend-config>

After that, wherever you retrieve an Object_Product you will get an My_Product, also the following My_Product_List will contain My_Product

$myProduct = Object_Abstract::getById(234);
$myProductList = Object_Product::getList(array("limit" => 10));

if ($myProduct instanceof My_Product) {
   // yes that will be true ;-)
}


if ($myProductList instanceof My_Product_List) {
   // yes that will be also true ;-)
}
WARNING
pimcore also uses the mapping internally. Because of that you can also hook into the core of pimcore. Be carefully if you want to overwirte methods like save(), update(), delete() or any other method which is already defined by pimcore.

So far it's only read-only that means that the mapping only take effect by the getters like Document::getById() or Asset::getList(), .. and so on. 
Don't forget to clear the cache after you change the configuration.

Supported Types

Until now this feature is only provided by classes based on Element_Interface like Asset, Document, Object_Abstract and their list implementations.

Following a bigger example:

<?xml version="1.0"?>
<zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">

    <!-- Objects -->
    <Object_Product>Myproject_ObjectProduct</Object_Product>
    <Object_Product_List>Myproject_ObjectProductList</Object_Product_List>
    <Object_Folder>Myproject_ObjectFolder</Object_Folder>

    <Object_List>Myproject_ObjectList</Object_List>

    <!-- Assets -->
    <Asset_Folder>Myproject_AssetFolder</Asset_Folder>
    <Asset_Image>Myproject_AssetImage</Asset_Image>

    <Asset_List>Myproject_AssetList</Asset_List>

    <!-- Documents -->
    <Document_Page>Myproject_DocumentPage</Document_Page>
    <Document_Snippet>Myproject_DocumentSnippet</Document_Snippet>
    <Document_Link>Myproject_DocumentLink</Document_Link>
    <Document_Folder>Myproject_DocumentFolder</Document_Folder>

    <Document_List>Myproject_DocumentList</Document_List>

</zend-config>
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.