Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5 feature/product page #9

Open
wants to merge 1 commit into
base: 4-feature/browse-products
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions public/js/product-detail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function productDetail() {
var url = new URL(window.location);
var urlParams = new URLSearchParams(url.search);
var productId = urlParams.get('product');

if (!productId) {
window.location = '/';
}

(function renderProduct() {
var productsCollection = firebase.firestore().collection('products');
productsCollection.doc(productId).get().then(function(snapshot) {
if(!snapshot.exists) {
window.location = '/';
}
var product = snapshot.data();

$('#image-preview').attr('src', product.imageUrl);
$('#name').text(product.name);
$('#description').text(product.description);
$('#price').text('P ' + parseFloat(product.price).toFixed(2));
$('#checkout').attr('href', '/checkout.html?product=' + productId);

$('#product-detail').removeClass('hide');
$('#loader').addClass('hide');
});
})();
}

$(document).ready(productDetail);
30 changes: 24 additions & 6 deletions public/product.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://www.gstatic.com/firebasejs/5.5.8/firebase.js"></script>
<script src="/js/firebase-config.js"></script>
</head>

<body class="row">
Expand All @@ -30,31 +32,47 @@
</div>
<!-- End Navbar -->

<div class="container col m6 offset-m3 s12 section">
<div class="container col m6 offset-m3 s12 section hide" id="product-detail">
<br>
<!-- Start Product Info -->
<div class="row">
<div class="col m6 s12">
<img src="/images/g.jpg" width="100%">
<img src="/images/g.jpg" width="100%" id="image-preview">
</div>
<div class="col m6 s12">
<h4>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</h4>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam mollitia officia, tempora molestiae ducimus molestias dolor impedit. Et ut ex, placeat vero earum facilis tempore, nemo in quis illum id.
<h4 id="name">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</h4>
<p id="description">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam mollitia officia, tempora molestiae ducimus molestias dolor impedit. Et ut ex, placeat vero earum facilis tempore, nemo in quis illum id.</p>
</div>
</div>
<!-- End Product Info -->

<!-- Start Order Button -->
<div class="center-align">
<h5>P 200.00</h5>
<a class="waves-effect waves-light btn-large teal darken-2" href="/checkout.html"><i class="material-icons left">add_shopping_cart</i>Place Order</a>
<h5 id="price">P 200.00</h5>
<a class="waves-effect waves-light btn-large teal darken-2" id="checkout" href="/checkout.html"><i class="material-icons left">add_shopping_cart</i>Place Order</a>
</div>
<!-- End Order Button -->
</div>

<br>
<div class="center-align" id="loader">
<div class="preloader-wrapper big active">
<div class="spinner-layer spinner-blue-only">
<div class="circle-clipper left">
<div class="circle"></div>
</div><div class="gap-patch">
<div class="circle"></div>
</div><div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
</div>

<script src="/js/jquery.js"></script>
<script src="/js/materialize.min.js"></script>
<script src="/js/nav.js"></script>
<script src="/js/firestore-config.js"></script>
<script src="/js/product-detail.js"></script>
</body>
</html>