SilverCart Forum

We moderate this Forum and we're here to help. Have you already run a forum search to check if your problem has already been solved?

You can help us helping you by providing detailed error messages, screenshots and logfile entries.

SebastianRamon

Page: 1
Topic Product images not displaying 2220 Views

Product images not displaying

4 October 2011 at 9:32am

Hello,

Hoping somebody can help me. I'm halfway through trying to integrate Silvercart into an installation and am having difficulties with product images.

I can select and add a product image in the Main tab. The image is stored in the database with what looks like the right number next to it. The permissions on the asset file are set to 777. There's no errors in the apache, php or mysql logs.

The other thing that is not happening, which i suspect is related, is that the Images tab in the product page is always blank which leads me to believe there might be a problem there.

I had made one or two small custom changes to SilvercartProduct which I thought might be causing the problem but reverting to a clean version and rebuilding doesn't fix it. Also tried adding a fresh version of Silvercart and supporting files to another installation and got the same problem.

I'm using version 1.1.

Any ideas? This is driving me kind of crazy as the rest of this looks great but this one problem is really holding me up. Would be massively grateful for troubleshooting tips.

Many thanks,

Andrew

Re: Product images not displaying

4 October 2011 at 9:33am

Apologies...just realised I didn't state the specific problem which is that no images show up next to products and it triggers the default product image I had set up every time.

Re: Product images not displaying

4 October 2011 at 10:18am

Hmmm...I've managed to get this working with what feels like a very hacky workaround.

The problem seems to be in function getSilverCartImages(), in SilvercartProduct.php. $this->SilvercartImages always returns nothing as the Images tab is somehow not working. I only need one image for the moment though and I can get at $this->ImageID which lets me hack around in there and have one image being returned per product and a default one when nothing defined.

Feels like a bad workaround though and I'm fairly sure that functionality should be working in the latest release. Seems like someone else would have spotted it before me so maybe it's something weird going on on my install.

Would still very much like to get to the bottom of it so any feedback, similar experiences or suggestions very much appreciated.

Regards,

Andrew

Re: Product images not displaying

4 October 2011 at 11:19am Last edited: 4 October 2011 6:15pm

Hello Andrew,

this is a known and already fixed bug. In fact, the bugfix isn't yet pushed into the public bitbucket repository, but we will update the repo soon.
The has_one relation Image on SilvercartProduct is deprecated and will be removed in near future.
The correct relation to add images to a product is the has_many relation SilvercartImages.

The problem is, that a custom workflow to handle the deprecated Image relation in high performance environments doesn't fit with the SilvercartImages relation and overwrites the new relations ImageDataObjectManager (this is a locale based problem and happens not for every language...).

To solve this problem you should write a Decorator for the SilvercartProduct. Here is an example:

/**
* Custom changes for SilvercartProduct
*
* @author Sebastian Diel
* @copyright 2011 pixeltricks GmbH
* @since 04.10.2011
*/
class MyCustomSilvercartProduct extends DataObjectDecorator {

/**
* Updates the CMS fields of SilvercartProduct to reset the ImageDataObjectManager
* for SilvercartImages.
*
* @param FieldSet &$fields CMS fields of SilvercartProduct
*
* @return void
*
* @author Sebastian Diel
* @since 04.10.2011
*/
public function updateCMSFields(FieldSet &$fields) {
$silvercartImagesTable = new ImageDataObjectManager(
$this->owner,
'SilvercartImages',
'SilvercartImage',
'Image',
null,
null,
sprintf("`SilvercartProductID`='%d'", $this->owner->ID));
$fields->addFieldToTab('Root.SilvercartImage', $silvercartImagesTable);
}

}

After that, register the decorator in your _config.php:

Object::add_extension('SilvercartProduct', 'MyCustomSilvercartProduct');

Now, the Image tab should be filled with a ImageDataObjectManager.

Hope this helps.

Regards,
Sebastian

Re: Product images not displaying

4 October 2011 at 6:00pm

Superb...just tried it there and it seems to work. Many many thanks.

Plus it also gives me a tiny inkling into some of the best practices with all this. Still largely hacking away here but am starting to really really like what you guys have put together. kudos! and thanks again for the assistance :)