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.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Products with different sizes/prices


Go to End


4 Posts   1691 Views

Avatar
NicolasLeuenberger

Community Member, 11 Posts

16 October 2011 at 1:14am

Dear community

I'm developing a really basic online shop (the ecommerce module would be overkill). It's working very well, I've got products that I'm managing with ModelAdmin.
Now I'd like to implement different sizes of the same product. Different sizes mean different prices and different weights, which are used to calculate the shipping fees.
How would I do that?
Would I use a HasMany relationship to a list with size/price/weight-entries?
Ideally, I'd have a table where I could add rows and enter size, price and weight.

Any hint in the right direction is higly appreciated :-)

Avatar
martimiz

Forum Moderator, 1391 Posts

16 October 2011 at 1:59am

Edited: 16/10/2011 1:59am

You could create a 'Specs' DataObject, where Product 'has_many' Specs. Then add a ComplexTableField (even in a separate tab) to the product's getCMSFields. This will let you add multiple specs to each product from within ModelAdmin.

Something like:

	public function getCMSFields() {
		$fields = parent::getCMSFields();

		$fields->addFieldToTab('Root.Specs', new ComplexTableField($this, 'Specs', 'Spec'));

		return $fields;
	}

Avatar
swaiba

Forum Moderator, 1899 Posts

16 October 2011 at 3:47am

While martimiz as ever is right on the money with the advice - I'd reconsider this...

I'm developing a really basic online shop (the ecommerce module would be overkill).

I've reinvented the wheel often enough to know better. Silvercart.org has just added the different costings for volue and has variable shipping costs (which I believe is the based on the feedback given at a ssmeetup in london) I'd encourage you to think whether you'd like other people to add to the code on your site for free - or every change you need you'll have to work for...

Avatar
NicolasLeuenberger

Community Member, 11 Posts

16 October 2011 at 5:07am

Thanks martimiz, I'll try that.

The problem, swaiba, is, that in the beginning my customer wanted a really, really basic list of 5-6 products. I only knew the ecommerce module and found it to be faster to develop my own solution, since the customer is very cost sensitive.
But as soon as this was in place, he wanted more...

Had I known Silvercart back then, I probably would have gone with it. Thanks for this hint, I'll use it next time :-)