SilverCart Forum

We moderate this Forum and we're here to help. Have you already run a forum search to check if your problem has already been solved?

You can help us helping you by providing detailed error messages, screenshots and logfile entries.

SebastianRamon

Page: 1 , 2
Topic Adding product variations 5665 Views

Re: Adding product variations

21 March 2011 at 4:36pm

Hi Graeme,

it's a bit hard to pick up your path and guide you to the right direction. The challenge is not to create a form or field, you will need some business logic to get the task done properly:

- you will have to decorate the cart-logic, so that a variation that is added creates a new positon if the same product with another variation is already present

- push the variation information through the whole checkout process, send it via e-mail and keep it present in the backend.

I am sorry, but I fear we can't provide a step-by-step guidance for such a complex task.

Maybe Roland will write a tutorial to accomplish this taks in the next weeks.

Cheers
Ramon

Re: Adding product variations

21 March 2011 at 8:39pm Last edited: 21 March 2011 8:39pm

Thanks Ramon,

I think what I want to do is a bit simpler than that. I don’t need to make a Product variation as what I want to do is akin to Quantity: the Size (or Colour) only needs to be selected when added to the Cart. This means I also donʻt need to store the information chosen—it just needs to be included in the emails (both to the customer and the supplier).

So my question becomes, where can I add to the information that gets sent in the confirmation emails so it can include what Size or Colour (if any) is chosen at purchase time?

I hope that makes more sense. I am still struggling to get my head around how Silvercart works—but that is more likely to be a problem with me than with you!

Re: Adding product variations

22 March 2011 at 6:12pm

Hello mck,

thanks for Your post. SilverCart is based on a clear architecture. As we planned and created SilverCart "quick and dirty" was NOT our credo. We share SilverCart with the community because we want to increase the software's quality and functionality constantly. We would be very happy if You would share a clean and reusable implementation of product variations with us. This is a common problem to many ecommerce projects.
I would not help anybody in realizing a "quick and dirty" solution to a problem because I would not go that way and that solution would not be useful to other people.

Cheers,

Roland

Re: Adding product variations

11 April 2011 at 12:19am

I have gone away and tried to solve this by myself, but as I am not skilled in Silverstripe development, my efforts haven’t yielded much fruit. Perhaps I am not the type of person you are seeking to try Silvercart at this stage and you only want highly skilled people to test it. If so, I will understand and go back to trying the latest builds of eCommerce and leave Silvercart for another day, perhaps. However, if anyone can help it would be much appreciated. I fully understand that there are glaring conceptual gaps in my understanding of Silverstripe and PHP but I have done the tutorials and successfully implemented several (simple) sites using it so I am not totally useless!

My problem: I have successfully added a ClothingSize field to the Product, can read this in to an array and make a drop-down of this on the product page, but I cannot seem to pass its value to ShoppingProductAddCartForm.php so it is available to be selected along with the Quantity of a product (It can be selected on the Product page but not in the portion that relates to the Shopping Cart which is built by ShoppingProductAddCartForm.php). I have tried multiple variations along this theme:

protected function fillInFieldValues() {
   $availablesize = $this->ClothingSize;
...

(I want to turn the ClothingSize string in to a drop-down field so I first want to get the existing value of ClothingSize which is stored as a string/VarChar.) The field exists in SilvercartProduct and also in SilvercartShoppingCartPosition.

Thanks
Graeme

Re: Adding product variations

13 April 2011 at 10:35am Last edited: 13 April 2011 10:55am

Hi Graeme,

in fact, your solution to add variations to silvercart is a little bit hacky and could cause some problems if you want to enhance it further (e.g. multiple variations for one product).
Another point i want to mention is that you should use decorator pattern or something similar as far as possible to extend silvercart. Otherwise you will not be able to update your silvercart version properly (and there was a lot of work to provide new features, bugfixes and other enhancements during the last weeks, which are not published yet ;-) ).

To get the variations working, you have to extend silvercarts ShoppingCartPositions and, of course, its OrderPositions.

To support you with your problem, we need a little more information.
Did you add the ClothingSize as a FormField to SilvercartProductAddCartForm like this:

protected $formFields = array(
...
'ClothingSize' => array(
'type' => 'DropdownField',
'title' => 'Size',
'checkRequirements' => array(
'isFilledIn' => true,
)
)
);

After adding the FormField PHP based, you need to manipulate the forms template. There are 3 templates you should copy to your projects folder:

SilvercartProductAddCartFormDetail.ss
SilvercartProductAddCartFormList.ss
SilvercartProductAddCartFormTile.ss

After you made a copy of the templates, you have to add the FormField like this:

$CustomHtmlFormFieldByName(ClothingSize,CustomHtmlFormFieldSelect)

After doing this, you have to flush SilverStripes cache by calling YOUR_URL/?flush=all

It's also important for us to know the content of $formData in SilvercartProductAddCartForm::submitSuccess().

Cheers
Sebastian

Re: Adding product variations

14 April 2011 at 9:46am

Hi Sebastian,

Thanks for the feedback. I had figured most of that out, and it is a good point about using Decorators -- I will definitely have to do that.

My idea isn’t as hacky as you think, however. I don't just want to add a ClothingSize Dropdown on the checkout page -- I would like to read a ClothingSize field I have added to the Product as a field:

public static $db = array(
...
'ClothingSize'    => 'VarChar(50)',
...

);

I have got this part working okay. I convert a comma-delimited string into a dropdown field which I can get to show on the SilvercartProductPage.ss with no problem. The problem is how to get this to work on the ShoppingCart. I don't know how to access, what would be called as SilvercartProduct.ClothingSize in the SilvercartProduct.php file, in the SilvercartProductAddCartForm.php file. If I can't read this field I can't then use this to create the value for my ClothingSize dropdown field.

I hope this makes more sense.

Regards,

Graeme

Re: Adding product variations

14 April 2011 at 10:15am Last edited: 14 April 2011 10:16am

Try this in SilvercartProductAddCartForm::fillInFieldValues() :

$product = DataObject::get_by_id('SilvercartProduct', $this->customParameters['productID']);
$this->formFields['ClothingSize']['value'] = $product->getClothingSizesAsArray();
$this->formFields['ClothingSize']['selectedValue'] = 'XXL';

'$product->getClothingSizesAsArray()' should be the products clothing sizes as array. It has to be a key value pair to fill the forms select field. The keys of the array are used as values of the forms select field, the values of the array are used as labels of the select fields options.

I hope this helps. After doing this, you can access the sent values in SilvercartProductAddCartForm::submitSuccess(). The relevant form data can be found in its parameter $formData.

Cheers
Sebastian

Re: Adding product variations

14 April 2011 at 10:35am

Hi Sebastian,

Thanks for that. I will let you know how I get on.

Regards
Graeme