本文整理汇总了PHP中Magento\CatalogImportExport\Model\Import\Product类的典型用法代码示例。如果您正苦于以下问题:PHP Product类的具体用法?PHP Product怎么用?PHP Product使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Product类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'));
}
}
}
开发者ID:Doability,项目名称:magento2dev,代码行数:40,代码来源:BundleTest.php
示例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]);
}
}
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:Import.php
示例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]);
}
}
}
开发者ID:Doability,项目名称:magento2dev,代码行数:29,代码来源:AdvancedPricingTest.php
示例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);
}
开发者ID:nja78,项目名称:magento2,代码行数:42,代码来源:ImportTest.php
示例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));
}
开发者ID:kid17,项目名称:magento2,代码行数:8,代码来源:AbstractTypeTest.php
示例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());
}
开发者ID:niranjanssiet,项目名称:magento2,代码行数:15,代码来源:ProductTest.php
示例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();
}
开发者ID:Doability,项目名称:magento2dev,代码行数:17,代码来源:GroupedTest.php
示例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();
}
开发者ID:IlyaGluschenko,项目名称:protection,代码行数:17,代码来源:DownloadableTest.php
示例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);
}
}
开发者ID:Doability,项目名称:magento2dev,代码行数:29,代码来源:GroupedTest.php
示例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());
}
}
开发者ID:Doability,项目名称:magento2dev,代码行数:19,代码来源:ProductTest.php
示例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);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:34,代码来源:OptionTest.php
示例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);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:54,代码来源:AfterImportDataObserverTest.php
示例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;
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:24,代码来源:Validator.php
示例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());
}
开发者ID:aiesh,项目名称:magento2,代码行数:27,代码来源:ProductTest.php
示例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);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:27,代码来源:ProductTest.php
示例16: isRowValid
/**
* Validate row attributes. Pass VALID row data ONLY as argument.
*
* @param array $rowData
* @param int $rowNum
* @param bool $isNewProduct Optional
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
{
$error = false;
$rowScope = $this->_entityModel->getRowScope($rowData);
if (\Magento\CatalogImportExport\Model\Import\Product::SCOPE_NULL != $rowScope) {
foreach ($this->_getProductAttributes($rowData) as $attrCode => $attrParams) {
// check value for non-empty in the case of required attribute?
if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
$error |= !$this->_entityModel->isAttributeValid($attrCode, $attrParams, $rowData, $rowNum);
} elseif ($this->_isAttributeRequiredCheckNeeded($attrCode) && $attrParams['is_required']) {
// For the default scope - if this is a new product or
// for an old product, if the imported doc has the column present for the attrCode
if (\Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT == $rowScope && ($isNewProduct || array_key_exists($attrCode, $rowData))) {
$this->_entityModel->addRowError(\Magento\CatalogImportExport\Model\Import\Product::ERROR_VALUE_IS_REQUIRED, $rowNum, $attrCode);
$error = true;
}
}
}
}
$error |= !$this->_isParticularAttributesValid($rowData, $rowNum);
return !$error;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:31,代码来源:AbstractType.php
示例17: testValidateDefaultScopeNotValidAttributesResetSku
public function testValidateDefaultScopeNotValidAttributesResetSku()
{
$sku = 'sku';
$rowNum = 0;
$attrCode = 'code';
$stringUtilsMock = $this->getMockBuilder('\\Magento\\Framework\\Stdlib\\StringUtils')->setMethods(null)->getMock();
$this->setPropertyValue($this->importProduct, 'string', $stringUtilsMock);
$scopeMock = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', ['getRowScope'], [], '', false);
$colStore = \Magento\CatalogImportExport\Model\Import\Product::COL_STORE;
$scopeRowData = [$sku => 'sku', $colStore => null];
$scopeResult = \Magento\CatalogImportExport\Model\Import\Product::SCOPE_DEFAULT;
$scopeMock->expects($this->any())->method('getRowScope')->with($scopeRowData)->willReturn($scopeResult);
$oldSku = [$sku => ['type_id' => 'type_id_val']];
$this->setPropertyValue($this->importProduct, '_oldSku', $oldSku);
$expectedSku = false;
$newSku = ['attr_set_code' => 'new_attr_set_code', 'type_id' => 'new_type_id_val'];
$this->skuProcessor->expects($this->any())->method('getNewSku')->with($expectedSku)->willReturn($newSku);
$this->setPropertyValue($this->importProduct, 'skuProcessor', $this->skuProcessor);
$attrParams = ['type' => 'varchar'];
$attrRowData = ['code' => str_repeat('a', \Magento\CatalogImportExport\Model\Import\Product::DB_MAX_VARCHAR_LENGTH + 1)];
$this->validator->expects($this->once())->method('isAttributeValid')->willReturn(false);
$messages = ['validator message'];
$this->validator->expects($this->once())->method('getMessages')->willReturn($messages);
$result = $this->importProduct->isAttributeValid($attrCode, $attrParams, $attrRowData, $rowNum);
$this->assertFalse($result);
}
开发者ID:vv-team,项目名称:foodo,代码行数:26,代码来源:ProductTest.php
示例18: testDownloadableImport
/**
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testDownloadableImport()
{
// import data from CSV file
$pathToFile = __DIR__ . '/../../_files/import_downloadable.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());
$downloadableProductLinks = $product->getExtensionAttributes()->getDownloadableProductLinks();
$downloadableLinks = $product->getDownloadableLinks();
$downloadableProductSamples = $product->getExtensionAttributes()->getDownloadableProductSamples();
$downloadableSamples = $product->getDownloadableSamples();
//TODO: Track Fields: id, link_id, link_file and sample_file)
$expectedLinks = ['file' => ['title' => 'TEST Import Link Title File', 'sort_order' => '78', 'sample_type' => 'file', 'price' => '123.0000', 'number_of_downloads' => '123', 'is_shareable' => '0', 'link_type' => 'file'], 'url' => ['title' => 'TEST Import Link Title URL', 'sort_order' => '42', 'sample_type' => 'url', 'sample_url' => 'http://www.bing.com', 'price' => '1.0000', 'number_of_downloads' => '0', 'is_shareable' => '1', 'link_type' => 'url', 'link_url' => 'http://www.google.com']];
foreach ($downloadableProductLinks as $link) {
$actualLink = $link->getData();
$this->assertArrayHasKey('link_type', $actualLink);
foreach ($expectedLinks[$actualLink['link_type']] as $expectedKey => $expectedValue) {
$this->assertArrayHasKey($expectedKey, $actualLink);
$this->assertEquals($actualLink[$expectedKey], $expectedValue);
}
}
foreach ($downloadableLinks as $link) {
$actualLink = $link->getData();
$this->assertArrayHasKey('link_type', $actualLink);
$this->assertArrayHasKey('product_id', $actualLink);
$this->assertEquals($actualLink['product_id'], $product->getData($this->productMetadata->getLinkField()));
foreach ($expectedLinks[$actualLink['link_type']] as $expectedKey => $expectedValue) {
$this->assertArrayHasKey($expectedKey, $actualLink);
$this->assertEquals($actualLink[$expectedKey], $expectedValue);
}
}
//TODO: Track Fields: id, sample_id and sample_file)
$expectedSamples = ['file' => ['title' => 'TEST Import Sample File', 'sort_order' => '178', 'sample_type' => 'file'], 'url' => ['title' => 'TEST Import Sample URL', 'sort_order' => '178', 'sample_type' => 'url', 'sample_url' => 'http://www.yahoo.com']];
foreach ($downloadableProductSamples as $sample) {
$actualSample = $sample->getData();
$this->assertArrayHasKey('sample_type', $actualSample);
foreach ($expectedSamples[$actualSample['sample_type']] as $expectedKey => $expectedValue) {
$this->assertArrayHasKey($expectedKey, $actualSample);
$this->assertEquals($actualSample[$expectedKey], $expectedValue);
}
}
foreach ($downloadableSamples as $sample) {
$actualSample = $sample->getData();
$this->assertArrayHasKey('sample_type', $actualSample);
$this->assertArrayHasKey('product_id', $actualSample);
$this->assertEquals($actualSample['product_id'], $product->getData($this->productMetadata->getLinkField()));
foreach ($expectedSamples[$actualSample['sample_type']] as $expectedKey => $expectedValue) {
$this->assertArrayHasKey($expectedKey, $actualSample);
$this->assertEquals($actualSample[$expectedKey], $expectedValue);
}
}
}
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:71,代码来源:DownloadableTest.php
示例19: _parseCustomOptions
/**
* Parse custom options string to inner format.
*
* @param array $rowData
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _parseCustomOptions($rowData)
{
$beforeOptionValueSkuDelimiter = ';';
if (empty($rowData['custom_options'])) {
return $rowData;
}
$rowData['custom_options']
|
请发表评论