Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

E-Commerce Modules /

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, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

Edit the moduls php-code, but keep it updateable


Go to End


7 Posts   2542 Views

Avatar
tea4ge

Community Member, 5 Posts

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)

Avatar
Sean

Forum Moderator, 922 Posts

20 February 2009 at 11:14am

Edited: 20/02/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

Avatar
tea4ge

Community Member, 5 Posts

21 February 2009 at 1:44am

Edited: 21/02/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?

Avatar
wewo

Community Member, 7 Posts

24 February 2009 at 2:47am

Edited: 24/02/2009 2:49am

Hi,

Did you found a solution meanwhile?

regards,
wewo

Avatar
tea4ge

Community Member, 5 Posts

25 February 2009 at 5:20am

No.

I will post it if I found one.

Avatar
BLU42 Media

Community Member, 71 Posts

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!

Avatar
tea4ge

Community Member, 5 Posts

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?