Create product attribute value

EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResAttributeValue ecoResAttributeValue;
EcoResTextValue textValue;

ttsbegin;

textValue.clear();
textValue.textValue = "ThisIsATest";
ecoResAttributeValue.insert();

ecoResProductInstanceValue = EcoResProductInstanceValue::findByProduct(_product.RecId);

if (!ecoResProductInstanceValue)
{
    ecoResProductInstanceValue.clear();
    ecoResProductInstanceValue.product = _product.RecId;
    ecoResProductInstanceValue.insert();
}

ecoResAttributeValue = EcoResAttributeValue::findByInstanceAttribute(ecoResProductInstanceValue.RecId, _attribute.RecId);

if (!ecoResAttributeValue)
{
    ecoResAttributeValue.clear();
    ecoResAttributeValue.Value = _value.RecId;
    ecoResAttributeValue.InstanceValue = ecoResProductInstanceValue.RecId;
    ecoResAttributeValue.Attribute = _attribute.RecId;
    ecoResAttributeValue.insert();
}

ttscommit;

Leave a Comment