-
Notifications
You must be signed in to change notification settings - Fork 20
/
EcommerceStore.sol
49 lines (42 loc) · 1.71 KB
/
EcommerceStore.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
pragma solidity ^0.4.13;
contract EcommerceStore {
enum ProductStatus { Open, Sold, Unsold }
enum ProductCondition { New, Used }
struct Product {
uint id;
string name;
string category;
string imageLink;
string descLink;
uint auctionStartTime;
uint auctionEndTime;
uint startPrice;
address highestBidder;
uint highestBid;
uint secondHighestBid;
uint totalBids;
ProductStatus status;
ProductCondition condition;
}
mapping (address => mapping(uint => Product)) stores;
mapping (uint => address) productIdInStore;
uint public productIndex;
function EcommerceStore() public {
productIndex = 0;
}
function addProductToStore(string _name, string _category, string _imageLink,
string _descLink, uint _auctionStartTime,
uint _auctionEndTime, uint _startPrice, uint _productCondition) public {
require (_auctionStartTime < _auctionEndTime);
productIndex += 1;
Product memory product = Product(productIndex, _name, _category, _imageLink, _descLink, _auctionStartTime, _auctionEndTime,
_startPrice, 0, 0, 0, 0, ProductStatus.Open, ProductCondition(_productCondition));
stores[msg.sender][productIndex] = product;
productIdInStore[productIndex] = msg.sender;
}
function getProduct(uint _productId) view public returns (uint, string, string, string, string, uint, uint, uint, ProductStatus, ProductCondition) {
Product memory product = stores[productIdInStore[_productId]][_productId];
return (product.id, product.name, product.category, product.imageLink, product.descLink, product.auctionStartTime,
product.auctionEndTime, product.startPrice, product.status, product.condition);
}
}