Handling digital assets in Magento with Pimcore

Handling digital assets in Magento with Pimcore

Throughout this article I will show you a simple and quick way of integrating Magento and pimcore. Before that, lets outline the definitions of the two.

Magento is a feature-rich eCommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their eCommerce store. Magento’s intuitive administration interface features powerful marketing, search engine optimization and catalog-management tools to give merchants the power to create sites that are tailored to their unique business needs. Designed to be completely scalable and backed by Varien’s support network, Magento offers companies the ultimate eCommerce solution.

Pimcore is a powerful and robust Zend Framework based PHP content management system (WCMS) for creating and managing digital content and assets licensed under the open-source BSD license. Besides being a full-featured open-source WCMS system, pimcore is the first and premier PHP open source enterprise product information management framework (PIM) available. This means true multi-channel publishing and integration into ecommerce systems like Magento and OXID eSales.

Technologically pimcore is strictly based on the Zend Framework, the leading development framework for the PHP programming language used by 100s of companies such as Fox, IBM and bwin. Pimcore’s frontend GUI interface is 100% powered by the renown ExtJS Javascript library, which is used by companies such as Adobe, Amazon and Sony.

The above definitions are “borrowed” respectively from the corresponding sites (http://www.magentocommerce.com/, http://www.pimcore.org/).

The advantage of pimcore besides that it comes with several nice digital asset management (DAM) features is that it comes as a standalone PHP application you can install on your own servers. And since not everyone is willing to give their data to various CDN services like Amazon or other 3rd party DAM services this can be a key factor in choosing your privately hosted DAM platform.

Now, imagine if all of the digital media assets that a single Magento product might have can be served from pimcore platform. This includes standard images, possible PDF files, videos, audio files, etc. Since Magento is pretty limited when it comes to its Digital Asset Management feature we turn our looks towards pimcore as it is its core functionality.

Lets suppose we have our Magento shop up and running, and we want to integrate it now with pimcore in order to achieve the above mentioned goal. Following are the basic steps we will take in doing so.

Within pimcore, under the “Settings > Object > Classes” define a new class called “MagentoBaseProduct”. You can check the screenshots for the fields defined on class. You will notice that SKU is among them. We will use SKU as identifier link between pimcore and Magento.

Create apiAction method within {pimcore_root}/website/controllers/DefaultController class of pimcore and implement the desired “api logic”. Basically we will use this controller action to serve images to Magento based on the SKU that was passed as parametar.

file {pimcore_root}/website/controllers/DefaultController.php:

public function apiAction () 
	$sku = $this->_getParam('sku');
	if (!$sku) {
		throw new Zend_Controller_Router_Exception('Missing "sku" parameter from request.');
	$products = Object_MagentoBaseProduct::getBySku($sku);
	$product = $products->current();
	if (!$product) {
		throw new Zend_Controller_Router_Exception('Unable to find the product object based on the provided "sku" value.');	
            $images = array();
            if ($product->getBase()) {
                $images['base'] =  array(
                    'filename' => $product->getBase()->getFilename(),
                    'path' => $product->getBase()->getPath(),
                    'src' => $product->getBase()->getThumbnail('magento_base'),
                    'mimetype' => $product->getBase()->getMimetype(),
            if ($product->getThumbnail()) {
                $images['thumbnail'] =  array(
                    'filename' => $product->getThumbnail()->getFilename(),
                    'path' => $product->getThumbnail()->getPath(),
                    'src' => $product->getThumbnail()->getThumbnail('magento_thumbnail'),
                    'mimetype' => $product->getThumbnail()->getMimetype(),
            if ($product->getSmall()) {
                $images['small'] =  array(
                    'filename' => $product->getSmall()->getFilename(),
                    'path' => $product->getSmall()->getPath(),
                    'src' => $product->getSmall()->getThumbnail('magento_small'),
                    'mimetype' => $product->getSmall()->getMimetype(),
            $galleryImages = @$product->getGallery()->getItems();
            if ($galleryImages) {
                foreach ($galleryImages as $imgObj) {
                    $image = $imgObj->getImage();
                    $images['gallery'][] = array(
                        'filename' => $image->getFilename(),
                        'path' => $image->getPath(),
                        'src' => $image->getThumbnail('magento_small'),
                        'mimetype' => $image->getMimetype(),
            /* image url is like: http://pimcore.loc/website/var/assets/{path}{filename} */
            $response = array(
                'sku' => $sku,
                'images' => $images,
	header('Content-Type: application/json');
	echo json_encode($response);

Now modify the {magento_root}/app/design/frontend/default/default/template/catalog/product/view/media.phtml file in such way that it calls the pimcore’s apiAction method and fetches the images through it. (please note that this actually an example of a bad practice, to execute such logic from .phtml file, however it will do for the purpose of this example).

file {magento_root}/app/design/frontend/default/default/template/catalog/product/view/media.phtml:

    $_product = $this->getProduct();
    $_helper = $this->helper('catalog/output');
    $imgCDNPath = 'http://pimcore.loc/';
$client = new Zend_Http_Client();
$client->setConfig(array('timeout' => 5));
$client->setParameterGet('controller', 'default');
$client->setParameterGet('action', 'api');
$client->setParameterGet('sku', $_product->getSku());
//$client->setParameterGet('sku', 'iphone-4s');
$response = $client->request();
$remoteProductObj = null;
$imagesGallery = null;
if ($response->isSuccessful() && ($response->getStatus() === 200)) {
    $remoteProductObj = json_decode($response->getBody());
    //Zend_Debug::dump($remoteProductObj); exit;
    $imagesGallery = @$remoteProductObj->images->gallery;
<?php if (@$remoteProductObj->images->base): ?>
    <h4><?php echo $this->__('Base Image') ?></h4>
    <img src="<?php echo $imgCDNPath.$remoteProductObj->images->base->src ?>" />
<?php endif; ?>
<?php if (@$remoteProductObj->images->thumbnail): ?>
    <h4><?php echo $this->__('Thumbnail Image') ?></h4>
    <img src="<?php echo $imgCDNPath.$remoteProductObj->images->thumbnail->src ?>" />
<?php endif; ?>
<?php if (@$remoteProductObj->images->small): ?>
    <h4><?php echo $this->__('Small Image') ?></h4>
    <img src="<?php echo $imgCDNPath.$remoteProductObj->images->small->src ?>" />
<?php endif; ?>    
<?php if ($imagesGallery): ?>
    <h4><?php echo $this->__('Image Gallery') ?></h4>
    <?php foreach ($imagesGallery as $img): ?>
        <img src="<?php echo $imgCDNPath.$img->src ?>" />
    <?php endforeach; ?>
<?php endif; ?>

The above code example is by no means final, its just an example focused around getting the images from pimcore platform. If you look at the Zend_Http_Client class above you can conclude that you can access the pimcore controller action by following url http://pimcore.loc/?controller=default&action=api&sku=123456 if your url rewrites are off, where pimcore.loc needs to be replaced with the real domain where your pimcore paltform is installed.

Finally create some product (object) entries under pimcore with valid SKU and images assigned from pimcore assets. The SKU values on pimcore products (objects) need to correspond to SKU values on your Magento products.

The above example is all about pulling images from pimcore and displaying them on Magento product view page. This analogy can easily be extended to all sort of digital assets (pdf, audio, video, etc.). For example you might have a shop which sels products that come with instruction manuals. You can manage and serve these instruction PDF files from pimcore and then just pull and display them on Magento. Please keep in mind that the real integration would be done in a much more proper manner (API call caching, etc.), all of the above is just a rough example to give you a hint on things.

Hope this article gives you some great ideas on how to combine Magento and pimcore, in case you need more digital asset management capabilities.

You made it all the way down here so you must have enjoyed this post! You may also like:

Custom data components in Pimcore Zoran Salamun
Zoran Salamun, | 3

Custom data components in Pimcore

Extending Pimcore with plugins Zoran Salamun
Zoran Salamun, | 9

Extending Pimcore with plugins

Pimcore Portlets Zoran Salamun
Zoran Salamun, | 0

Pimcore Portlets


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.