function course_uc_check_cart in Course 3.x
Same name and namespace in other branches
- 8.3 modules/course_uc/course_uc.module \course_uc_check_cart()
- 8.2 modules/course_uc/course_uc.module \course_uc_check_cart()
- 7.2 modules/course_uc/course_uc.module \course_uc_check_cart()
- 7 modules/course_uc/course_uc.module \course_uc_check_cart()
Check if a course is already in a user's cart.
Note that we have to check if the user is purchasing the course for someone else.
2 calls to course_uc_check_cart()
- course_commerce_uc_add_to_cart in modules/
course_commerce/ course_commerce.module - Implements hook_add_to_cart().
- course_uc_uc_add_to_cart in modules/
course_uc/ course_uc.module - Implements hook_add_to_cart().
File
- modules/
course_uc/ course_uc.module, line 289
Code
function course_uc_check_cart(Node $node, AccountInterface $user, $data = array()) {
$contents = Drupal::entityTypeManager()
->getStorage('uc_cart_item')
->loadByProperties([
'cart_id' => $user
->id(),
]);
// Use the uid on behalf if provided.
$uid = isset($data['uid']) ? $data['uid'] : $user
->id();
foreach ($contents as $item) {
// Check if user already has course in their cart, if the user already is
// purchasing this course for somebody else.
/* @var $item CartItem */
if ($item
->get('nid')
->getString() == $node
->id() && (!isset($item->data['uid']) || $item->data['uid'] == $uid)) {
return TRUE;
}
}
}