Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Update a parameter of subclass of Page subclass

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

Page: 1
Go to End
Author Topic: 1111 Views
  • zard
    Avatar
    Community Member
    22 Posts

    Update a parameter of subclass of Page subclass Link to this post

    Hi,
    in my code I have a subclass of Page, and I am trying to update some of its additional parameters but unlike regular updates my changes do not take effect. They are visible in the admin console as unpublished versions, how can I just simply change some parameters?
    I have overridden canEdit and canPublish to allow changes from any user (as that will be my intended use) but I am trying it out with admin anyway, the code looks similar to this:

    $product->QuantityInStock -= 1;
    $product->write();

    I have also tried calling following:

    $product->publish('Stage', 'Live');
    $product->doPublish();

    None of it actually publishes the page, it only produces unpublished versions which I can review in the admin console and can "roll back" to them but that is not really what I want as I would like to have a counter on the page which any user can update via special form and code.

    Also, I only want to update the product object, it is not created anew.

    I would really appreciate some help!

    Thanks
    Petr

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Update a parameter of subclass of Page subclass Link to this post

    I believe you would need to call write() then publish().

    $product->write();
    $product->publish('Stage', 'Live');

  • zard
    Avatar
    Community Member
    22 Posts

    Re: Update a parameter of subclass of Page subclass Link to this post

    Just to give people a reply if they find this post via google - I have tried multiple ways (staging and publishing etc.) but did not manage to make it work.

    I have done alternative solution - I have created an extra object with has_one relationship on the page which is not versioned and I have created a setter and getter on the page so it behaves like internal parameter. I did not need the versioning for that param so it was viable solution for me.

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