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 , 2
Topic Adding product variations 5666 Views

Adding product variations

15 March 2011 at 1:40am

What would be the best way of going about to offer variations of a product? For example, for clothing offering sizes (S, M, L, XL) or colours (Red, Blue, Black).

From a user's point of view I would think a checkbox would work best, but a drop-down menu might also be a good idea.

Regards,
Graeme McKinstry

Re: Adding product variations

15 March 2011 at 7:22am Last edited: 15 March 2011 7:24am

Hi Graeme,

it depends on the amount of possible variations.

From a usability point of view, I would either go radio buttons (if one option is allowed) or checkboxes (if multiple options are allowed).This way, the user sees the available options at a glance. Does work great for smaller option lists, but does not work good for large option lists, like country selections.

Dropdown would work, too. But the available options are partly hidden, which I see as a disadvantage for the user. On the other hand, you can squeeze huge lists into a dropdown (like country selections).

Cheers
Ramon

Re: Adding product variations

15 March 2011 at 10:48pm

First an admission: I’m relatively new to PHP programming so there are plenty of gaps in my knowledge. (I haven’t programmed in earnest for many years!)

As I see it there would need to be two parts: the ability to specify what colours and sizes (say) are available, in the CMS; and the ability for the user to pick a colour and/or size from the available options which would be dynamically generated depending on what was available via the CMS. I can code the second part (for the end user) but I am not sure how I would go about adding the ability to add variable colours and sizes in the CMS. Something like UserForms gives the CMS editor the ability to create custom dropdown menus, etc., but I am not sure how I go about adding this functionality to Silvercart.

Any help and/or pointers appreciated.

Graeme McKinstry

Re: Adding product variations

16 March 2011 at 10:19am

Hi Graeme,

seems like your question is more SilverStripe related.

You may want to go through the SilverStripe tutorials first, especially http://doc.silverstripe.org/sapphire/en/tutorials/5-dataobject-relationship-management. After that, you will most likely be able to answer the question by yourself.

If you look at the class diagram http://www.silvercart.org/assets/documentation/SilvercartClassDiagram.pdf you will notice, that SilvercartProduct is the class that needs to have a $has_many relationship with your variation class.

Implementing this, editing the fields and plugging a variation to a product in the backend and writing some logic (e.g. price determination) is plain SilverStripe craft.

Hope this helps.

Cheers
Ramon

Re: Adding product variations

18 March 2011 at 5:04am

Okay, I have come up with a cunning plan that relies on reading the fields into an array and then creating a CheckboxSetField element using a function. However, I can't get my functions to be usable in the templates.

For example, if I place:

function somerandomtext() {
return "Some random text";
}

in the Controller of, say, SilvercartProduct.php
I should be able to call $somerandomtext in the template (SilvercartProductPage.ss, for example) but I get nothing – my variable is just gobbled up without outputting the text. I have tried this on a normal Silverstripe installation and it worked fine so is there something that Silvercart is doing to stop this working? I have even tried placing the function in Page.php, etc.

I have spent some considerable time trying to get this to work with no joy. No doubt it is something obvious – is there somewhere specific that these function calls need to go?

Re: Adding product variations

18 March 2011 at 6:50am

Hi,

Solved my own problem. Added function on the wrong part of ProductPage.php.

Re: Adding product variations

18 March 2011 at 7:32am

Hi mck,

silvercart does not manipulate the templating process in any way.

Cheers,

Roland

Re: Adding product variations

21 March 2011 at 12:16am

Almost there. I have made a new text field in the Product definition to include a list of clothing sizes (comma delimited).

If this list in not empty then the customer will see a dropdown field of available sizes to choose.

How do I add the customer-chosen value to the list of information sent to the shopping cart (along with quantity and price)? I know it needs to be included in the form $productAddCartForm. Do I need to add another field? If so, where?

There are lots of files and it is difficult to know, without conducting a lot of trial and error, exactly where this should be added.

Thanks
Graeme McKinstry