CommerceCartProviderSession.class.php in Commerce Core 7
File
modules/cart/plugins/cart_provider/CommerceCartProviderSession.class.php
View source
<?php
class CommerceCartProviderSession implements CommerceCartProviderInterface {
const COMPLETED = 'commerce_cart_completed_orders';
const CART = 'commerce_cart_orders';
public function cartDelete($order_id = NULL, $completed = FALSE) {
$key = $completed ? self::COMPLETED : self::CART;
if (!empty($_SESSION[$key])) {
if (!empty($order_id)) {
$_SESSION[$key] = array_diff($_SESSION[$key], array(
$order_id,
));
}
else {
unset($_SESSION[$key]);
}
}
}
public function cartExists($order_id = NULL, $completed = FALSE) {
$key = $completed ? self::COMPLETED : self::CART;
if (!empty($order_id)) {
return !empty($_SESSION[$key]) && in_array($order_id, $_SESSION[$key]);
}
else {
return !empty($_SESSION[$key]);
}
}
public function cartOrderIds($completed = FALSE) {
$key = $completed ? self::COMPLETED : self::CART;
return empty($_SESSION[$key]) ? array() : $_SESSION[$key];
}
public function cartSave($order_id, $completed = FALSE) {
$key = $completed ? self::COMPLETED : self::CART;
if (empty($_SESSION[$key])) {
$_SESSION[$key] = array(
$order_id,
);
}
elseif (!in_array($order_id, $_SESSION[$key])) {
$_SESSION[$key][] = $order_id;
}
}
}