Download & Extend

Provide a default image when Amazon doesn't provide one

Project:Amazon Module
Version:7.x-1.x-dev
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:patch (to be ported)

Issue Summary

When Amazon hasn't provided a picture of the product, how does one display a default image to stand in for the missing picture?

Comments

#1

I thought Amazon always provided an image. Can you give me an example ASIN that causes this problem for you?

#2

ASIN: B0006EMD14

The default image doesn't appear in a grid view I've set up with the Views2 module. It's not just happening to this one book; it's happening to several. The books for which Amazon displays individual, associated cover pictures come through fine.

On the Amazon Store item page, the default image displays correctly. However, on this page the default image displays the following text: "No image available. Share your own customer image." Since the "share your own customer image" function isn't available to visitors of my site, this default image is rather misleading. It would be nice to replace it.

#3

Title:default image» Provide a default image when Amazon doesn't provide one
Category:support request» feature request

Interesting - in this case Amazon does not populate the Image URL at all - it doesn't even get populated. I'm not sure how Amazon Store is doing that differently and getting the Amazon "no image" image.

So there should be a way to do this. In the meantime, you could could probably make your view behave differently if that field is empty (might need views_calc for that)

#4

If the field is empty, I can make Views2 omit displaying the field. This is not particularly helpful for this scenario.

I've looked at Views_Calc; it doesn't appear to offer the amazon image as a field it will calculate.

#5

You would use a relationship - please see the example view and the handbook page on using Amazon with views.

#6

I already understand how to make the Amazon fields appear within Views2. The problem seems to be that Views_calc requires you to build the calculation within its settings control panel before you can call it in Views2. The Amazon fields do not appear in the Views_calc settings control panel and there is no way to exploit relationships there.

I am new to Views_calc, so maybe I'm missing something or misunderstanding your instructions.

---
Addendum: I also just tried adding a Views_calc field by initially building it with a placeholder calculation that would validate; then once the calculation field was available in Views2, I had hoped that there I could summon the Amazon field by creating the relationship and later adjust the calculation to include the Amazon field made available by the relationship. No joy. Even after creating a Views_calc field and examining it in Views2, it does not offer the option to create a relationship.

I discovered after my experiment the following warning on the Views_calc project page: The complex queries created are not relationship-safe yet, so you can't do accurate calculations on fields coming from relationships.

Moreover, there appears to be no way to access relationships via Views_calc at this time.

#7

Proposal for how to resolve this:

1. Add to the administrative interface a place to load a file.
2. Check if we need to choose the size or crop/resize the file. (Integration with imagecache would be another step, not considered here)
3. Fix the code (the proprocess would be the place) to substitute the image when it's not provided.
4. Make sure it works correctly both with the standard templates and in views.
5. Provide the fix for both D6 and D7.

The one problem that I see is that Amazon provides *3* images for each product, so we'll have to take care of all three. That either means imagecache or having 3 file upload spots on the admin page. Not sure I like that idea. Using imagecache would add it as a dependency for this feature.

#8

Status:active» needs review

Wow, that's a lot of work for a small feature. However, this patch appears to work. Please test and take a look. I'm attaching both a patch and the module with the patch applied.

1. Enable imagecache
2. Create (or use if you have them) 3 presets for small/medium/large
3. Visit admin/settings/amazon and open up the default image fieldset.
4. Upload the image you want to use and select the presets that should be used.
5. [edit] truncate your amazon_item and amazon_item_image tables
6. [edit] visit the nodes with amazon items again so that the database is refreshed

Seems to work in views and in the one normal template I tried.

You can view your amazon_item_image table to see what's happening with these.

AttachmentSize
amazon.default_image_869286_08.patch 6.9 KB
amazon_with_default_image.tar_.gz 38.09 KB

#9

I've installed the new module attached to comment #8 above
Ran update.php.
Added a default image within the Amazon.module control panel
Selected imagecache presets in the Amazon.module control panel
Cleared Drupal cache
Cleared Views' cache

Unfortunately, the view itself isn't displaying the default image. I checked the Views config but didn't see any appropriate new settings there. I checked the /files/imagecache/ directory for the resized default image, and it was present.

Have I missed a step?

#10

You missed the

Note that you will have to truncate your amazon_item and amazon_item_image tables and use some method to revisit those nodes for the images to be re-created.

at the end. I just edited that to put it in a more obvious place.

#11

Status:needs review» needs work

We need a hook_update_N() to rebuild the image data for existing amazon items that do not have pictures. This should be a fairly straightforward query on the database, rebuilding/reloading wherever there is not an existing image.

Actually, this is kind of a missing concept in general - there should be a way to rebuild the entire set of amazon data. All the Amazon data is essentially a kind of cache, but it's not formally a cache so doesn't get cleared with cache clearing operations.

It *does* however refresh after the configured time, so this would eventually sort itself out.

#12

Thanks. My bad. I've got it working now. Looks great.

Would be nice if the Amazon_store module also respected the custom default image, but I'm delighted just to have this feature in the Amazon module.

Regarding the rebuilding the entire Amazon data "cache", I had noticed that my Amazon items were not keeping completely current with the Amazon site. For instance, inventory available from third-party book stores seems occasionally out of sync with Amazon.com.

#13

For updates: You may want to go to admin/settings/amazon/storage and change the refresh schedule. Also, make sure cron is running to support that.

#14

#15

Oh, I've had the site's cron running on a daily schedule for months, and other modules have provided evidence that it is correctly configured and executing without problem.

When I originally installed the Amazon module, I configured the refresh schedule for daily too. I just double-checked those settings again and they seem correct.

Also: Thanks for opening that Amazon store issue.

#16

"daily" just means that when a record is 24 hours old, it gets updated. So you might want more than that. Note too that if you ran cron only once a day, and had the refresh schedule set for 24 hours, you could conceivably have nearly 48 hours before an update occurred. If you can come up with specific examples of something that doesn't get updated, please create a new issue with details.

#17

Sorry I haven't committed this yet - I do want to do the update hook. This week will probably be busy as I'm traveling, but maybe I can get it late in the week.

#18

Looking forward to it.

#19

Status:needs work» needs review
AttachmentSize
amazon.default_image_869286_19.patch 8.53 KB

#20

Version:6.x-1.1» 6.x-1.x-dev
Status:needs review» patch (to be ported)

Committed to DRUPAL-6--1: http://drupal.org/cvs?commit=407036

This will show up in the next package cycle of the dev release, in 12 hours or less.

I'm going to mark this "Patch to be ported" so we don't forget about it for D7.

#21

Version:6.x-1.x-dev» 7.x-1.x-dev

#22

I'm not entirely happy with how much had to be done and how much this intrudes on the admin interface, and am wondering if we wouldn't be better with just a theme-layer based approach here for D7. That way people could just theme the image the way they want.

#23

Can one write if-then statements in css?

#24

Theming involves PHP and CSS, as much of each as a person wants. Changing the way something displays is largely a theming function - that's one reason I think I may have gone off-track doing this with a full module solution instead of a tpl.php.

-Randy

#25

Maybe, but I like your full module solution because it's easier for admins to implement; and I suspect that mucking around with the php templates is a barrier for many. Now, if it were included in the module's templates, and all that was needed was to uncomment the relevant code, that could work marvelously. I'm not sure it makes sense to require everyone to cobble together a custom solution; if it were done once and included with the module that would save a lot of aggregate programming hours.

#26

Category:feature request» bug report

A regression in v7.x-1 and therefore a bug. Last week, I already had a reimplementation for 7.x in the works that takes care of #1037698: Provide a way to delete the default image as well. Just need to find the patch... :)