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

Listing Colors from product variations in product template


Go to End


7 Posts   2228 Views

Avatar
Nobrainer Web

Community Member, 138 Posts

13 November 2013 at 9:03am

Hi guys,

I'm using https://github.com/burnbright/silverstripe-shop v. 1.0.

I have added variations to my products.
The variations are based on Size and Color. (Product - Large:Blue, Small:Blue, Small:Black, Medium:White)
Now i would like to show all the Colors for a product in the product list.
But how do i do this?

It would be perfect if someone could show me how i could do the following:
Create a function that gets all the Variations of a product, and then gets all the unique colors of these variations.
(I have extended ProductAttributeValue with a custom field that holds a HEX value of the color)
Result: Product, Colors: Blue, Black, White

Hope someone can help me

Avatar
Jedateach

Forum Moderator, 238 Posts

13 November 2013 at 9:22am

Edited: 13/11/2013 9:22am

Kind of like this? http://merinooutlet.com/

nimeso might be able to help there.

Avatar
Nobrainer Web

Community Member, 138 Posts

13 November 2013 at 9:26am

Kinda like that yes :-)

Avatar
Nobrainer Web

Community Member, 138 Posts

13 November 2013 at 9:57am

So far i did this, but how can i improve it to only get from current product?:

	public function GetAvailableColors () {
		//$productid = $this->owner->ID;
		
		$colortype = ProductAttributeType::get()->filter(array('Name' => 'Color'))->First();	
		$attributevalues = ProductAttributeValue::get()->filter(array('TypeID' => $colortype->ID));
	
		return $attributevalues;
	}

But that, as far as i can figure out, just gives me all the colors - not looking into what is actually a color variation on the current product.

Template looks like:

		<% loop GetAvailableColors %>
			<li style="background: #{$CustomData};" title="$Value"></li>
		<% end_loop %>

Avatar
Jedateach

Forum Moderator, 238 Posts

27 January 2014 at 4:12pm

Hi Nobrainer,

I'm just wondering how you got on with this. I'm looking at making it part of the core module. Did you manage to get it working?

Avatar
Nobrainer Web

Community Member, 138 Posts

27 January 2014 at 11:45pm

Hi,

I can't really remember what i did and why, but as i recall the client told me that all sizes would allways have all colors available.
What i have is this in the template:

	<% if Variations %>
		<ul class="colorlist">
			<% loop GetAvailableColors %>
			<li style="background: #{$CustomData};" title="$Value"></li>
			<% end_loop %>
		</ul>
	<% end_if %>

and this in a productExtension

public function GetAvailableColors () {
		$productid = $this->owner->ID;
		
		$colortype = ProductAttributeType::get()->filter(array('Name' => 'Color'))->First();	
		$attributevalues = ProductAttributeValue::get()->filter(array('TypeID' => $colortype->ID));
	
		return $attributevalues;
	}

I just add the list of colors under the image and apply some jquery to set the right color in the dropdown.
You can see the site here: http://www.blusbar-engros.dk/produkter/damer/bluse-2/