state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML); $store0Collection = $this->productCollectionFactory->create() ->setStoreId(0) ->addAttributeToFilter('protocols_documentation', ['neq' => 'NULL']) ->load(); $store1Collection = $this->productCollectionFactory->create() ->setStoreId(1) ->addAttributeToFilter('protocols_documentation', ['neq' => 'NULL']) ->load(); foreach ($store1Collection as $item) { /* @var $item \Magento\Catalog\Model\Product */ /* @var $product \Magento\Catalog\Model\Product */ $product = $store0Collection->getItemById($item->getId()); $output->writeln('store 1 product: '. $item->getSku()); $output->writeln('store 0 product: '. $product->getSku()); $output->writeln(''); // $output->writeln('store 1 protocols_documentation:'); // $output->writeln($item->getData('protocols_documentation')); // // $output->writeln('store 0 protocols_documentation:'); // $output->writeln($product->getData('protocols_documentation')); $item->setData('protocols_documentation', $product->getData('protocols_documentation')); $item->setData('_edit_mode', true); try { $this->productRepository->save($item); } catch (\Exception $e) { $output->writeln('product: '.$item->getSku().'exception: '.$e->getMessage().''); } } return Command::SUCCESS; } }