Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Products with different sizes/prices

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

Page: 1
Go to End
Author Topic: 554 Views
  • NicolasLeuenberger
    Avatar
    Community Member
    9 Posts

    Products with different sizes/prices Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1078 Posts

    Re: Products with different sizes/prices Link to this post

    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;
       }

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Products with different sizes/prices Link to this post

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

  • NicolasLeuenberger
    Avatar
    Community Member
    9 Posts

    Re: Products with different sizes/prices Link to this post

    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

    554 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.