Last active
February 19, 2018 17:28
-
-
Save laminbarrow/b8adc674bd8e396d3069 to your computer and use it in GitHub Desktop.
My Submission for the Silverstripe Code Competition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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