2

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)?

  • I must ask why you use underscores in front of your variable and function names. It's an old agreement between programmers that it means the variable or function is private. As of modern PHP versions, you can declare visibility as you are already doing. It is even officially deprecated: github.com/php-fig/fig-standards/blob/master/accepted/… – Jacques Dec 14 '16 at 15:15
  • I'm old, my code is old, my old code uses old agreements. – Alex Gusev Dec 15 '16 at 7:02
  • Whenever I edit an old module with such names I refactor it. Easily done with a proper EDI like PhpStorm. – Jacques Dec 19 '16 at 13:22
3

Set the current store by name:

$this->_manStore->setCurrentStore("admin");
  • yes, store code instead of store ID works, both for admin and default stores. – Alex Gusev Dec 16 '16 at 6:31
  • Old, but life saving ! Thanks for the tip. – Nicolas PERNOT Jul 13 '17 at 13:15

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.