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
Topic Extending SilvercartShopConfigurationAdmin with extra managed objects 3549 Views

Extending SilvercartShopConfigurationAdmin with extra managed objects

29 June 2012 at 10:04am Last edited: 29 June 2012 10:04am

Hi,

I'm using your awesome SilverCart product on a clients current SilverStripe install and very happy with it.

I have extended the SilvercartProduct with a DataObjectDecorator to get the extra fields in the client requires without an issue.

However I now need to extend your SilvercartShopConfigurationAdmin so that the object I have created (similar to your SilvercartProductCondition) can be edited by the client in the CMS admin.

I have tried creating an Extension for SilvercartShopConfigurationAdmin as recommended by SilverStripe but cannot see how to add extra $managed_models.

I know this is more of a SilverStripe knowledge issue than a SilverCart issue but I though you guys have probably done this thousands of times already and I'm just banging my head against the table now!

Re: Extending SilvercartShopConfigurationAdmin with extra managed objects

29 June 2012 at 2:09pm

Hello Dom,

I happy to hear that SilverCart is the right software for you. Please show me your code, otherwise it is hard for me to give you any advice.

Re: Extending SilvercartShopConfigurationAdmin with extra managed objects

29 June 2012 at 2:39pm

Roland,

I've copied your SilvercartProductCondition and renamed to ProductSize:

class ProductSize extends DataObject {
public static $db = array(
'Size' => 'VarChar(255)'
);
static $belongs_many_many = array(
'SilvercartProducts' => 'SilvercartProduct'
);

public function fieldLabels($includerelations = true) {
$fieldLabels = array_merge(
parent::fieldLabels($includerelations), array(
'Size' => 'Size',
'SilvercartProducts' => _t('SilvercartProduct.PLURALNAME')
)
);

$this->extend('updateFieldLabels', $fieldLabels);
return $fieldLabels;
}

public function summaryFields() {
$summaryFields = array(
'Size' => 'Size'
);

$this->extend('updateSummaryFields', $summaryFields);
return $summaryFields;
}

}

and extended the SilvercartProduct class:

class SilvercartProductDecorator extends DataObjectDecorator {

public function extraStatics() {
return array(
'many_many' => array(
'ProductSizes' => 'ProductSize',
),
);
}

public function updateCMSFields(FieldSet &$fields) {
$sizeMap = array();
$sizes = DataObject::get('ProductSize');
if ($sizes) {
$sizeMap = $sizes->map('ID', 'Size');
}

$sizeField = new CheckboxSetField('ProductSizes', 'Size', $sizeMap);
$fields->push($sizeField);
}
}

?>

with the following code in _config.php

Object::add_extension('SilvercartProduct', 'SilvercartProductDecorator');

This all works fine (unless there is a better way!). The next part is there I have the problem. I've tried extending the SilvercartShopConfigurationAdmin using SilverStripes Extension so the DataObject I created ProductSize appears in the SC Config as a managed object.

I hope this makes sense.

Thanks

Dom

Re: Extending SilvercartShopConfigurationAdmin with extra managed objects

30 June 2012 at 2:22am

Hi Dom,

your idea has been thought already. I think that you should use the product variants module. Your shirt sizes are product variants. Have a look at this thread:
http://www.silvercart.org/forum/support-and-troubleshooting/show/830#post830

Greetings,

Roland

Re: Extending SilvercartShopConfigurationAdmin with extra managed objects

30 June 2012 at 3:29pm

Thanks for the link, i'll have a look at the plugin to pull some ideas for the mo.

I was actually planning on turning what I have done into a module for SilverCart but looks like you've go their first!

Once i've finished this project and got it working i'll have a play with the product_variants module and use that instead of my own and probably fork if I have some ideas.

Thanks for all you help.

Dom

Re: Extending SilvercartShopConfigurationAdmin with extra managed objects

30 June 2012 at 3:53pm

Okay, just read that you can only use with SilverCart 1.3 which I believe is not ready for production environments.

Do you guys know what the roadmap is for 1.3 just so that I can align with my projects as I think i'm going to stick with SilverCart as haven't done much Magento yet and it is a bigger beast to tame!

THanks

Dom

Re: Extending SilvercartShopConfigurationAdmin with extra managed objects

30 June 2012 at 5:45pm

Hi Dom,

we're already using SilverCart 1.3 in production for a couple of our customers. To be officially published, it needs polishing, documentation, some more test cases and such.

The official release is not too far away, but it's hard to come up with a date since we're very much engaged with client work these days. If all things go well, it might be in 4-6 weeks.

Cheers
Ramon

Re: Extending SilvercartShopConfigurationAdmin with extra managed objects

30 June 2012 at 9:07pm

Ramon,

Okay, not a problem. I'm so far with this project now that I don't want to switch but I will download 1.3 and play with the product variants module before my next project.

Thanks for all you guys help.

Dom