Change value custom product Tag

Any idea to display all product and just certain or one custom product tag list editor at entity screen for change value from Yes to No
i have idea to make item can’t order when custom product tag, name “Aktif” equal No.
if i give permit product tag list editor to user level like manager, i am scare they will change all custom product tag.

There is no Action for updating a Product Tag and there is no API command for it either.

So there is no mechanism to set or change a Product Custom Tag value other than using the Product Tag Editor or directly modifying the DB (ie. running SQL Script via JScript).

there is sample script for do that please

No sample to do that. Will take time to develop since the Tags are stored in JSON format. I can put something together but it won’t happen until next week - no time right now.

Thank You, i still try test it, but i get problem with json format to manage it.

ok

Here is a start… EDIT: fully working!

function productTagUpdate(productName,tagName,tagValue) {
  // for testing
  //productName = 'Barena';
  //tagName = 'productType';
  //tagValue = 'Drink';
  
  var productId = 0;
  
  var SQL = "SELECT [Id] FROM [MenuItems] WHERE [Name] = '" + productName + "'";
  
  var sqlResult = sql.Exec(SQL);

  if (typeof sqlResult[0] === 'undefined') {
    dlg.ShowMessage('Could not find Product: ' + productName);
    return 1;
  }
  
  productId = sqlResult[0];
  
  SQL = "SELECT [CustomTags] FROM [MenuItems] WHERE [Id] = " + productId;
  sqlResult = sql.Exec(SQL);

  if (typeof sqlResult[0] === 'undefined') {
    dlg.ShowMessage('Could not find Product with Id: ' + productId);
    return 1;
  }

  // convert [CustomTags] JSON String to an Arry of Objects
  var jsonObj = JSON.parse(sqlResult[0]);
  
  var foundTag = false;
  
  var op = "productName:" + productName + "\r";
  
  // iterate the Array of Objects looking for the tagName
  for (var t=0; t<jsonObj.length; t++) {
  
    // if we find the tagName, replace the tagValue
    if (jsonObj[t].TN == tagName) {
      dlg.ShowMessage("Found Tag '" + tagName + "' for Product '" + productName + "'.\rChanging value from '" + jsonObj[t].TV + "' to '" + tagValue + "'");
      jsonObj[t].TV = tagValue;
      foundTag = true;
    }
    
    op += jsonObj[t].TN;
    op += ":";
    op += jsonObj[t].TV;
    op += "\r";
  }
  
  var newJSON = "";
  
  if (foundTag) {
    // convert the Array of Objects back into a JSON String
    newJSON = JSON.stringify(jsonObj);
    // do SQL UPDATE
    SQL = "UPDATE [MenuItems] SET [CustomTags] ='" + newJSON + "'  WHERE [Id] = " + productId;
    sqlResult = sql.Exec(SQL);
    dlg.ShowMessage("Executed SQL:\r"+SQL);
    return 0;
  } else {
    dlg.ShowMessage("FAILED to find Tag '" + tagName + "' for Product '" + productName + "'");
    return 1;
  }
  
  return op;
}

2 Likes

Should we request it as a feature in future releases? I found that it could very helpful.

@QMcKay are you…

  1. A time travelling ninja
  2. Always keen to solve a problem
  3. All round awesome and providing amazing support and insight to all of us
1 Like

I don’t sleep much and… Yes. Yes I am. :stuck_out_tongue_winking_eye:

3 Likes

Hi @QMcKay Excellent script, I’m trying to use it with dlg.EditValue(“product name;;;ON”,""); so can be automatized for every product can you please enlight me

This part of the Script:

// if we find the tagName, replace the tagValue
    if (jsonObj[t].TN == tagName) {
      dlg.ShowMessage("Found Tag '" + tagName + "' for Product '" + productName + "'.\rChanging value from '" + jsonObj[t].TV + "' to '" + tagValue + "'");
      jsonObj[t].TV = tagValue;
      foundTag = true;
    }

This line from above:

      jsonObj[t].TV = tagValue;

Add a line before it:

      tagValue = dlg.EditValue("product name;;;ON","");
      jsonObj[t].TV = tagValue;

Thank you for your script. I wanted to used it for product stop-list tag that can be used to set quantity of each product that can be sold and when that tag reaches 0 it will not allow to put that product in ticket. This script allows me to decrease stopTag quantity only once when ticket is opened, not everytime product placed in ticket. When ticket is reopened and product is placed to ticket, again it decreases tag quantity only one time . What can be the issue? Or is there any built-in SambaPOS function to make it work?

If your not getting much response maybe try the paid support route? QMcKay is no longer with us so he will not personally reply.

I i was not familiar with paid support. Now, i know. Thanks

All you want is it to limit products so if you try to add to ticket it wont allow it and it shows no product available right? Do you use inventory?

Yes. But without using warehouse.

So you are not using inventory then?

Right. I wanted to implement it with product tag, so, if user needs to limit some items sales, he/she needs to enter a quantity to product tag, without creating inventory items and creating receipes for them. Product tag would make it much easier, i think.