Jump to:

2088 Posts in 1008 Topics by 455 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » Edit the moduls php-code, but keep it updateable

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: 1581 Views
  • tea4ge
    Avatar
    Community Member
    5 Posts

    Edit the moduls php-code, but keep it updateable Link to this post

    Hi,

    1. Thanks for Silverstripe. I love it!

    2. I want to make same changes on the "Product" page (there's no need für a weight field etc). How can I do this without loosing the updateability?

    The only way I see is to subclass "Product" to "myProduct" (for example), but than I have an useless page type in my list:
    --> not very user friendly!

    What do you recommend to do?

    (sry for possible english mistakes)

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Edit the moduls php-code, but keep it updateable Link to this post

    You can do this without subclassing Product.

    What you'll want to implement is a DataObjectDecorator class for Product - http://doc.silverstripe.com/doku.php?id=dataobjectdecorator - this is a standard way of modifying an existing class without harming upgradability.

    e.g.

    Create a new file MyProductDecorator.php in the mysite/code/ directory with the following (or simiar) code:

    <?php
    class MyProductDecorator extends DataObjectDecorator {

       function updateCMSFields($fields) {
          $fields->removeByName('Weight');
       }

    }
    ?>

    Add this line to your _config.php file in the mysite directory for your project to enable the decorator for Product:

    Object::add_extension('Product', 'MyProductDecorator');

    The decorator should be enabled after you run ?flush=1

    The example decorator simply removes the Weight field from the product editing fields in the CMS. It doesn't manipulate the DB to remove the Weight column. This should be sufficient enough for you.

    If you're wanting to update the Product HTML template, simply copy Product.ss from the ecommerce module into your theme (or mysite) templates folder and change it from there, after you run ?flush=1 your Product.ss should be used instead of the one in ecommerce.

    Cheers,
    Sean

  • tea4ge
    Avatar
    Community Member
    5 Posts

    Re: Edit the moduls php-code, but keep it updateable Link to this post

    Ahh! Thanks!

    Sill have a Problem:
    The "Weight" field doesn't disappear.
    A "Debug::show("test")" in updateCMSFields works.

    It seems that my "updateCMSFields" function is executed before(!) the "getCMSFields" function of the "Product" class.
    I would say this is because "getCMSFields" misses the following line:
    "$this->extend('updateCMSFields', $fields);"

    Any tipps?

  • wewo
    Avatar
    Community Member
    7 Posts

    Re: Edit the moduls php-code, but keep it updateable Link to this post

    Hi,

    Did you found a solution meanwhile?

    regards,
    wewo

  • tea4ge
    Avatar
    Community Member
    5 Posts

    Re: Edit the moduls php-code, but keep it updateable Link to this post

    No.

    I will post it if I found one.

  • BLU42 Media
    Avatar
    Community Member
    71 Posts

    Re: Edit the moduls php-code, but keep it updateable Link to this post

    Try adding in the ampersand in your decorator's updateCMSFields function:

    function updateCMSFields(&$fields) {
    $fields->removeByName('Weight');
    }

    See if that helps!

  • tea4ge
    Avatar
    Community Member
    5 Posts

    Re: Edit the moduls php-code, but keep it updateable Link to this post

    To: SmartPlugsDesign
    Thanks for your tip. I had tried that already -> It does`t help.

    After some tests I'm pretty sure that my supposition is true:
    The "getCMSFields()" function misses this line:
    "$this->extend('updateCMSFields', $fields);"

    I added it and everything works fine!
    See http://doc.silverstripe.com/doku.php?id=dataobjectdecorator#modifying_cms_fields for details.

    In addition I found another problem:
    The ProductGroup has no "static $has_one = array();"
    So I can't add new relations (http://doc.silverstripe.com/doku.php?id=dataobjectdecorator#adding_extra_database_fields)

    Should I open a ticket?

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