6

How can I set the name of a product in a specific language (store view)?

3
  • Have you tried setting $product->setStoreId($anotherStoreId); before saving? Mar 25, 2016 at 20:20
  • Thanks! I'll try that in a couple of days. But I can tell you now: it feels weird because it's not part of ProductInterface. Mar 26, 2016 at 0:17
  • no reply? how to do that?
    – LucScu
    Dec 28, 2016 at 10:06

1 Answer 1

0

Please try with below code, to create custom script in root, than add below code in script :

<?php

use Magento\Framework\App\Bootstrap;

require __DIR__ . '/../app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);

$obj = $bootstrap->getObjectManager();

$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

$product = $obj->get('Magento\Catalog\Model\Product');

$product
    ->setName('demo name ')
    ->setSku('sku-name')
    ->setPrice(0.00)
    ->setStatus(2)// Disabled
    ->setWebsiteIds([1, 2])
    ->setVisibility(4)
    ->setAttributeSetId($product->getDefaultAttributeSetId())
    ->setTypeId('simple')
    ->save();

echo "Saved product ID " . $product->getId() . "\n";

please check its work for me...

1
  • It will save the same value for all store view. Dec 7, 2021 at 6:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.