public function item($code, array $data) : bool { Properties::$items = $this->driver->select(md5('SystemCartData')) ?? NULL; if (empty(Properties::$items)) { return false; } $i = 0; foreach (Properties::$items as $row) { if (is_array($code)) { if (isset($row[key($code)]) && $row[key($code)] == current($code)) { $code = $row[key($code)]; } } $key = array_search($code, $row); if (!empty($key)) { array_splice(Properties::$items, $i, 1); if (count($data) !== count($row)) { foreach ($data as $k => $v) { $row[$k] = $v; } array_push(Properties::$items, $row); } else { array_push(Properties::$items, $data); } } $i++; } return $this->driver->insert(md5('SystemCartData'), Properties::$items); }
public function prices() : int { Properties::$items = $this->driver->select(md5('SystemCartData')) ?? NULL; if (empty(Properties::$items)) { return 0; } $total = 0; foreach (Properties::$items as $values) { $quantity = isset($values['quantity']) ? $values['quantity'] : 1; $price = isset($values['price']) ? $values['price'] : 0; $total += $price * $quantity; } return $total; }
public function item(array $product) : bool { // Ürünün adet parametresinin belirtilmemesi durumunda 1 olarak kabul edilmesi istenmiştir. if (!isset($product['quantity'])) { $product['quantity'] = 1; } // Sepettin daha önce oluşturulup oluşturulmadığına göre işlemler gerçekleştiriliyor. if ($sessionCart = $this->driver->select(md5('SystemCartData'))) { Properties::$items = $sessionCart; } array_push(Properties::$items, $product); $this->driver->insert(md5('SystemCartData'), Properties::$items); Properties::$items = $this->driver->select(md5('SystemCartData')); return true; }
public function item($code) : \stdClass { Properties::$items = ($sessionCart = $this->driver->select(md5('SystemCartData'))) ? $sessionCart : ''; if (empty(Properties::$items)) { return (object) []; } foreach (Properties::$items as $row) { if (!is_array($code)) { $key = array_search($code, $row); } else { if (isset($row[key($code)]) && $row[key($code)] == current($code)) { $key = $row; } } if (!empty($key)) { return (object) $row; } } }