0

Currently in My Site I have 2 Store

  1. Store 1
  2. Store 2

I Want copy Data "Store 2" to "Store 1"

Any help would be greatly appreciated.

  • You can enable 2nd store also in the product rather than transferring all to that store again. – Prasad D. Warnakulasuriya Feb 14 at 11:24
  • not understanding please explain briefly – Rk Rathod Feb 14 at 11:35
0

In vendor/magento/module-catalog/Controller/Adminhtml/Product/Save.php File You Can See copyToStores Function.

After Review This Function I Got The Solution.

<?php

use Magento\Framework\App\Bootstrap;

require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('global');

$productFactory = $obj->get('\Magento\Catalog\Model\ProductFactory');

$productCollection = $productFactory->create()->getCollection()
    ->getAllIds();
try {
    foreach ($productCollection as $productId) {
        $obj->create(\Magento\Catalog\Model\Product::class)
            ->setStoreId(1)
            ->load($productId)
            ->setStoreId(0)
            ->setCopyFromView(true)
            ->save();
        echo "Product Id :- " . $productId, PHP_EOL;
    }
} catch (\Exception $e) {
    echo "Error :- " . $e->getMessage(), PHP_EOL;
}
| improve this answer | |

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.