本文整理匯總了PHP中Magento\CatalogImportExport\Model\Import\Product::getUploader方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::getUploader方法的具體用法?PHP Product::getUploader怎麽用?PHP Product::getUploader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\CatalogImportExport\Model\Import\Product
的用法示例。
在下文中一共展示了Product::getUploader方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testSaveMediaImage
/**
* @magentoDataIsolation enabled
* @magentoDataFixture mediaImportImageFixture
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testSaveMediaImage()
{
$this->markTestSkipped('Test must be unskiped after implementation MAGETWO-47449');
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Filesystem');
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $this->objectManager->create('\\Magento\\ImportExport\\Model\\Import\\Source\\Csv', ['file' => __DIR__ . '/_files/import_media.csv', 'directory' => $directory]);
$this->_model->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product', 'import_images_file_dir' => 'pub/media/import']);
$appParams = \Magento\TestFramework\Helper\Bootstrap::getInstance()->getBootstrap()->getApplication()->getInitParams()[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS];
$uploader = $this->_model->getUploader();
$destDir = $directory->getRelativePath($appParams[DirectoryList::MEDIA][DirectoryList::PATH] . '/catalog/product');
$tmpDir = $directory->getRelativePath($appParams[DirectoryList::MEDIA][DirectoryList::PATH] . '/import');
$directory->create($destDir);
$this->assertTrue($uploader->setDestDir($destDir));
$this->assertTrue($uploader->setTmpDir($tmpDir));
$errors = $this->_model->setSource($source)->validateData();
$this->assertTrue($errors->getErrorsCount() == 0);
$this->_model->importData();
$resource = $objectManager->get('Magento\\Catalog\\Model\\ResourceModel\\Product');
$productId = $resource->getIdBySku('simple_new');
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
$product->load($productId);
$this->assertEquals('/m/a/magento_image.jpg', $product->getData('swatch_image'));
$gallery = $product->getMediaGalleryImages();
$this->assertInstanceOf('Magento\\Framework\\Data\\Collection', $gallery);
$items = $gallery->getItems();
$this->assertCount(1, $items);
$item = array_pop($items);
$this->assertInstanceOf('Magento\\Framework\\DataObject', $item);
$this->assertEquals('/m/a/magento_image.jpg', $item->getFile());
$this->assertEquals('Image Label', $item->getLabel());
}