[checkout] make custom fields available during checkout

wildguy
wildguy's picture

Joined: 2007-09-04
Posts: 42
Posted: Fri, 2009-03-06 22:04

I use customfields to apply dynamic backgounds to photo thumbnails. Is there a way to load custom field data into a template variable for use during checkout? I have been able to add a whole block for each item in the cart by adding this line to SessionContents template....

{g->block type=customfield.CustomFields item=$tpl.items[$item.id]}

What I want, however, is to return a specific value from a particular field, instead of the entire block.

i.e why doesn't this.... {$block.customfield.LoadCustomFields.fields.CustomThumbBg} work?


Gallery URL = http://thewildside.dreamhosters.com/main.php
Gallery version = 2.3 core 1.3.0
API = Core 7.54, Module 3.9, Theme 2.6, Embed 1.5
PHP version = 4.4.9 cgi-fcgi
Webserver = Apache/2.2.11 (Unix) PHP/4.4.9 mod_ssl/2.2.11 OpenSSL/0.9.8c mod_fastcgi/2.4.6 Phusion_Passenger/2.0.5 DAV/2 SVN/1.4.2
Database = mysqlt 5.0.67-log, lock.system=flock
Toolkits = Gd, Thumbnail, ImageMagick, jpegtran, NetPBM
Acceleration = none/86400, none/21600
Operating system = Linux bonanno 2.6.24.5-serf-xeon-c6.1-grsec #1 SMP Tue Oct 7 06:18:04 PDT 2008 x86_64
Default theme = wildsidegothic
gettext = enabled
Locale = en_US
Browser = Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_4_11; en) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16
Rows in GalleryAccessMap table = 76
Rows in GalleryAccessSubscriberMap table = 3741
Rows in GalleryUser table = 24
Rows in GalleryItem table = 3736
Rows in GalleryAlbumItem table = 26
Rows in GalleryCacheMap table = 0

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2009-03-07 10:30

Sure, it's quite straightforward.

Add a new module (which is as simple as 11 lines of code in a file called module.inc in its own folder) which has a callbacks.inc file. In the template where you want to load new variables make a call to your callback function. The callback function has to follow the right variable structure, of course, but that's just a matter of following examples.

If you want to be really neat you don't even need to modify templates: create your own block in your new module - the block has a template file which calls your callback function etc. etc.

Alternatively instead of writing a new little module you can hack the customfields module to do the same, if you want, but it's not as tidy.

There's nothing checkout-specific about this; checkout uses the same technique to display item prices - it has a block with a template, and the template calls a callback in the checkout module's callbacks.inc to fetch the prices for the item on display, then the template can display them.

Quote:
i.e why doesn't this.... {$block.customfield.LoadCustomFields.fields.CustomThumbBg} work?

Er... dunno. But have you actually loaded the variable anywhere, before you try to use it? Like in a callback function?

 
wildguy
wildguy's picture

Joined: 2007-09-04
Posts: 42
Posted: Mon, 2009-03-09 16:53
alecmyers wrote:
Quote:
i.e why doesn't this.... {$block.customfield.LoadCustomFields.fields.CustomThumbBg} work?

Er... dunno. But have you actually loaded the variable anywhere, before you try to use it? Like in a callback function?

Yes, sorry I didn't mention it. I originally tried the following within the foreach loop:

{g->callback type="customfield.LoadCustomFields" itemId=$tpl.items[$item.id]}
or
{g->callback type="customfield.LoadCustomFields" itemId=$theme.item.id}

However no data was returned this way, and I imagine that isn't ideal to place a callback in the loop.

I will try to make a simple module as you suggest. Thanks.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Mon, 2009-03-09 17:00

If the data you want is (or ought to be) fetched by an existing callback, then I wouldn't bother with creating your own module; use the callback that's there.

Debug the callback with the usual technique of inserting echo() statements into the callback code to see what's happening.

I find inserting this to be helpful:

echo ('<pre>'); print_r($variableToDebug); echo('</pre>');

If you run in debug 'buffered' you also get a pop-up window with all the Smarty variables, which should include $block, so you can see what's in that.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Tue, 2009-03-10 13:45

Also I've just seen this post by the God Floridave in another thread, which might be helpful:

http://gallery.menalto.com/node/85470#comment-299820

 
wildguy
wildguy's picture

Joined: 2007-09-04
Posts: 42
Posted: Wed, 2009-03-11 14:27

Thanks for your help, I am on the right track now.