Magento 2 – Save Product Description for Adminhtml Programmatically

adminhtmlmagento2product-attributerepositorystore-view

I cannot see description and short description attributes of the product in adminhtml after saving:

/** @var \Magento\Store\Model\StoreManagerInterface */
protected $_manStore;
/** @var \Magento\Catalog\Api\ProductRepositoryInterface */
protected $_repoProd;

/**
 * @param \Magento\Catalog\Api\Data\ProductInterface $product
 * @param string $name
 * @param string $desc
 * @param string $shortDesc
 * @param int $status
 * @param float $price
 * @param float $weight
 */
protected function _updateProduct($product, $name, $desc, $shortDesc, $status, $price, $weight)
{
    $product->setName($name);
    $product->setDescription($desc);
    $product->setShortDescription($shortDesc);
    $product->setStatus($status);
    $product->setPrice($price);
    $product->setWeight($weight);
    $this->_manStore->setCurrentStore("0");
    $this->_repoProd->save($product);
}

Description & short desc. attributes are saved for default store view instead (store_id=1):

enter image description here

How can I save these attributes visible for adminhtml using Magento way (not SQL direct updates)?

Best Answer

Set the current store by name:

$this->_manStore->setCurrentStore("admin");
Related Topic