Frage

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.

War es hilfreich?

Lösung

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;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top