當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Product::getErrorAggregator方法代碼示例

本文整理匯總了PHP中Magento\CatalogImportExport\Model\Import\Product::getErrorAggregator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::getErrorAggregator方法的具體用法?PHP Product::getErrorAggregator怎麽用?PHP Product::getErrorAggregator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\CatalogImportExport\Model\Import\Product的用法示例。


在下文中一共展示了Product::getErrorAggregator方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testSaveMediaImage

 /**
  * @magentoDataIsolation enabled
  * @magentoDataFixture mediaImportImageFixture
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testSaveMediaImage()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Framework\Filesystem::class);
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['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();
     $this->assertTrue($this->_model->getErrorAggregator()->getErrorsCount() == 0);
     $resource = $objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
     $productId = $resource->getIdBySku('simple_new');
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
     $product->load($productId);
     $this->assertEquals('/m/a/magento_image.jpg', $product->getData('swatch_image'));
     $gallery = $product->getMediaGalleryImages();
     $this->assertInstanceOf(\Magento\Framework\Data\Collection::class, $gallery);
     $items = $gallery->getItems();
     $this->assertCount(1, $items);
     $item = array_pop($items);
     $this->assertInstanceOf(\Magento\Framework\DataObject::class, $item);
     $this->assertEquals('/m/a/magento_image.jpg', $item->getFile());
     $this->assertEquals('Image Label', $item->getLabel());
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:38,代碼來源:ProductTest.php

示例2: testValidateAmbiguousData

 /**
  * Test for validation of ambiguous data
  *
  * @param array $rowData
  * @param array $errors
  * @param string|null $behavior
  * @param int $numberOfValidations
  *
  * @covers \Magento\CatalogImportExport\Model\Import\Product\Option::validateAmbiguousData
  * @covers \Magento\CatalogImportExport\Model\Import\Product\Option::_findNewOptionsWithTheSameTitles
  * @covers \Magento\CatalogImportExport\Model\Import\Product\Option::_findOldOptionsWithTheSameTitles
  * @covers \Magento\CatalogImportExport\Model\Import\Product\Option::_findNewOldOptionsTypeMismatch
  * @covers \Magento\CatalogImportExport\Model\Import\Product\Option::_saveNewOptionData
  * @dataProvider validateAmbiguousDataDataProvider
  */
 public function testValidateAmbiguousData(array $rowData, array $errors, $behavior = null, $numberOfValidations = 1)
 {
     $this->_testStores = ['admin' => 0];
     $this->setUp();
     if ($behavior) {
         $this->_modelMock->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND]);
     }
     $this->_bypassModelMethodGetMultiRowFormat($rowData);
     for ($i = 0; $i < $numberOfValidations; $i++) {
         $this->_modelMock->validateRow($rowData, $i);
     }
     if (empty($errors)) {
         $this->assertTrue($this->_modelMock->validateAmbiguousData());
     } else {
         $this->assertFalse($this->_modelMock->validateAmbiguousData());
     }
     $resultErrors = $this->_productEntity->getErrorAggregator()->getRowsGroupedByErrorCode([], [], false);
     $this->assertEquals($errors, $resultErrors);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:34,代碼來源:OptionTest.php


注:本文中的Magento\CatalogImportExport\Model\Import\Product::getErrorAggregator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。