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