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?

1 Answer 1

0

Try

$newproduct->unsetProductDiscountCode(); 

or

$newproduct->setProductDiscountCode(null); 

One of those should do the trick.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.