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.

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, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

Listing Colors from product variations in product template


Reply


7 Posts   741 Views

Avatar
Nobrainer Web

Community Member, 137 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, 233 Posts

13 November 2013 at 9:22am

Edited: 13/11/2013 9:22am

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

[url=http://www.silverstripe.org/ForumMemberProfile/show/6572]nimeso[/url] might be able to help there.

Avatar
Nobrainer Web

Community Member, 137 Posts

13 November 2013 at 9:26am

Kinda like that yes :-)

Avatar
Nobrainer Web

Community Member, 137 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, 233 Posts

13 November 2013 at 10:02am

May also useful:

https://github.com/sunnysideup/silverstripe-ecommerce_product_variation_colours
https://github.com/burnbright/silverstripe-shop/issues/59

Avatar
Jedateach

Forum Moderator, 233 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, 137 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/