5

I have an import script which imports configs and the variants.

There is set the special price if some is set in my import XML document. If no special price is set, i try to remove the special price. - But it do not work! - The special price is already set, after save!

if ($oProductGroupVariantProductItem->getSpecialpriceBrutto() > 0) {
    $oSimpleProduct->setSpecialPrice($oProductGroupVariantProductItem->getSpecialpriceBrutto());
} else {
    $oSimpleProduct->setSpecialPrice('');
}

what i am doing wrong?

Thanks Andre

4
  • try with unset($oProductGroupVariantProductItem->getSpecialpriceBrutto()) Jan 20, 2017 at 13:06
  • ??? - I want to unset the "$oSimpleProduct" special price value !! Not my Import Data Value Object! Jan 20, 2017 at 13:10
  • you can do this in else case of your condition Jan 20, 2017 at 13:10
  • Any luck with this? Feb 21, 2017 at 9:32

2 Answers 2

9

Saving the price and forcibly update the product attribute using the resource model worked in my situtation:

$product->setSpecialPrice(null);
$product->getResource()->saveAttribute($product, 'special_price');

Note: Make sure a $product object has store_id = 0. special_price attribute is global attribute. If store_id won't be 0, this method won't work, then you will try to unset special_price.

1

You just need to save the product after you updated the attributes.

Try this:

$oSimpleProduct->save();
1
  • 1
    Don't use deprecated save()-methods on legacy models. Use the repository instead (see ProductRepositoryInterface::save()). May 17, 2017 at 12:13

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.