Skip to content

Instantly share code, notes, and snippets.

@laminbarrow
Last active February 19, 2018 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laminbarrow/b8adc674bd8e396d3069 to your computer and use it in GitHub Desktop.
Save laminbarrow/b8adc674bd8e396d3069 to your computer and use it in GitHub Desktop.
My Submission for the Silverstripe Code Competition
<?php
/**
* Code submitted by Lamin Barrow (@laminbarrow)
*/
class MarketPlaceProduct extends BaseProduct
{
private static $db = array(
'AdditionalDetails' => 'MultiValueField',
);
private static $has_one = array(
'Owner' => 'Member',
);
private static $dependencies = array(
'marketPlacePaymentService' => '%$MarketPlacePaymentService',
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->push(KeyValueField::create('AdditionalDetails', 'Additional Details (Key and Value)'));
return $fields;
}
public function buy()
{
return $this->marketPlacePaymentService->buy($this);
}
public function sell()
{
return $this->marketPlacePaymentService->sell($this);
}
public function processRender(SS_HTTPRequest $request)
{
if ($marketPlaceProduct = MarketPlaceProduct::get()->byID($request->param('ID'))) {
if (Director::is_Ajax()) {
return $marketPlaceProduct->renderWith('MarketPlaceProduct');
}
return $marketPlaceProduct->renderWith('MarketPlaceProduct', 'Page');
}
return ErrorPage::response_for(404);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment