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.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Ecommerce - Product options (sizes/colours/types...) and discounts


Go to End


8 Posts   7495 Views

Avatar
freeyland

Community Member, 22 Posts

3 August 2007 at 8:42pm

From the docs:
Stage 1. Just a list of options (e.g. red, blue, green, Big, Green, Small), but same weight/price for all
Stage 2. Different weights, prices and possibly photos could for the types.

I am making a holiday booking system. For each hotel you will have different rooms (the products). If you chose to go by bus you will be charged an extra price on top of the standard product price. If you go by car, you get a reduction .

I think the easiest way to do so is to have some kind of admin page where you can administer the different options.
Then you would need to assign available options to a product.
Per option you should have the possibility to add or deduct an amount. (So + and - dropdown and maybe also *)
So when adding product to the cart. You should be able to select from dropdowns the option you want and the price beeing adapted in real time when changing the options.
You should also be able to have options where you don't assign a price to it. Those options will just be for informational use. (ex. Do you take skilessons yes or no, which period do you want to go).

Do I need to make a spereate tab for this or do I add them on the go when creating a product? (The way you can add extra formfields to a contactform)
This has probably to be done with a has_many relationship. In what relation do i need to add the price and the mathematical symbols?

Anybody have ideas or remarks on how to implement this.

Avatar
Sean

Forum Moderator, 922 Posts

4 August 2007 at 5:02pm

Edited: 04/08/2007 5:11pm

There is a Product_Attribute class in there I believe, however, it doesn't appear to have been used yet and is only 'stubbed out'. I think basically:

class MyProduct extends Product {

   static $has_many = array(
      'Attributes' => 'MyProduct_Attribute'
   );

}

class MyProduct_Attribute extends DataObject {

}

I don't know if it should be a many_many or a has_many, many_many just confuses me...

Cheers,
Sean

Avatar
freeyland

Community Member, 22 Posts

7 August 2007 at 1:35am

Edited: 07/08/2007 1:41am

Thx Sean,

Something which is still not clear for me in ss framework is how to implment such things. I had the same problem with articles. Let say we want to add each article to a specific category.
I found the following in the docs:

class Article extends DataObject {
	static $many_many = array(
		"Categories" => "Category",
	);
	
	/**
	 * @param DataObjectSet
	 */
	function addCategories(additionalCategories) {
		$existingCategories = $this->Categories();
		
		// method 1: Add many by iteration
		foreach($additionalCategories as $category) {
			$existingCategories->add($category);
		}
 
		// method 2: Add many by ID-List
		$existingCategories->addMany(array(1,2,45,745));
	}
}
 
class Category extends DataObject {
	static $belongs_many_many = array(
		"Articles" => "Article",
	);
}

Where do I add the available categories in the admin section? Do I add an extra tab with CMSfields or do I need to make a separate page where you can administer the different categories.

I know you are working on a blog module. Is there some kind of cloud with tags? If so, how are the administarted?

thx

Avatar
Sean

Forum Moderator, 922 Posts

12 August 2007 at 3:17pm

Edited: 12/08/2007 9:37pm

Hi there,

I don't know a whole lot about the many_many, and belongs_many_many, but I believe this is a step in the direction. Article would extend Page, because you're wanting it to be a page that can be easily created/deleted from within the SS CMS. Category would be extending DataObject because it doesn't require itself to be a page created or deleted in the CMS, and is just exactly that, an object with some data but without specific page requirements.

I think you are able to use a CheckboxSetField, which should populate with the categories. Although, I'm not entirely sure how this works with the many_many. Perhaps someone else could shed some light?

[EDIT: http://doc.silverstripe.com/doku.php?id=many_many-example ]. I've created a small example here if you'd like to take a look.

Avatar
Willr

Forum Moderator, 5523 Posts

13 August 2007 at 9:09pm

Very nice example Sean! :D

Avatar
freeyland

Community Member, 22 Posts

13 August 2007 at 10:39pm

Thank you Sean. Much clearder now. Thx.

Avatar
BeefStake

23 Posts

18 August 2007 at 8:24am

>Very nice example Sean! :D
Seconded

Avatar
bones

Community Member, 110 Posts

11 June 2008 at 10:38pm

Sean's link no longer works. Would somebody mind reposting it for me, please.

Thanks