I am new to solidity and I have an undeclared identifier error on lines 80 and 81. Can someone please explain what I am missing. I am trying to write a smart contract for adding and deleting products in an online store.

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.8.7;

contract Products {
    // Variable: Owner
    address public owner;
    // Variable: product Count
    uint productCount;

    // Event: 'State' with value 'ForSale'
    enum State { ForSale, Sold }
    // Struct: Product. name, id, MSP, sellingprice, state, seller
    struct Product {
        uint pID;
        string pName;
        uint MSP;
        uint sellingPrice;
        State  state;
        address  seller;
    mapping(uint => Product) products;
    // Events
    event ForSale(uint skuCount);
    event Sold(uint sku);
    event ProductAdded(uint _pID);
    event ProductAddedFailed(uint _pID);
    event ProductDeleted(uint _pID);
    event  ProductDeletionFailed(uint _pID);
    // Modifier: Only Owner see if msg.sender == owner of the contract
    modifier onlyOwner() {
        require(msg.sender == owner);
    // Define a modifier that verifies that the product is available
     modifier isProduct(uint _pID) {
        require(products[_pID].pID ==  _pID);
    // Define a modifier that checks if an product.state of a pID is ForSale
    modifier forSale(uint _pID) {
        require(products[_pID].state == State.ForSale);
      // Define a modifier that checks if an product.state of a pID is Sold
    modifier sold(uint _pID) {
        require(products[_pID].state == State.Sold);
    constructor () public {
        owner = msg.sender;
        productCount = 0;
    function addProduct(uint _pID, string memory _pName, uint _MSP, uint _sellingPrice, string memory _stateIs, address _seller) onlyOwner public returns (bool success) {
        // Increment product
        productCount = productCount + 1;
        // Emit the appropriate event
        emit ForSale(productCount);
        // Add the new item into inventory and mark it for sale
        products[productCount] = Product({pName: _pName, pID: productCount, MSP: _MSP, sellingPrice: _sellingPrice, state: State.ForSale, seller: msg.sender});
     function removeProduct(uint _pID) public onlyOwner returns (bool success) {
         product = products[_pID];
         if (product == _pID) {
             delete products[_pID];
             return true;
        return false;
//     function currentLevel(address userAddress) public constant returns (uint) {
//      return userLevel[userAddress];
// }

    function updateProduct() external onlyOwner {
    // fetch the price from external source at the time of execution
    function setMSP() onlyOwner external {
    function viewProduct(uint _pID) public view returns (uint pID, string memory pName, uint MSP, uint sellingPrice, string memory stateIs,address seller) { 
        uint state;
        pName = products[_pID].pName;
        pID = products[_pID].pID;
        MSP = products[_pID].MSP;
        sellingPrice = products[_pID].sellingPrice;
        state = uint(products[_pID].state);

        if( state == 0) {
            stateIs = "For Sale";

        if( state == 1) {
            stateIs = "Sold";

        seller = products[_pID].seller;

The code at line 80 doesn't make sense

     product = products[_pID];
     if (product == _pID) {

Probably the intentions were to read pID from products[_pID].

Something like this:

     uint product = products[_pID].pID;
     if (product == _pID) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.