Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

plans for extending images in ecommerce?


Go to End


4 Posts   1704 Views

Avatar
supermegaultra

Community Member, 33 Posts

17 August 2010 at 10:33am

Hey guys,

Are there any plans at all on making a module for easily addable multiple images for ecommerce?

Something like what trademe.co.nz have would be amazingly beneficial.

I would but I don't have anywhere near enough skills to do something like this..

Avatar
Bambii7

Community Member, 254 Posts

18 August 2010 at 2:23pm

Not sure what the plans are for the ecommerce module and this. But if you look around you'll find some useful posts on DataObjectManager and the gallery.
I got multiple images working on a site I haven't yet made live yet. I like to make a seperate DataObject to handle the images, so I can include captions and fancy stuff. But it might be easier for you to not worry about that to start with.
It'll take some PHP coding on your part, but there is plenty of help around.
If you look in ecommerce/code/products/Product.php on line 28

	public static $has_one = array(
		'Image' => 'Product_Image'
	);

You'll want many so, change the "has_many" array to include many product images.
	public static $has_many = array(
		'Variations' => 'ProductVariation',
		'Images' => 'Product_Image'
	);

Then you'll need to add a few lines to the getCMSFields function to add a form for you to add mulitple images. This is where I find the DataObjectManager module REALLY useful. If you download it and add it to your site you should be able to add a field like

		$MyImageManager= new DataObjectManager(
			$this,	
			'Images',
			'Product_Image'
		);
		$fields->addFieldToTab("Root.Content.Images", $MyImageManager);

The next thing will be to print the added images to your template. I think this should work.

<% control Images %>
$Product_Image
<% end_control %>

Avatar
supermegaultra

Community Member, 33 Posts

18 October 2010 at 12:12pm

Thanks heaps for that Bambi!

I've installed DataObjectManager and have updated my files like you instructed and it all seems good to go!

One issue remains is that the last bit about adding the images to the template.. Can't get them to show?

I have added: <% control Images %> $Product_Image <% end_control %>
replacing the original call for the images were in my ecommerce/templates/layouts/product.ss:

<% if Image.ContentImage %>
			<img class="productImage" src="$Image.LargeImage.URL" alt="<% sprintf(_t("IMAGE","%s image"),$Title) %>" />
		<% else %>
			<img src="ecommerce/images/productPlaceHolderNormal.gif" alt="<% sprintf(_t("NOIMAGE","Sorry, no product image for &quot;%s&quot;"),$Title) %>" />
		<% end_if %>

Is this right? Lookin forward to your help. It's already been a huge help!

Avatar
supermegaultra

Community Member, 33 Posts

25 November 2010 at 11:57pm

Hey again guys,

I've made progress with this thanks to Bambi's help. I have the dataobjectmanager showing on each product page in the backend.. But still have not been able to show the additional images I want on the frontend product page.

Have also noticed there is an issue where there is no control over what images show for that specific product in the form where I add mulitple images. It displays all of the files in the assets/uploads folder for ever product.

Could someone please supply the code for their products.php and products.ss files?

Much appreciated.