Datafeedr Support Forums

Datafeedr Support Forums (http://www.datafeedr.com/forums/index.php)
-   Questions (http://www.datafeedr.com/forums/forumdisplay.php?f=67)
-   -   Get local url for product image (http://www.datafeedr.com/forums/showthread.php?t=7953)

tloenders October 21st, 2012 08:25 AM

Get local url for product image
 
Hi,

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?

Thanks!

Eric October 21st, 2012 09:19 AM

Hi,

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.

Eric

tloenders October 22nd, 2012 07:59 AM

Very helpful, thank you!

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

Code:

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>';
                endforeach;
        endif;
}



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

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