0

I tried the below code in custom controller and cron job method [just load and save] after that I felt some issues

$product = $this->productRepository->getById(548); $this->productRepository->save($product); 

From Controller:

  • It change the product type from simple to virtual
  • No issues in product detail page
  • It removes the product from category page.

From Cron

  • It change the product type from simple to virtual
  • product detail page goes to 404 page not found
  • It removes the product from category page.

Update

I checked the same in Magento 2.1.3

From Cron

  • It change the product type from simple to virtual
  • No issues in product detail page
  • It removes the product from category page.

is there any limitation to use product repository in cron? or did I something wrong?

1
  • Did anybody report a core-issue on github for this? Commented Aug 2, 2017 at 11:11

1 Answer 1

0

I think you mismatch object to save a update product info. I tried blow code using corn its works for me.

 $product = $this->productRepository->getById($product_id); $product->setName("Testing"); $product->save(); 

Update:

I saw vendor/magento/module-catalog/Model/ProductRepository::save() same way to save product, its works for me.

I use

 $this->productRepository->save($target, $saveOptions = false); 

Instread of below line

 $this->productRepository->save($target); 
1
  • could you look at this module-catalog/Model/ProductRepository::save(), it seems like pass the product as the argument. by the way I tried you suggestion but it is not work in 2.0.8 Commented Feb 7, 2017 at 8:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.