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.

Data Model Questions

Products with different sizes/prices


4 Posts   570 Views


16 October 2011 at 1:14am Community Member, 9 Posts

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 :-)


16 October 2011 at 1:59am (Last edited: 16 October 2011 1:59am), Forum Moderator, 1091 Posts

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;


16 October 2011 at 3:47am Forum Moderator, 1796 Posts

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. 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...


16 October 2011 at 5:07am Community Member, 9 Posts

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 :-)