Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webProject
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ignacio Hernández de la Fuente
webProject
Commits
7a37ce94
Commit
7a37ce94
authored
1 year ago
by
totoW
Browse files
Options
Downloads
Patches
Plain Diff
starting the shopping cart
parent
c69d5d6c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
html/data_treatment/AJAX/modifier_panier.php
+28
-0
28 additions, 0 deletions
html/data_treatment/AJAX/modifier_panier.php
startbootstrap-agency-gh-pages/index.php
+51
-24
51 additions, 24 deletions
startbootstrap-agency-gh-pages/index.php
with
79 additions
and
24 deletions
html/data_treatment/AJAX/modifier_panier.php
0 → 100644
+
28
−
0
View file @
7a37ce94
<?php
session_start
();
include
(
"../connect_database.php"
);
// Vérifier si l'article est déjà dans le panier
if
(
!
isset
(
$_SESSION
[
'panier'
]))
{
$_SESSION
[
'panier'
]
=
array
();
}
$itemName
=
$_POST
[
'itemName'
];
$itemPrice
=
$_POST
[
'itemPrice'
];
$itemQuantity
=
$_POST
[
'itemQuantity'
];
// Vérifier si l'article est déjà dans le panier
if
(
array_key_exists
(
$itemName
,
$_SESSION
[
'panier'
]))
{
// L'article est déjà dans le panier, mettez à jour la quantité
$_SESSION
[
'panier'
][
$itemId
][
'quantity'
]
+=
$itemQuantity
;
}
else
{
// L'article n'est pas encore dans le panier, ajoutez-le au panier et à la base de données
$_SESSION
[
'panier'
][
$itemName
]
=
array
(
'price'
=>
$itemPrice
,
'quantity'
=>
$itemQuantity
);
}
$response
=
array
(
'success'
=>
true
,
'message'
=>
'Article ajouté au panier avec succès'
);
echo
json_encode
(
$response
);
?>
This diff is collapsed.
Click to expand it.
startbootstrap-agency-gh-pages/index.php
+
51
−
24
View file @
7a37ce94
...
@@ -303,38 +303,41 @@ echo "Hello Mr./Ms. ".explode('@',$_SESSION["username"])[0].", you were last onl
...
@@ -303,38 +303,41 @@ echo "Hello Mr./Ms. ".explode('@',$_SESSION["username"])[0].", you were last onl
<!-- Portfolio Modals-->
<!-- Portfolio Modals-->
<!-- Portfolio item 1 modal popup-->
<!-- Portfolio item 1 modal popup-->
<?php
<?php
for
(
$i
=
0
;
$i
<
count
(
$articles
);
$i
++
){
for
(
$i
=
0
;
$i
<
count
(
$articles
);
$i
++
){
?>
?>
<div
class=
"portfolio-modal modal fade"
<?php
echo
'id="portfolioModal'
.
$i
.
'"'
?>
tabindex=
"-1"
role=
"dialog"
aria-hidden=
"true"
>
<div
class=
"portfolio-modal modal fade"
<?php
echo
'id="portfolioModal'
.
$i
.
'"'
?>
tabindex=
"-1"
role=
"dialog"
aria-hidden=
"true"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-content"
>
<div
class=
"close-modal"
data-bs-dismiss=
"modal"
><img
src=
"assets/img/close-icon.svg"
alt=
"Close modal"
/></div>
<div
class=
"close-modal"
data-bs-dismiss=
"modal"
><img
src=
"assets/img/close-icon.svg"
alt=
"Close modal"
/></div>
<div
class=
"container"
>
<div
class=
"container"
>
<div
class=
"row justify-content-center"
>
<div
class=
"row justify-content-center"
>
<div
class=
"col-lg-8"
>
<div
class=
"col-lg-8"
>
<div
class=
"modal-body"
<?php
echo
'id="modal'
.
$articles
[
$i
][
"itemName"
]
.
'"'
;
?>
>
<div
class=
"modal-body"
<?php
echo
'id="modal'
.
$articles
[
$i
][
"itemName"
]
.
'"'
;
?>
>
<!-- Project details-->
<!-- Project details-->
<h2
class=
"text-uppercase"
>
<?php
echo
$articles
[
$i
][
"itemName"
]
?>
</h2>
<h2
class=
"text-uppercase"
>
<?php
echo
$articles
[
$i
][
"itemName"
]
?>
</h2>
<!-- <p class="item-intro text-muted">Lorem ipsum dolor sit amet consectetur.</p> -->
<img
class=
"img-fluid d-block mx-auto"
src=
<?php
echo
"'../image/laptops/"
.
$articles
[
$i
][
"imagename"
]
.
"'"
;
?>
alt="..."
/>
<img
class=
"img-fluid d-block mx-auto"
src=
<?php
echo
"'../image/laptops/"
.
$articles
[
$i
][
"imagename"
]
.
"'"
;
?>
alt="..."
/>
<p>
<?php
echo
$articles
[
$i
][
"description"
];
?>
</p>
<p>
<?php
echo
$articles
[
$i
][
"description"
];
?>
</p>
<p>
<?php
echo
"Price: "
.
$articles
[
$i
][
"price"
]
.
" € <br>Quantity available: "
.
$articles
[
$i
][
"quantity"
];
?>
</p>
<p>
<?php
echo
"Price: "
.
$articles
[
$i
][
"price"
]
.
" € <br>Quantity available: "
.
$articles
[
$i
][
"quantity"
];
?>
</p>
<div
class=
"quantity"
>
<div
class=
"quantity"
>
<button
class=
"remove-button"
onclick=
"removeProduct(this)"
>
X
</button>
<button
class=
"remove-button"
onclick=
"removeProduct(this)"
>
X
</button>
<button
onclick=
"decrementQuantity(this)"
>
-
</button>
<button
onclick=
"decrementQuantity(this)"
>
-
</button>
<input
type=
"text"
value=
"1"
<?php
echo
'id="quantity'
.
$i
.
'"'
;
?>
>
<input
type=
"text"
value=
"1"
<?php
echo
'id="quantity"'
.
$i
;
?>
>
<button
onclick=
"incrementQuantity(this)"
>
+
</button>
<button
onclick=
"incrementQuantity(this)"
>
+
</button>
</div>
<button
class=
"btn btn-primary btn-xl text-uppercase"
type=
"button"
data-item-id=
"
<?php
echo
$i
;
?>
"
data-item-name=
"
<?php
echo
$articles
[
$i
][
"itemName"
];
?>
"
data-item-price=
"
<?php
echo
$articles
[
$i
][
"price"
];
?>
"
onclick=
"addToCart(this)"
>
Add to shopping cart
</button>
</div>
</div>
<button
class=
"btn btn-primary btn-xl text-uppercase"
type=
"button"
<?php
echo
'id = "buttonShoppingCart'
.
$i
.
'"'
;
?>
>
Add to shopping cart
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
};
?>
<?php
};
?>
<!-- Bootstrap core JS-->
<!-- Bootstrap core JS-->
<script
src=
"https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"
></script>
<script
src=
"https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"
></script>
...
@@ -380,6 +383,30 @@ echo "Hello Mr./Ms. ".explode('@',$_SESSION["username"])[0].", you were last onl
...
@@ -380,6 +383,30 @@ echo "Hello Mr./Ms. ".explode('@',$_SESSION["username"])[0].", you were last onl
// Initial update
// Initial update
updateOnlineUsers
();
updateOnlineUsers
();
function
addToCart
(
button
)
{
var
itemId
=
button
.
getAttribute
(
"
data-item-id
"
);
var
itemName
=
button
.
getAttribute
(
"
data-item-name
"
);
var
itemPrice
=
button
.
getAttribute
(
"
data-item-price
"
);
var
itemQuantity
=
document
.
getElementById
(
"
quantity
"
+
itemId
).
value
;
// Faire une requête Ajax pour ajouter l'article au panier
$
.
ajax
({
url
:
'
../html/data_treatment/AJAX/modifier_panier.php
'
,
method
:
'
POST
'
,
data
:
{
itemName
:
itemName
,
itemPrice
:
itemPrice
,
itemQuantity
:
itemQuantity
},
dataType
:
'
json
'
,
success
:
function
(
response
)
{
alert
(
response
.
message
);
// Vous pouvez personnaliser cela en fonction de votre logique
},
error
:
function
(
error
)
{
console
.
error
(
error
);
}
});
}
</script>
</script>
</body>
</body>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment