本文整理匯總了PHP中Magento\CatalogImportExport\Model\Import\Product類的典型用法代碼示例。如果您正苦於以下問題:PHP Product類的具體用法?PHP Product怎麽用?PHP Product使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Product類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testBundleImport
/**
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*/
public function testBundleImport()
{
// import data from CSV file
$pathToFile = __DIR__ . '/../../_files/import_bundle.csv';
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
$errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData();
$this->assertTrue($errors->getErrorsCount() == 0);
$this->model->importData();
$resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
$productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME);
$this->assertTrue(is_numeric($productId));
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
$product->load($productId);
$this->assertFalse($product->isObjectNew());
$this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName());
$this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId());
$this->assertEquals(1, $product->getShipmentType());
$optionIdList = $resource->getProductsIdsBySkus($this->optionSkuList);
$bundleOptionCollection = $product->getExtensionAttributes()->getBundleProductOptions();
$this->assertEquals(2, count($bundleOptionCollection));
foreach ($bundleOptionCollection as $optionKey => $option) {
$this->assertEquals('checkbox', $option->getData('type'));
$this->assertEquals('Option ' . ($optionKey + 1), $option->getData('title'));
$this->assertEquals(self::TEST_PRODUCT_NAME, $option->getData('sku'));
$this->assertEquals($optionKey + 1, count($option->getData('product_links')));
foreach ($option->getData('product_links') as $linkKey => $productLink) {
$optionSku = 'Simple ' . ($optionKey + 1 + $linkKey);
$this->assertEquals($optionIdList[$optionSku], $productLink->getData('entity_id'));
$this->assertEquals($optionSku, $productLink->getData('sku'));
}
}
}
示例2: clearProductUrls
/**
* @param ImportProduct $import
* @return void
*/
protected function clearProductUrls(ImportProduct $import)
{
$oldSku = $import->getOldSku();
while ($bunch = $import->getNextBunch()) {
$idToDelete = [];
foreach ($bunch as $rowNum => $rowData) {
if ($import->validateRow($rowData, $rowNum) && ImportProduct::SCOPE_DEFAULT == $import->getRowScope($rowData)) {
$idToDelete[] = $oldSku[$rowData[ImportProduct::COL_SKU]]['entity_id'];
}
}
foreach ($idToDelete as $productId) {
$this->urlPersist->deleteByData([UrlRewrite::ENTITY_ID => $productId, UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE]);
}
}
}
示例3: testImportReplace
/**
* @magentoDataFixture Magento/AdvancedPricingImportExport/_files/create_products.php
* @magentoAppArea adminhtml
*/
public function testImportReplace()
{
// import data from CSV file
$pathToFile = __DIR__ . '/_files/import_advanced_pricing.csv';
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
$errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE, 'entity' => 'advanced_pricing'])->validateData();
$this->assertEquals(0, $errors->getErrorsCount(), 'Advanced pricing import validation error');
$this->model->importData();
/** @var \Magento\Catalog\Model\ResourceModel\Product $resource */
$resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
$productIdList = $resource->getProductsIdsBySkus(array_keys($this->expectedTierPrice));
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
foreach ($productIdList as $sku => $productId) {
$product->load($productId);
$tierPriceCollection = $product->getTierPrices();
$this->assertEquals(3, count($tierPriceCollection));
/** @var \Magento\Catalog\Model\Product\TierPrice $tierPrice */
foreach ($tierPriceCollection as $tierPrice) {
$this->assertContains($tierPrice->getData(), $this->expectedTierPrice[$sku]);
}
}
}
示例4: testAfterImportData
/**
* Test for afterImportData()
* Covers afterImportData() + protected methods used inside except related to generateUrls() ones.
* generateUrls will be covered separately.
*
* @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::afterImportData
* @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::_populateForUrlGeneration
* @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::isGlobalScope
* @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::populateGlobalProduct
* @covers \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import::addProductToImport
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testAfterImportData()
{
$newSku = ['entity_id' => 'value'];
$websiteId = 'websiteId value';
$productsCount = count($this->products);
$websiteMock = $this->getMock('\\Magento\\Store\\Model\\Website', ['getStoreIds'], [], '', false);
$storeIds = [1, Store::DEFAULT_STORE_ID];
$websiteMock->expects($this->once())->method('getStoreIds')->willReturn($storeIds);
$this->storeManager->expects($this->once())->method('getWebsite')->with($websiteId)->willReturn($websiteMock);
$this->importProduct->expects($this->exactly($productsCount))->method('getNewSku')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]])->willReturn($newSku);
$this->importProduct->expects($this->exactly($productsCount))->method('getProductCategories')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]]);
$getProductWebsitesCallsCount = $productsCount * 2;
$this->importProduct->expects($this->exactly($getProductWebsitesCallsCount))->method('getProductWebsites')->willReturn([$newSku['entity_id'] => $websiteId]);
$map = [[$this->products[0][ImportProduct::COL_STORE], $this->products[0][ImportProduct::COL_STORE]], [$this->products[1][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE]]];
$this->importProduct->expects($this->exactly(1))->method('getStoreIdByCode')->will($this->returnValueMap($map));
$product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'setId', 'getSku', 'setStoreId', 'getStoreId'], [], '', false);
$product->expects($this->exactly($productsCount))->method('setId')->with($newSku['entity_id']);
$product->expects($this->any())->method('getId')->willReturn($newSku['entity_id']);
$product->expects($this->exactly($productsCount))->method('getSku')->will($this->onConsecutiveCalls($this->products[0]['sku'], $this->products[1]['sku']));
$product->expects($this->exactly($productsCount))->method('getStoreId')->will($this->onConsecutiveCalls($this->products[0][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE]));
$product->expects($this->once())->method('setStoreId')->with($this->products[1][ImportProduct::COL_STORE]);
$this->catalogProductFactory->expects($this->exactly($productsCount))->method('create')->willReturn($product);
$this->connection->expects($this->exactly(4))->method('quoteInto')->withConsecutive(['(store_id = ?', $storeIds[0]], [' AND entity_id = ?)', $newSku['entity_id']]);
$productUrls = ['url 1', 'url 2'];
$importMock = $this->getImportMock(['generateUrls', 'canonicalUrlRewriteGenerate', 'categoriesUrlRewriteGenerate', 'currentUrlRewritesRegenerate', 'cleanOverriddenUrlKey']);
$importMock->expects($this->once())->method('generateUrls')->willReturn($productUrls);
$this->urlPersist->expects($this->once())->method('replace')->with($productUrls);
$importMock->afterImportData($this->observer);
}
示例5: testIsRowValidError
public function testIsRowValidError()
{
$rowData = ['_attribute_set' => 'attribute_set_name'];
$rowNum = 1;
$this->entityModel->expects($this->any())->method('getRowScope')->willReturn(1);
$this->entityModel->expects($this->once())->method('addRowError')->with(\Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface::ERROR_VALUE_IS_REQUIRED, 1, 'attr_code')->willReturnSelf();
$this->assertFalse($this->simpleType->isRowValid($rowData, $rowNum));
}
示例6: testProductWithInvalidWeight
/**
* @magentoDbIsolation enabled
*/
public function testProductWithInvalidWeight()
{
// import data from CSV file
$pathToFile = __DIR__ . '/_files/product_to_import_invalid_weight.csv';
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Filesystem');
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = new \Magento\ImportExport\Model\Import\Source\Csv($pathToFile, $directory);
$validationResult = $this->_model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND])->isDataValid();
$expectedErrors = ["Product weight is invalid" => [2]];
$this->assertFalse($validationResult);
$this->assertEquals($expectedErrors, $this->_model->getErrorMessages());
}
示例7: testSaveDataScopeStore
/**
* Test saveData() with store row scope
*/
public function testSaveDataScopeStore()
{
$this->entityModel->expects($this->once())->method('getNewSku')->will($this->returnValue(['sku_assoc1' => ['entity_id' => 1], 'productSku' => ['entity_id' => 2, 'attr_set_code' => 'Default', 'type_id' => 'grouped']]));
$this->entityModel->expects($this->once())->method('getOldSku')->will($this->returnValue(['sku_assoc2' => ['entity_id' => 3]]));
$attributes = ['position' => ['id' => 0], 'qty' => ['id' => 0]];
$this->links->expects($this->once())->method('getAttributes')->will($this->returnValue($attributes));
$bunch = [['associated_skus' => 'sku_assoc1=1, sku_assoc2=2', 'sku' => 'productSku', 'product_type' => 'grouped']];
$this->entityModel->expects($this->at(2))->method('getNextBunch')->will($this->returnValue($bunch));
$this->entityModel->expects($this->any())->method('isRowAllowedToImport')->will($this->returnValue(true));
$this->entityModel->expects($this->at(4))->method('getRowScope')->will($this->returnValue(\Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT));
$this->entityModel->expects($this->at(5))->method('getRowScope')->will($this->returnValue(\Magento\CatalogImportExport\Model\Import\Product::SCOPE_STORE));
$this->links->expects($this->once())->method('saveLinksData');
$this->grouped->saveData();
}
示例8: testSetUploaderDirFalse
/**
* @dataProvider dataForUploaderDir
*/
public function testSetUploaderDirFalse($newSku, $bunch, $allowImport)
{
$this->connectionMock->expects($this->any())->method('fetchAll')->with($this->select)->willReturnOnConsecutiveCalls([['attribute_set_name' => '1', 'attribute_id' => '1'], ['attribute_set_name' => '2', 'attribute_id' => '2']]);
$this->downloadableModelMock = $this->objectManagerHelper->getObject('\\Magento\\DownloadableImportExport\\Model\\Import\\Product\\Type\\Downloadable', ['attrSetColFac' => $this->attrSetColFacMock, 'prodAttrColFac' => $this->prodAttrColFacMock, 'resource' => $this->resourceMock, 'params' => $this->paramsArray, 'uploaderHelper' => $this->uploaderHelper, 'downloadableHelper' => $this->downloadableHelper]);
$this->entityModelMock->expects($this->once())->method('getNewSku')->will($this->returnValue($newSku));
$this->entityModelMock->expects($this->at(1))->method('getNextBunch')->will($this->returnValue($bunch));
$this->entityModelMock->expects($this->at(2))->method('getNextBunch')->will($this->returnValue(null));
$this->entityModelMock->expects($this->any())->method('isRowAllowedToImport')->willReturn($allowImport);
$exception = new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Error'));
$this->setExpectedException('\\Magento\\Framework\\Exception\\LocalizedException');
$this->setExpectedException('\\Exception');
$this->uploaderMock->expects($this->any())->method('move')->will($this->throwException($exception));
$this->downloadableModelMock->saveData();
}
示例9: testImport
/**
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*/
public function testImport()
{
// Import data from CSV file
$pathToFile = __DIR__ . '/../../_files/grouped_product.csv';
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
$errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData();
$this->assertTrue($errors->getErrorsCount() == 0);
$this->model->importData();
$resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
$productId = $resource->getIdBySku('Test Grouped');
$this->assertTrue(is_numeric($productId));
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
$product->load($productId);
$this->assertFalse($product->isObjectNew());
$this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName());
$this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId());
$childProductCollection = $product->getTypeInstance()->getAssociatedProducts($product);
foreach ($childProductCollection as $childProduct) {
$this->assertContains($childProduct->getSku(), $this->optionSkuList);
}
}
示例10: testProductWithUseConfigSettings
/**
* @magentoAppIsolation enabled
*/
public function testProductWithUseConfigSettings()
{
$products = ['simple1' => true, 'simple2' => true, 'simple3' => false];
$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/products_to_import_with_use_config_settings.csv', 'directory' => $directory]);
$errors = $this->_model->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->setSource($source)->validateData();
$this->assertTrue($errors->getErrorsCount() == 0);
$this->_model->importData();
foreach ($products as $sku => $manageStockUseConfig) {
/** @var \Magento\CatalogInventory\Model\StockRegistry $stockRegistry */
$stockRegistry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\CatalogInventory\\Model\\StockRegistry');
$stockItem = $stockRegistry->getStockItemBySku($sku);
$this->assertEquals($manageStockUseConfig, $stockItem->getUseConfigManageStock());
}
}
示例11: 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);
}
示例12: testAfterImportData
/**
* Test for afterImportData()
* Covers afterImportData() + protected methods used inside
*
* @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::afterImportData
* @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::_populateForUrlGeneration
* @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::isGlobalScope
* @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::populateGlobalProduct
* @covers \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::addProductToImport
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testAfterImportData()
{
$newSku = [['entity_id' => 'value'], ['entity_id' => 'value3']];
$websiteId = 'websiteId value';
$productsCount = count($this->products);
$websiteMock = $this->getMock('\\Magento\\Store\\Model\\Website', ['getStoreIds'], [], '', false);
$storeIds = [1, Store::DEFAULT_STORE_ID];
$websiteMock->expects($this->once())->method('getStoreIds')->willReturn($storeIds);
$this->storeManager->expects($this->once())->method('getWebsite')->with($websiteId)->willReturn($websiteMock);
$this->importProduct->expects($this->exactly($productsCount))->method('getNewSku')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]])->will($this->onConsecutiveCalls($newSku[0], $newSku[1]));
$this->importProduct->expects($this->exactly($productsCount))->method('getProductCategories')->withConsecutive([$this->products[0][ImportProduct::COL_SKU]], [$this->products[1][ImportProduct::COL_SKU]])->willReturn([]);
$getProductWebsitesCallsCount = $productsCount * 2;
$this->importProduct->expects($this->exactly($getProductWebsitesCallsCount))->method('getProductWebsites')->willReturnOnConsecutiveCalls([$newSku[0]['entity_id'] => $websiteId], [$newSku[0]['entity_id'] => $websiteId], [$newSku[1]['entity_id'] => $websiteId], [$newSku[1]['entity_id'] => $websiteId]);
$map = [[$this->products[0][ImportProduct::COL_STORE], $this->products[0][ImportProduct::COL_STORE]], [$this->products[1][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE]]];
$this->importProduct->expects($this->exactly(1))->method('getStoreIdByCode')->will($this->returnValueMap($map));
$product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'setId', 'getSku', 'setStoreId', 'getStoreId'], [], '', false);
$product->expects($this->exactly($productsCount))->method('setId')->withConsecutive([$newSku[0]['entity_id']], [$newSku[1]['entity_id']]);
$product->expects($this->any())->method('getId')->willReturnOnConsecutiveCalls($newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[0]['entity_id'], $newSku[1]['entity_id'], $newSku[1]['entity_id'], $newSku[1]['entity_id']);
$product->expects($this->exactly($productsCount))->method('getSku')->will($this->onConsecutiveCalls($this->products[0]['sku'], $this->products[1]['sku']));
$product->expects($this->exactly($productsCount))->method('getStoreId')->will($this->onConsecutiveCalls($this->products[0][ImportProduct::COL_STORE], $this->products[1][ImportProduct::COL_STORE]));
$product->expects($this->exactly($productsCount))->method('setStoreId')->withConsecutive([$this->products[0][ImportProduct::COL_STORE]], [$this->products[1][ImportProduct::COL_STORE]]);
$this->catalogProductFactory->expects($this->exactly($productsCount))->method('create')->willReturn($product);
$this->connection->expects($this->exactly(4))->method('quoteInto')->withConsecutive(['(store_id = ?', $storeIds[0]], [' AND entity_id = ?)', $newSku[0]['entity_id']], ['(store_id = ?', $storeIds[0]], [' AND entity_id = ?)', $newSku[1]['entity_id']]);
$this->connection->expects($this->once())->method('fetchAll')->willReturn([]);
$this->select->expects($this->any())->method('from')->willReturnSelf();
$this->select->expects($this->any())->method('where')->willReturnSelf();
$this->urlFinder->expects($this->any())->method('findAllByData')->willReturn([]);
$this->productUrlPathGenerator->expects($this->any())->method('getUrlPathWithSuffix')->willReturn('urlPathWithSuffix');
$this->productUrlPathGenerator->expects($this->any())->method('getUrlPath')->willReturn('urlPath');
$this->productUrlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->willReturn('canonicalUrlPath');
$this->urlRewrite->expects($this->any())->method('setStoreId')->willReturnSelf();
$this->urlRewrite->expects($this->any())->method('setEntityId')->willReturnSelf();
$this->urlRewrite->expects($this->any())->method('setEntityType')->willReturnSelf();
$this->urlRewrite->expects($this->any())->method('setRequestPath')->willReturnSelf();
$this->urlRewrite->expects($this->any())->method('setTargetPath')->willReturnSelf();
$this->urlRewrite->expects($this->any())->method('getTargetPath')->willReturn('targetPath');
$this->urlRewrite->expects($this->any())->method('getStoreId')->willReturnOnConsecutiveCalls(0, 'not global');
$this->urlRewriteFactory->expects($this->any())->method('create')->willReturn($this->urlRewrite);
$productUrls = ['targetPath-0' => $this->urlRewrite, 'targetPath-not global' => $this->urlRewrite];
$this->urlPersist->expects($this->once())->method('replace')->with($productUrls);
$this->import->execute($this->observer);
}
示例13: isValidAttributes
/**
* @return bool
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
protected function isValidAttributes()
{
$this->_clearMessages();
if (!isset($this->_rowData['product_type'])) {
return false;
}
$entityTypeModel = $this->context->retrieveProductTypeByName($this->_rowData['product_type']);
if ($entityTypeModel) {
foreach ($this->_rowData as $attrCode => $attrValue) {
$attrParams = $entityTypeModel->retrieveAttributeFromCache($attrCode);
if ($attrParams) {
$this->isAttributeValid($attrCode, $attrParams, $this->_rowData);
}
}
if ($this->getMessages()) {
return false;
}
}
return true;
}
示例14: testProductsWithMultipleStores
/**
* @magentoDataFixture Magento/Catalog/_files/categories.php
* @magentoDataFixture Magento/Core/_files/store.php
* @magentoDataFixture Magento/Catalog/Model/Layer/Filter/_files/attribute_with_option.php
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_attribute.php
*/
public function testProductsWithMultipleStores()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$filesystem = $objectManager->create('Magento\\Framework\\App\\Filesystem');
$directory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::ROOT_DIR);
$source = new \Magento\ImportExport\Model\Import\Source\Csv(__DIR__ . '/_files/products_multiple_stores.csv', $directory);
$this->_model->setParameters(array('behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'))->setSource($source)->isDataValid();
$this->_model->importData();
/** @var \Magento\Catalog\Model\Product $product */
$product = $objectManager->create('Magento\\Catalog\\Model\\Product');
$id = $product->getIdBySku('Configurable 03');
$product->load($id);
$this->assertEquals('1', $product->getHasOptions());
$objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->setCurrentStore('fixturestore');
/** @var \Magento\Catalog\Model\Product $simpleProduct */
$simpleProduct = $objectManager->create('Magento\\Catalog\\Model\\Product');
$id = $simpleProduct->getIdBySku('Configurable 03-option_0');
$simpleProduct->load($id);
$this->assertEquals('Option Label', $simpleProduct->getAttributeText('attribute_with_option'));
$this->assertEquals(array(2, 4), $simpleProduct->getAvailableInCategories());
}
示例15: testProductCategories
/**
* @magentoAppArea adminhtml
* @dataProvider categoryTestDataProvider
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*/
public function testProductCategories($fixture, $separator)
{
// import data from CSV file
$pathToFile = __DIR__ . '/_files/' . $fixture;
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Filesystem');
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = new \Magento\ImportExport\Model\Import\Source\Csv($pathToFile, $directory);
$errors = $this->_model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product', Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR => $separator])->validateData();
$this->assertTrue($errors->getErrorsCount() == 0);
$this->_model->importData();
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$resource = $objectManager->get('Magento\\Catalog\\Model\\ResourceModel\\Product');
$productId = $resource->getIdBySku('simple1');
$this->assertTrue(is_numeric($productId));
/** @var \Magento\Catalog\Model\Product $product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
$product->load($productId);
$this->assertFalse($product->isObjectNew());
$categories = $product->getCategoryIds();
$this->assertTrue(count($categories) == 2);
}