static function getProductsFromBasket($image = FALSE) { try { self::init(); $products = []; $productModel = new ProductTableModel(); $productModel->setTable('product as p'); $imageModel = new ImageTableModel(); foreach (self::$basket as $id => $quantity) { if ($id !== 'id' && is_int($id)) { $productModel->setId($id); $product = $productModel->readRecordsById('id', 'p.title, p.price')[0]; if ($image) { $imageModel->setId($id); $imageModel->setTable('image'); $product['image'] = $imageModel->readRecordsById('product_id', 'image', 'AND main = 1')[0]['image']; } $product['total'] = (int) $product['price'] * $quantity; if (is_array($product)) { $products[$id] = new Product($id, $quantity); $products[$id]->setData($product); } } } return $products; } catch (Exception $ex) { Basket::cleanBasket(); Basket::init(); header('Location: /'); exit; } }
public function cleanBasketAction() { header('Content-type: text/plain; charset=utf-8'); header('Cache-Control: no-store, no-cache'); header('Expires: ' . date('r')); echo Basket::cleanBasket(); }