function CourseObjectUbercart::take in Course 3.x
Display the add to cart button, or a message that it was already purchased.
Implementing classes should override me if a custom display is desired.
Overrides CourseObject::take
File
- modules/
course_uc/ src/ Plugin/ course/ CourseObject/ CourseObjectUbercart.php, line 36
Class
- CourseObjectUbercart
- Plugin annotation @CourseObject( id = "ubercart", label = "Payment", )
Namespace
Drupal\course_uc\Plugin\course\CourseObjectCode
function take() {
$user = Drupal::currentUser();
$bypass = Drupal::config('course_uc.settings')
->get('bypass_checkout');
if (!($this
->getNode()->sell_price > 0) && $bypass) {
$this
->getFulfillment($user)
->setComplete(1)
->save();
}
if ($this
->getFulfillment($user)
->isComplete()) {
return "You've already purchased this activity.";
}
else {
$node_view = node_view($this
->getNode());
$atc = t('You must purchase this course before proceeding.') . \Drupal::service('renderer')
->render($node_view['display_price']) . \Drupal::service('renderer')
->render($node_view['add_to_cart']);
if (!$atc) {
// The add to cart form was hidden?
return "Something isn't right...";
}
else {
return [
'#markup' => $atc,
];
}
}
}