Datafeedr Support Forums  

Go Back   Datafeedr Support Forums > Current Version (V3) Forum > Questions
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Important - The support forums are now in "read-only" mode as we transition to an alternative help desk solution. Feel free to contact us here with any of your questions or search the forums for an existing solution.
Thread Tools Search this Thread Display Modes
Old October 21st, 2012, 08:25 AM
tloenders tloenders is offline
Join Date: Jun 2012
Posts: 52
Default Get local url for product image


I've created my own loop outside of the Datafeedr context where I grab some products for display. All works fine, except that I can't seem to find how to dynamically get the url of the local product image.

I thought of constructing it by using the $product->id, but I noticed that eg. Amazon product images are not cached locally (as might be the case for other merchants), so this is not an option.

Took a quick glance at datafeedr.php, but perhaps you could point me in the right direction?

Old October 21st, 2012, 09:19 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
Join Date: Feb 2008
Posts: 16,902


The first step is to obtain the product record. If product ID is 789502110370127:

PHP Code:
$product dfr('products')->get('789502110370127'); 
If the code is in a [product] block, you can omit this step, since the $product variable is already available.

Then, there's a function "dfr('app')->url(kind, product)" that returns different kinds of urls for a specific product

PHP Code:
dfr('app')->url('image'$product); //returns something like "/store/image/789502110370127/18-piece-bbq-set/"
dfr('app')->url('thumbnail'$product); // similar for a thumbnail
dfr('app')->url('click'$product); // returns "store/product/buy/789502110370127/18-piece-bbq-set/" 
And finally, $product object properties contain direct merchant urls.

Old October 22nd, 2012, 07:59 AM
tloenders tloenders is offline
Join Date: Jun 2012
Posts: 52

Very helpful, thank you!

For future reference, here's how one could use this to build a random product image blob:

function my_awesome_product_loop( $total = 10 ) {

	global $wpdb;

	$table    = $wpdb->prefix . 'dfr_shop_products';
	$querystr = "SELECT * FROM $table ORDER BY RAND() LIMIT {$total}";
	$products = $wpdb->get_results( $querystr );

	if ( $products ) :
		foreach ( $products as $product ) :
			// Do stuff with Eric's feedback here, like:
			echo '<a href="' . dfr( 'app' )->url( 'click', $product ) . '" title="' . esc_attr( $product->name ) . '"><img src="' . dfr( 'app' )->url( 'image', $product ) . '" /></a>';

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Image zoom plugin for product image? barbinec Questions 1 March 21st, 2012 08:37 AM
Connection Key for local development ajstocco Questions 10 January 23rd, 2012 09:32 AM
Local product data extrazin Questions 2 October 31st, 2011 08:31 AM

All times are GMT -5. The time now is 12:57 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.