0

I have a custom product attribute that gets populated from a csv import. If the relevant field has a value, that value is applied to the product's attribute. However if that field is empty, the value should be removed. This is what I currently have, but it's not removing the value:

if (trim($prod[$fields['SOPDiscountCode']]) != ''){
    $newproduct->setProductDiscountCode($discounts[$prod[$fields['SOPDiscountCode']]]);
}else{
    $newproduct->setProductDiscountCode(0);
}

I'm not sure of the correct way to remove the value:

$newproduct->setProductDiscountCode('');

or

$newproduct->setProductDiscountCode();

for example?

0

Try

$newproduct->unsetProductDiscountCode();

or

$newproduct->setProductDiscountCode(null);

One of those should do the trick.

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.