Jump to:

2088 Posts in 1007 Topics by 455 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » How to add a new field to the product.php file?

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

Page: 1
Go to End
Author Topic: 1772 Views
  • coreyheyhey
    Avatar
    Community Member
    1 Post

    How to add a new field to the product.php file? Link to this post

    After I added a new field in the product page, I got a problem to save the content. I got the Content Save Error.
    I tried to change some .SS files but still the same error.
    What else i should chage?
          $fields->addFieldToTab("Root.Content.Main", new TextField("Weight", "Weight (kg)", "", 12));
          $fields->addFieldToTab("Root.Content.Main", new TextField("Price", "Price", "", 12));
          $fields->addFieldToTab("Root.Content.Main", new TextField("Model", "Author", "", 50));
          $fields->addFieldToTab("Root.Content.Main", new TextField("Workshop", "Speaker", "", 50));

  • Jay-Dee
    Avatar
    Community Member
    11 Posts

    Re: How to add a new field to the product.php file? Link to this post

    I would also like to know how to do this.

    I've added extra fields, and after doing db/build, I don't get any errors after saving and publishing. However, the new fields won't show up on the product page.

    Anyone?

    Thanks
    Jay

  • bennettpr
    Avatar
    Community Member
    37 Posts

    Re: How to add a new field to the product.php file? Link to this post

    you need to make sure the fields are added in the model as well.
    EG:

    static $db = array(
          'Price' => 'Currency',
          'Weight' => 'Decimal(9,2)',
          'Model' => 'Varchar',
          'FeaturedProduct' => 'Boolean',
          'AllowPurchase' => 'Boolean',
          "InternalItemID" => "Varchar(30)",
       );

    That way SilverStripe will know where to save the data.

  • Jay-Dee
    Avatar
    Community Member
    11 Posts

    Re: How to add a new field to the product.php file? Link to this post

    Hey Bennett, thanks for your reply. I have done this already.. I added the following line to that array.

    'Year' => 'Varchar',

    And the following line to the getCMSFields function.

    $fields->addFieldToTab("Root.Content.Main", new TextField("Year", "Year", "", 50));

    I can see the field when I want to create a new product, I can type in the YEAR, I can save it and publish it, but when I go to the product page, "Year" is not displayed.

    Do you know why this is happening?
    Thank you
    Jay!

  • bennettpr
    Avatar
    Community Member
    37 Posts

    Re: How to add a new field to the product.php file? Link to this post

    Hi Jay Dee,

    Try (something like) this in your template

    <div class="year">
    Year: $Year
    </div>

    $Year will / should display the year data.


    Paul

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