Howto pull cached-blocks into external e-commerce app

Author Message

Jeroen van Duffelen

Thursday 10 September 2009 7:43:42 am

Hi people,

We are working on the integration of Magento Commerce with eZ Publish. At the moment we are facing two challenges:
1) Some cached blocks of the eZ Publish templates need to be integrated into the templates of Magento.
2) Sync sessions of both the systems.

I'll post the second challenge in another topic when this one is solved.

So the cached blocks challenge can be discussed here.

On http://www.mybiz.cc you'll find the template we're working on. This template shows three menu's:
1) top menu (with the links "Home" and "Default form")
2) user menu (with the links "My account", "My wishlist", "My cart", etc)
3) primary menu (with the links "Archive folder", "Content folder", "Documentation page", etc)

Both the 1) top menu and the 3) primary menu are cached with cache-block. We want to pull these cached blocks into Magento. We know the cached blocks are saved in the "var" folder and we have already identified the right files... but we need to load them dynamically of course... So some one has an idea of how to do this? Which classes/functions to use?

Any help is welcome!

Jeroen van Duffelen

Thursday 10 September 2009 8:25:38 am

We found that we could use the eZTemplateCacheBlock class. But how to use this in an external PHP file? What to include to get this working?

Jeroen van Duffelen

Thursday 10 September 2009 10:25:54 am

Ok, now we know we can use

 eZTemplateCacheBlock::cachePath( eZTemplateCacheBlock::keyString( $keys ), $nodeID );

But where do I get the $keys from... :S

When checking the the key sent by eZ Publish itself it looks like this scary string:

{i:0;a:3:{i:0;s:2:"60";i:1;s:1:"/";i:2;s:2:"1,";}i:1;s:88:"82_0_82_74_extension/driwebin_1_0-3/design/front_driwebin_1_0-3/templates/pagelayout.tpl";i:2;s:30:"dev__________mybiz_cc___eng-GB";}

André R.

Thursday 10 September 2009 10:39:20 pm

Reading the template caches like this will not work (read: it gets to complex)
Example use of keys:

{cache-block keys=array( $module_result.uri, $basket_is_empty, $current_user.contentobject_id, $extra_cache_key )}

Suggestion: Use subtree_expiry=<node_id> on all your cache blocks, this will make eZ Publish store the cache blocks in a more predictable manner using node id in the first part of it's path, and they won't be cleared globally on any publish action.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Jeroen van Duffelen

Friday 11 September 2009 12:49:30 am

Thx for your reply André!

We are using the keys and the subtree_expiry in the template:

{cache-block keys = array($current_node_id, $module_result.uri, $user_hash) subtree_expiry = $super_menu_root_node_id}

We are calling the cachePath function <b>outside</b> eZ Publish but with the subtree_expiry we still need to generate that enormous long key string to fetch it from the file-system right?

We know the $current_node_id, $module_result.uri and the $user_hash outside eZ Publish and we also know the $super_menu_root_node_id. But we can not generate the key without all the other info.

the code we're using for generating cache-block path:

	class eZBlock { 
	 
		static function cachePath($keyString, $nodeID = false){
				//include_once( 'ezsys.php' );
				
				$checksum = sprintf('%u', crc32(serialize($keyString)));
				$filename = $checksum.'.cache';
	
				$phpDir = ezBlock::templateBlockCacheDir();
				if(is_numeric($nodeID)) {
					$phpDir .= ezBlock::calculateSubtreeCacheDir($nodeID, $filename);
				} else {
					$phpDir .= $filename[0].'/'.$filename[1].'/'.$filename[2];
				}
	
				$phpPath = $phpDir.'/'.$filename;
				return $phpPath;
		}
		
		static function templateBlockCacheDir() {
			$cacheDir = '.../var/cmandev_com/cache/template-block/';
			return $cacheDir;
		}
	
		static function calculateSubtreeCacheDir($nodeID, $cacheFilename) {
			$cacheDir = ezBlock::subtreeCacheSubDirForNode($nodeID);
			$cacheDir .='/'.$cacheFilename[0].'/'.$cacheFilename[1].'/'.$cacheFilename[2];
			return $cacheDir;
		}
	
		static function subtreeCacheBaseSubDir() {
			return 'subtree';
		}	
		
		static function subtreeCacheSubDirForNode($nodeID) {
			$cacheDir = ezBlock::subtreeCacheBaseSubDir();
	
			if (is_numeric($nodeID)) {
				$nodeID = (string)$nodeID;
				$length = strlen($nodeID);
				$pos = 0;
				while ($pos<$length) {
					$cacheDir .= '/'.$nodeID[$pos];
					++$pos;
				}
			} else {
	
			}
	
			$cacheDir .= '/cache';
			return $cacheDir;
		}
	}
	
	echo eZBlock::cachePath(array(60, '/', '1,'), 62).'<br />';
	echo eZBlock::cachePath(array(60, '/', '1,'), 63).'<br />';

The result of this code can be found on:
http://www.mybiz.cc/webshop/load_ez_header3.php

André R.

Friday 11 September 2009 1:48:43 am

"the subtree_expiry we still need to generate that enormous long key string to fetch it from the file-system right?"
Yes, so if you really have to do this (try to look for other ways to integrate maybe?) you should start with something simple like keys=1 + read trough the source code of eZTemplateCacheBlock, especially ::keyString() and ::cachePath() if you haven't already.

For the current_user related code, look in eZUser class (kernel/classes/datatypes/ezuser/).
Some of those variables(user id, roles and limitations) are stored in user session, so you can get them from there.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Jeroen van Duffelen

Friday 11 September 2009 4:29:30 am

Pfff this is getting too complicated. We're thinking about another solution. Please advice if this is the good approach.

In eZ Publish we're going to build module that only shows the html of the menu's. This module outputs those menu's based on the user's credentials. So if a user is logged in, it will show a different menu than when the user is not logged in. We want to cache this output with eZ Publish and pull the cached output into Magento with cURL.

But for this solution to work we have to know when the cache is expired because we want to save the cached file in Magento as a separate cache file too.

So is there a way to check (within the module of Magento) to check if the cached template for the eZ Publish module view is expired?

André R.

Friday 11 September 2009 7:22:40 am

You can check the modified_subnode on ezcontentobject_tree table, and also make sure you only cache it for 2 hours as that is the default cache time for cache-blocks .

Something like:

$sql = "SELECT modified_subnode FROM ezcontentobject_tree WHERE node_id=$nodeID";

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Nicolas Lescure

Friday 11 September 2009 4:08:03 pm

Hi Jeroen,

Can you tell us more about your project ?
I know Magento a little, and I don't see where you want to integrate eZ. Instead of a static block of Magento ?

When you say "So if a user is logged in, it will show a different menu than when the user is not logged in.". You will have one Magento & one eZ I suppose. But the user logs in Magento or eZ ?

Another question : why don't you make the menu in Magento ?

Jeroen van Duffelen

Monday 14 September 2009 1:17:01 am

@André R: thx we'll look at that!

@Nicolas Lescure: we've been developing a standard website interface for eZ Publish (just like the EZWEBIN extension that comes with a standard install of eZ Publish). This website interface has a basic template set which we want to integrate with Magento. Ofcourse the front end user should not see any difference when it switches from eZ to Magento so we want to show blocks of Magento on the eZ front end and show the basic navigation ellements of eZ on Magento.

You can see an example on http://www.mybiz.cc/static/magento/index2.html. Here you'll see that the 1) top menu and the 3) primary menu are shown in the Magento templates.

We are going to sync the sessions and make a single log in for the systems. In the future we'll have content behind a section where users have to login for. So when the user logs in the menu items pointing to the content in the hidden section will shop up. But when the user is not logged in, the menu items are hidden.

We dont make the menu in Magento because than the admin has to update 2 systems...

Mischa Markus

Thursday 17 December 2009 2:19:58 am

looked for it too, found this:

http://blog.baobaz.com/en/blog/ez-gento-managing-ez-publish-content-from-magento-admin-interface

http://www.ezgento.org/

still we can work with ezpublish + xrowecommerce + some paymentgateways

but for complex ecommercesystem it will be interesting in future

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.