diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3668dc8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/public/assets/add-to-cart.svg b/public/assets/add-to-cart.svg index 2581f42..b8c7099 100644 --- a/public/assets/add-to-cart.svg +++ b/public/assets/add-to-cart.svg @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/public/assets/scripts.js b/public/assets/scripts.js index 999054a..77f2e50 100644 --- a/public/assets/scripts.js +++ b/public/assets/scripts.js @@ -78,4 +78,35 @@ function toggleCart() document.getElementById('cart-nav').classList.toggle('active') document.getElementById('cart-backdrop').classList.toggle('active') +} + +function createCookie(name,value,days) { + let expires; + if (days) { + let date = new Date(); + date.setTime(date.getTime() + (days * 24 * 60 * 60 *1000)); + expires = "; expires=" + date.toLocaleString(); + } else { + let expires = ""; + } + document.cookie = name + "=" + JSON.stringify(value) + expires + "; path=/"; +} + +function readCookie(name) { + let nameEQ = name + "="; + let ca = document.cookie.split(';'); + for(let i=0;i < ca.length;i++) { + let c = ca[i]; + while (c.charAt(0)==' ') { + c = c.substring(1,c.length); + } + if (c.indexOf(nameEQ) == 0) { + return JSON.parse(c.substring(nameEQ.length,c.length)); + } + } + return null; +} + +function eraseCookie(name) { + createCookie(name,"",-1); } \ No newline at end of file diff --git a/src/Controllers/Manage/ManageDVDController.php b/src/Controllers/Manage/ManageDVDController.php index 520d141..1ba867e 100644 --- a/src/Controllers/Manage/ManageDVDController.php +++ b/src/Controllers/Manage/ManageDVDController.php @@ -150,8 +150,8 @@ private function postToDvdModel(DVDModel $model) $model->Quantity = $_POST["Quantity"]; $model->Price = $_POST["Price"]; $model->Year = $_POST["Year"]; - $model->TypeId = !is_null($_POST["TypeId"]) ? intval($_POST["TypeId"]) : null; - $model->GenreId = !is_null($_POST["GenreId"]) ? intval($_POST["GenreId"]) : null; + $model->TypeId = isset($_POST["TypeId"]) ? intval($_POST["TypeId"]) : null; + $model->GenreId = isset($_POST["GenreId"]) ? intval($_POST["GenreId"]) : null; $model->Image = $_POST["Image"]; } } diff --git a/src/Utils/Components/FormSelectComponent/FormSelectComponent.template.php b/src/Utils/Components/FormSelectComponent/FormSelectComponent.template.php index a9cdc13..5dca628 100644 --- a/src/Utils/Components/FormSelectComponent/FormSelectComponent.template.php +++ b/src/Utils/Components/FormSelectComponent/FormSelectComponent.template.php @@ -3,7 +3,7 @@ required?"required":""; ?> readOnly?"readOnly":""; ?>> - Select a value + Select a value availableValues as $item): ?> Id == $this->value ? "selected" : ""; ?>> Name; ?> diff --git a/src/Views/DVD/DVDView.js b/src/Views/DVD/DVDView.js index e69de29..2826668 100644 --- a/src/Views/DVD/DVDView.js +++ b/src/Views/DVD/DVDView.js @@ -0,0 +1,33 @@ +function addToCart(pId, pName) +{ + let cart = readCookie("cart"); + + if(cart && cart.articles) + { + let existingArticle = cart.articles.find(x => x.id === pId); + if(existingArticle !== undefined) + { + existingArticle.quantity++; + } + else + { + cart.articles.push({ + id: pId, + name: pName, + quantity: 1 + }) + } + } + else + { + cart = { + articles: [{ + id: pId, + name: pName, + quantity: 1 + }] + } + } + + createCookie("cart", cart, 30); +} \ No newline at end of file diff --git a/src/Views/DVD/DVDView.php b/src/Views/DVD/DVDView.php index 5b8550b..5ffa842 100644 --- a/src/Views/DVD/DVDView.php +++ b/src/Views/DVD/DVDView.php @@ -21,7 +21,7 @@ public function render(): void { $layoutData = new LayoutViewModel(); $layoutData -> pageSubTitle = $this->subTitle; - parent::renderLayout($layoutData, $this->data); + parent::renderLayout($layoutData, $this->data, true); } } } \ No newline at end of file diff --git a/src/Views/DVD/DVDView.style.css b/src/Views/DVD/DVDView.style.css index b17e86c..3c11673 100644 --- a/src/Views/DVD/DVDView.style.css +++ b/src/Views/DVD/DVDView.style.css @@ -4,6 +4,7 @@ } .product-detail { + position: relative; margin: auto; display: flex; flex-direction: column; @@ -37,4 +38,16 @@ .details h3 { text-align: left; color: white; +} + +.button { + position: absolute; + right: 0; + top: 5px; + padding: 10px 20px; + border: none; + border-radius: 4px; + background-color: #27994e; + color: white; + cursor: pointer; } \ No newline at end of file diff --git a/src/Views/DVD/DVDView.template.php b/src/Views/DVD/DVDView.template.php index 433b27f..9903e4e 100644 --- a/src/Views/DVD/DVDView.template.php +++ b/src/Views/DVD/DVDView.template.php @@ -3,6 +3,9 @@ echo $data->dvd->LocalTitle; ?> + + + @@ -47,5 +50,7 @@ dvd->Note; ?> + + diff --git a/src/Views/Layout/LayoutView.style.css b/src/Views/Layout/LayoutView.style.css index f417be5..5ab3cb5 100644 --- a/src/Views/Layout/LayoutView.style.css +++ b/src/Views/Layout/LayoutView.style.css @@ -28,6 +28,7 @@ header h1 a { } main { + position: relative; display: flex; flex: 9; flex-direction: column;