e-commerce extension with colours and sizes

1 view
Skip to first unread message

windandwaves

unread,
Nov 21, 2007, 4:35:33 PM11/21/07
to SilverStripe Development
Hi

This is my second post about the e-commerce module. I need to add
size, quantity, etc... However, I am having real trouble doing so. I
have noticed that you have made provisions for this already:

___________________________________________
order.php - line 1115
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

/**
* This class stores extra information about the order item,
* such as colour, size, or type as defined in the Product
* Attribute class
*/
class Order_Item_Attribute extends Product_Attribute{
static $db = array(
"AttributeTitle" => "Varchar(50)",
"Type" => "Enum (array('Size','Colour','Subscription'),'Size')",
"Quantity" => "Int",
"UnitPrice" => "Currency",
"OrderID" => "Int",
"ProductID" => "Int",
);
static $has_one = array(
"Order_Item" => "Order_Item", // Internal field becomes OrderID, not
Order
"Product_Atrribute" => "Product_Atrribute",
);
}

NOTE: there is a spelling mistake here - it should be Attribute and
not Atrribute

___________________________________________
product.php - line 1115
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

class Product_Attribute extends DataObject {

}


I tried to implement the whole product attribute thing, but I got
stuck. That is, I tried to follow the "path" of how a product gets
added to the cart and add an additional parameter for attributes, but
this seemed rather endless so I was probably doing something wrong.

In terms of allowing the owner of the site to provide various sizes /
colours, I added fields to the product class and also added them to
the CMS so that the site owner can tick boxes for each product on what
is available. I am still having some issues in actually getting the
extra variables (e.g. size, colour) with a button. So far, I have done
the following:

1. change the buy now hyperlink (a href) to a form button
2. use javascript (not ideal!) to add the size / colour to the action
of the form (e.g. /product/add/green/)

I tried to access the POST or GET variables from the form, but I had
trouble doing so (the form was hardwired in my silverstripe template
so perhaps I should move the form to the php code to facilitiate
this).

As you can read, I have limited experience with these things, but I am
keen to learn. Any help would be greatly appreciated.

Thank you

Nicolaas

Sigurd Magnusson

unread,
Nov 21, 2007, 5:44:49 PM11/21/07
to silverst...@googlegroups.com
Hey thanks for the code and interest in the module. Sean will give you
more info but basically the code you found on product attributes is
unfinished work, and Sean is going to see if he can dig up some code on
the events module that will give you guidance. Hopefully you code up
colour/size support and submit the code, along with the code in your
emails, as patches at http://open.silverstripe.com , because we're
currently in need of support for the next ecommerce release :)

Siggy


--
Thanks,
Sigurd
--

Sigurd Magnusson | Chief Marketing Officer
SilverStripe
http://www.silverstripe.com

Office: +64 4 978 7332
Skype: sigurdmagnusson

Learn more about our next version of the SilverStripe product!
http://silverstripe.com/whats-coming-in-silverstripe-2-2/

Sean Harvey

unread,
Nov 22, 2007, 3:42:26 PM11/22/07
to silverst...@googlegroups.com
I think you could have a crack at implementing the Product_Attribute
class, and place some
database fields on it, so:

class Product_Attribute extends DataObject {

static $db = array(
'Colour' => 'Varchar',
'Size' => 'Varchar'
);

}

And, then add on Product.php

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

getCMSFields() on Product.php could be updated to allow a TableField
for adding new Product_Attribute(s).
This table would be used to add more colours and sizes for each product.

There's also the fact an Order_Item_Attribute class exists. But the
way I see it, we first
get the data saved with Product_Attribute then worry about getting
this information into Order_Item_Attribute. :-)

Anyone else have any ideas about how this sort of implementation could
be scalable?

Sean

-------
Sean Harvey | Developer
SilverStripe
http://silverstripe.com

Phone: +64 4 978 7330 ext 39
Skype: halkyon5

Level 3, 97-99 Courtenay Place
Wellington, New Zealand

Reply all
Reply to author
Forward
0 new messages