1998 Posts in 530 Topics by 433 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, Jedateach, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1423 Views |
-
Edit the moduls php-code, but keep it updateable

20 February 2009 at 4:15am
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)
-
Re: Edit the moduls php-code, but keep it updateable

20 February 2009 at 11:14am Last edited: 20 February 2009 11:19am
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 -
Re: Edit the moduls php-code, but keep it updateable

21 February 2009 at 1:44am Last edited: 21 February 2009 2:31am
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?
-
Re: Edit the moduls php-code, but keep it updateable

24 February 2009 at 2:47am Last edited: 24 February 2009 2:49am
Hi,
Did you found a solution meanwhile?
regards,
wewo -
Re: Edit the moduls php-code, but keep it updateable

25 February 2009 at 5:20am
No.
I will post it if I found one.
-
Re: Edit the moduls php-code, but keep it updateable

2 March 2009 at 4:07am
Try adding in the ampersand in your decorator's updateCMSFields function:
function updateCMSFields(&$fields) {
$fields->removeByName('Weight');
}See if that helps!
-
Re: Edit the moduls php-code, but keep it updateable

12 March 2009 at 11:03am
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?
| 1423 Views | ||
|
Page:
1
|
Go to Top |




