Article will focus on implementation user cart icon with display of number and total price for items in main menu page. For further visual improvement we use graphical icon with text. Also sell icon with link to sellitem page is added.
Expectation from cart icon display
Cart notification icon is small graphic remainder of number of items added into a cart and actual total price for pay.
Our implementation will offer these functionalities:
contain graphic depiction of cart
show total number of items in a cart
show total price that will be paid for all items in a cart
must be includable into a other bazaar pages
cart must be visible only for registered and loged in users
Visual implementations of cart icon
Next part provide further depiction of cart icon shown in upper part of logged in user pages.
Code of the cart icon and including into a page
In a next rows you can look at way how cart icon is implemented in script named cart_icon.php.
die(„ERROR: Could not connect to database – stage of article listing. “ . mysqli_connect_error());
}
// read all rows (data) from guestbook table in „test“ database
$sql = „SELECT * FROM bazaar_item WHERE cart_number=“.“‚$_user_id'“.“ ORDER BY item_id ASC „; // read items marked in cart_number with appropriate users_id
Our code obtain users_id of currently logged in user from session variable, then go through all rows in bazaar_item table that are marked by users_id (they are added into a cart). If current row id marked by users_id of currently logged user then increment number of items and accumulate price of items by price of that item.
In next part of code snippet is cart_icon.php included in headermenu.php and header menu is included (required_once) in all pages that in some way implement menu. In this way we created decomposition and make our code much more modular.
require_once(‚sell_icon.php‘); // graphic menu item for selling your items
echo ‚<a class=“navbar-brand“ href=“rss.php“><img src=“./images/rss.png“ width=“45″></a>‘; //rss feed link
require_once(‚cart_icon.php‘); // small cart icon in menu
} else { // visitor without login
echo ‚<div id=“menu“>‘;
echo ‚<a class=“navbar-brand“ href=“login.php“><img id=“menuimage“ src=“./images/menu_login.png“> Log In </a>‘;
echo ‚<a class=“navbar-brand“ href=“signup.php“><img id=“menuimage“ src=“./images/menu_signup.png“> Sign Up for better membership! </a>‘;
echo ‚<a class=“navbar-brand“ href=“index.php“><img width=“150″ src=“./images/bazaarheader.png“> Bazaar – best items for a best prices!</a>‘;
echo ‚</div >‘;
};
?>
And final way how headermenu.php is called in our bazaar pages
… code omitted …
<body>
<nav class=“navbar „>
<div id=“header_container_1060″>
<div class=“navbar-header“>
<?php
require_once(‚headermenu.php‚); // including menu items
?>
</div>
</div>
</nav>
<div class=“container“ id=“container_1060″>
… code omitted …
Conclusion
Cart_icon.php fulfill our expectation for good way how to constantly inform our customer about all items added to buy. Problem decomposition by implementing them into a headermenu.php and text to all pages is solution for further code maintainability.
Full code of bazaar app can be obtained from github here.
We inform you that we use cookies and other technologies on this site to function and improve the operation of the site, ensure it, provide social networking features, personalize content and ads to users, and analyze traffic and user behavior. For more information, please read our Terms of Use and Cookies. You can prevent cookies from being processed by changing the settings in your Internet browser.OkPrivacy policy