My contract has structs for products, companies etc. The product struct has a 'quant' var to store quantity of the product ordered, and an array of quant size called clicks, that's supposed to track the no. of times that piece of product is checked. A function 'ShowPDetials' is supposed to retrieve that product's data from a mapping, and each time its called, it takes a piece number and adds 1 to that spot in the array, therefore tracking no. of checks on that particular piece.
The issue is that when i call PDetails, that spot in the array shows 1 but when i call it again, it still shows 1 instead of 2. If i call it again with another piece number, the new spot shows 1 and old spot turns back into 0. Basically, the count is working only once in one spot, and isn't actually changing the numbers by 1 and storing it that way to iterate higher in the future. My task is to update the piece's spot each time the function is called with given piece number. Code below:
struct Product {
uint PId;
string PName;
string Brand;
uint PQuant;
uint[] clicks;
SCSection[] SChain;
}
function StoreProduct(uint CompanyId, string memory ProductName, string memory PBrand, uint quant, uint FId, uint To_Id, string memory EmployeeId, string memory TaskDetails, string memory Current_Location) public returns(uint ProductId) {
ProductId = PmapSize+1;
Product storage p = Pmap[ProductId];
p.PId = ProductId;
p.PName = ProductName;
p.Brand = PBrand;
p.PQuant = quant;
for (uint256 i = 0; i < quant; i++) {
p.clicks.push(0);
}
p.SChain.push(SCSection(PmapSize+1, FId, To_Id, EmployeeId, TaskDetails, Current_Location, block.timestamp, block.timestamp));
PmapSize += 1;
Cmap[CompanyId].CProducts.push(ProductId);
}
function showPDetails(uint pid, uint piece_num) public returns(Product memory p) {
p = Pmap[pid];
p.clicks[piece_num-1] += 1;
}