F
F
Faber Estello2015-03-27 13:36:08
JavaScript
Faber Estello, 2015-03-27 13:36:08

How to create an online shopping cart with javascript?

Task:
1. Write a functional for the shopping cart of an online store.
Create an object with properties and methods (the list of goods already in the cart, the number of goods in the cart; adding/removing goods, calculating the amount of the cost ... ). Request\output - modal window.
This I can do!
But I don't understand. requirements:
2. The list of available products must be declared in a global array variable. The array should store OBJECTS with two fields: price and name.
How to implement it?!
I’m starting to learn js and I don’t fully understand how objects can be stored in an array, how to add and retrieve them there ?!
PS: If someone can, then you can solve the whole problem!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Talalaev, 2015-03-27
@senselessV7

Most likely they were talking about an array of Object literals, read it here , everything is simple.
You will have something like this:

var tovary = [
    {name:"Кукла", price:'55'},
    {name:"Машинка", price:'300'},..

O
Online store without Php, 2019-01-07
@HEEG

Do not store product data in an array of a javascript file. This data will not be indexed by search engines. simplecartjs.org here is an example of a store on it novye-podarki.ru/6_7_0 collects data from the page from the view structure

<div class="simpleCart_shelfItem" style="left: 171px; top: 0px;">
          <span class="item_price">$59.99</span>
          <a href="javascript:;" class="item_add">Add to Cart</a>
          <img src="/assets/images/nhl12.png" alt="Sample Product" class="item_image">
          <span class="item_name">NHL 12</span>
</div>

when opening the page, javascript numbers all product buttons by id (for example
<input class="item_add" type="button" value="в корзину" id="s6">
see example) when you click on this button, all data from the parent is collected and added to the basket and Local Storage.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question