Prevet vseme ja neruske nu chetajo po ruske nu not peshat neochen.
Hi everyone I'm not Russian, I can read Russian but writing is problem for me.
Eta tolka export paka nu sdelaju i import jesle kamu nebut enteresna.
Eta tolko nacheal patom mozhete raseret.
This is only export at the moment I will make import if anyone interested
This is only starting point which you can expand.
Mne nekagda neravewlos magento export/import dle etava ja vsegda delal scodam po bolshe vazmozhnaste tak
I newer liked magento import/export for that reson I always make code to do so
A pervich me sdelaiem nash malenke app shto bab patkliuchetsa v magento
We will make small conection app to magento
Dle etava nam nuzhno sdelat Novaju papku e php document
For that we will need to make new folder with php file inside
MagentoROOT/scripts/abstract.php
Nutre php documente me palazhem etat script (mnoga abesnet nu jesle vaprosafr jes pazhalsta)
Iside php file we eill paste this script ( alot to explain here but if you have any quastions please ask)
Код:
<?php
use \Magento\Framework\AppInterface as AppInterface;
use \Magento\Framework\App\Http as Http;
use Magento\Framework\ObjectManager\ConfigLoaderInterface;
use Magento\Framework\App\Request\Http as RequestHttp;
use Magento\Framework\App\Response\Http as ResponseHttp;
use Magento\Framework\Event;
use Magento\Framework\Filesystem;
use Magento\Framework\App\AreaList as AreaList;
use Magento\Framework\App\State as State;
abstract class AbstractApp implements AppInterface
{
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager,
Event\Manager $eventManager,
AreaList $areaList,
RequestHttp $request,
ResponseHttp $response,
ConfigLoaderInterface $configLoader,
State $state,
Filesystem $filesystem,
\Magento\Framework\Registry $registry
) {
$this->_objectManager = $objectManager;
$this->_eventManager = $eventManager;
$this->_areaList = $areaList;
$this->_request = $request;
$this->_response = $response;
$this->_configLoader = $configLoader;
$this->_state = $state;
$this->_filesystem = $filesystem;
$this->registry = $registry;
}
public function launch()
{
$this->run();
return $this->_response;
}
abstract public function run();
public function catchException(\Magento\Framework\App\Bootstrap $bootstrap, \Exception $exception)
{
return false;
}
}
?>
A teper nam nuzan file catori budet paselat vapros iz nash nowe document abstract.php ( mozhat bet zapros zakazos producta i neskalko eschio veshe) na etat ras tolka producta exporta
Now we need other fille which will be requesting data from our abstract.php ( that can be used to request orders or products few things more to) for this time only products export
Novi documnet buded v papke MagentoROOT/scripts/index.php
New document will be made MagentoROOT/scripts/index.php
Nutre php documente me palazhem etat script (mnoga abesnet nu jesle vaprosafr jes pazhalsta)
Iside php file we eill paste this script ( alot to explain here but if you have any quastions please ask)
Код:
<?php
require dirname(__FILE__) . '/../app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
require dirname(__FILE__) . '/abstract.php';
class Getapp extends AbstractApp
{
public function run()
{
$this->_objectManager->get('Magento\Framework\Registry')->register('isSecureArea', true);
$this->_state->setAreaCode('frontend');
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $_objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();
$data= "Product ID, Product Name, Product Weight\n";
$i =1;
foreach ($collection as $product){
//nam nuzhno sdelat array ez date = making arry from data
$data .= $product->getId().",";
$data .= $product->getName().",".$product->getWeight().",".$product->getPrice();
$data .="\n";
$i++;
}
//a teper delaem csv iz date / Time to make csv with data
header("Content-Type: application/csv");
$csv_filename = 'data.xlsx';
header("Content-Disposition:attachment;filename=".$csv_filename);
$fd = fopen ($csv_filename, "w");
fputs($fd,$data);
fclose($fd);
echo $data;
die();
}
}
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Getapp');
$bootstrap->run($app);
?>
Test prashol pered Magento ver. 2.1.7
Test was done on Magento ver. 2.1.7