Esempio n. 1
0
 /**
  * @magentoDataIsolation enabled
  * @magentoDataFixture mediaImportImageFixture
  */
 public function testSaveMediaImage()
 {
     if (Magento_Test_Bootstrap::getInstance()->getDbVendorName() != 'mysql') {
         $this->markTestIncomplete('bug: MAGETWO-4227');
     }
     $attribute = Mage::getModel('Mage_Catalog_Model_Entity_Attribute');
     $attribute->loadByCode('catalog_product', 'media_gallery');
     $data = implode(',', array('sku', '_attribute_set', '_type', '_product_websites', 'name', 'price', 'description', 'short_description', 'weight', 'status', 'visibility', 'tax_class_id', '_media_attribute_id', '_media_image', '_media_label', '_media_position', '_media_is_disabled')) . "\n";
     $data .= implode(',', array('test_sku', 'Default', Mage_Catalog_Model_Product_Type::DEFAULT_TYPE, 'base', 'Product Name', '9.99', 'Product description', 'Short desc.', '1', Mage_Catalog_Model_Product_Status::STATUS_ENABLED, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, 0, $attribute->getId(), 'magento_image.jpg', 'Image Label', '1', '0')) . "\n";
     $data = 'data://text/plain;base64,' . base64_encode($data);
     $fixture = new Mage_ImportExport_Model_Import_Source_Csv($data);
     foreach (new Mage_Catalog_Model_Resource_Product_Collection() as $product) {
         $this->fail("Unexpected precondition - product exists: '{$product->getId()}'.");
     }
     $this->_model->setSource($fixture)->setParameters(array('behavior' => Mage_ImportExport_Model_Import::BEHAVIOR_APPEND))->isDataValid();
     $this->_model->importData();
     $resource = new Mage_Catalog_Model_Resource_Product();
     $productId = $resource->getIdBySku('test_sku');
     // fixture
     $product = Mage::getModel('Mage_Catalog_Model_Product');
     $product->load($productId);
     $gallery = $product->getMediaGalleryImages();
     $this->assertInstanceOf('Varien_Data_Collection', $gallery);
     $items = $gallery->getItems();
     $this->assertCount(1, $items);
     $item = array_pop($items);
     $this->assertInstanceOf('Varien_Object', $item);
     $this->assertEquals('/m/a/magento_image.jpg', $item->getFile());
     $this->assertEquals('Image Label', $item->getLabel());
 }
Esempio n. 2
0
 /**
  * Test if datetime properly saved after import
  *
  * @magentoDataFixture Mage/Catalog/_files/multiple_products.php
  */
 public function testSaveDatetimeAttribute()
 {
     $existingProductIds = array(10, 11, 12);
     $productsBeforeImport = array();
     foreach ($existingProductIds as $productId) {
         $product = new Mage_Catalog_Model_Product();
         $product->load($productId);
         $productsBeforeImport[$product->getSku()] = $product;
     }
     $resource = __DIR__ . '/_files/products_to_import_with_datetime.csv';
     $source = new Mage_ImportExport_Model_Import_Adapter_Csv($resource);
     $this->_model->setParameters(array('behavior' => Mage_ImportExport_Model_Import::BEHAVIOR_REPLACE, 'entity' => 'catalog_product'))->setSource($source)->isDataValid();
     $this->_model->importData();
     reset($source);
     foreach ($source as $row) {
         /** @var $productAfterImport Mage_Catalog_Model_Product */
         $productBeforeImport = $productsBeforeImport[$row['sku']];
         /** @var $productAfterImport Mage_Catalog_Model_Product */
         $productAfterImport = new Mage_Catalog_Model_Product();
         $productAfterImport->load($productBeforeImport->getId());
         $this->assertEquals(@strtotime($row['news_from_date']), @strtotime($productAfterImport->getNewsFromDate()));
         unset($productAfterImport);
     }
     unset($productsBeforeImport, $product);
 }
Esempio n. 3
0
 /**
  * Validate data.
  *
  * @throws Exception
  * @return Mage_ImportExport_Model_Import_Entity_Abstract
  */
 public function validateData()
 {
     if (!$this->_dataValidated) {
         $this->_createAttributeOptions();
         $this->_importExternalImageFiles();
         if (!$this->getAllowRenameFiles()) {
             $this->_getUploader()->setAllowRenameFiles(false);
         }
     }
     return parent::validateData();
 }
Esempio n. 4
0
 /**
  * Validate row attributes. Pass VALID row data ONLY as argument.
  *
  * @param array $rowData
  * @param int $rowNum
  * @param boolean $checkRequiredAttributes OPTIONAL Flag which can disable validation required values.
  * @return boolean
  */
 public function isRowValid(array $rowData, $rowNum, $checkRequiredAttributes = true)
 {
     $error = false;
     $rowScope = $this->_entityModel->getRowScope($rowData);
     if (Mage_ImportExport_Model_Import_Entity_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) && $checkRequiredAttributes && Mage_ImportExport_Model_Import_Entity_Product::SCOPE_DEFAULT == $rowScope && $attrParams['is_required']) {
                 $this->_entityModel->addRowError(Mage_ImportExport_Model_Import_Entity_Product::ERROR_VALUE_IS_REQUIRED, $rowNum, $attrCode);
                 $error = true;
             }
         }
     }
     $error |= !$this->_isParticularAttributesValid($rowData, $rowNum);
     return !$error;
 }
Esempio n. 5
0
 /**
  * Tests adding of custom options with different behaviours
  *
  * @param $behavior
  *
  * @magentoDataFixture Mage/Catalog/_files/product_simple.php
  * @dataProvider getBehaviorDataProvider
  * @covers Mage_ImportExport_Model_Import_Entity_Product::_saveCustomOptions
  */
 public function testSaveCustomOptionsDuplicate($behavior)
 {
     // import data from CSV file
     $pathToFile = __DIR__ . '/_files/product_with_custom_options.csv';
     $source = new Mage_ImportExport_Model_Import_Adapter_Csv($pathToFile);
     $this->_model->setSource($source)->setParameters(array('behavior' => $behavior))->isDataValid();
     $this->_model->importData();
     $product = new Mage_Catalog_Model_Product();
     $product->load(1);
     // product from fixture
     $options = $product->getProductOptionsCollection();
     $expectedData = $this->_getExpectedOptionsData($pathToFile);
     $expectedData = $this->_mergeWithExistingData($expectedData, $options);
     $actualData = $this->_getActualOptionsData($options);
     // assert of equal type+titles
     $expectedOptions = $expectedData['options'];
     // we need to save key values
     $actualOptions = $actualData['options'];
     sort($expectedOptions);
     sort($actualOptions);
     $this->assertEquals($expectedOptions, $actualOptions);
     // assert of options data
     $this->assertCount(count($expectedData['data']), $actualData['data']);
     $this->assertCount(count($expectedData['values']), $actualData['values']);
     foreach ($expectedData['options'] as $expectedId => $expectedOption) {
         $elementExist = false;
         // find value in actual options and values
         foreach ($actualData['options'] as $actualId => $actualOption) {
             if ($actualOption == $expectedOption) {
                 $elementExist = true;
                 $this->assertEquals($expectedData['data'][$expectedId], $actualData['data'][$actualId]);
                 if (array_key_exists($expectedId, $expectedData['values'])) {
                     $this->assertEquals($expectedData['values'][$expectedId], $actualData['values'][$actualId]);
                 }
                 unset($actualData['options'][$actualId]);
                 // remove value in case of duplicating key values
                 break;
             }
         }
         $this->assertTrue($elementExist, 'Element must exist.');
     }
 }
Esempio n. 6
0
 /**
  * Validate row attributes. Pass VALID row data ONLY as argument.
  *
  * @param array $rowData
  * @param int $rowNum
  * @param boolean $isNewProduct OPTIONAL.
  * @return boolean
  */
 public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
 {
     $error = false;
     $rowScope = $this->_entityModel->getRowScope($rowData);
     if (Mage_ImportExport_Model_Import_Entity_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 (Mage_ImportExport_Model_Import_Entity_Product::SCOPE_DEFAULT == $rowScope && ($isNewProduct || array_key_exists($attrCode, $rowData))) {
                     $this->_entityModel->addRowError(Mage_ImportExport_Model_Import_Entity_Product::ERROR_VALUE_IS_REQUIRED, $rowNum, $attrCode);
                     $error = true;
                 }
             }
         }
     }
     $error |= !$this->_isParticularAttributesValid($rowData, $rowNum);
     return !$error;
 }
 protected function _importData()
 {
     $result = parent::_importData();
     $resource = Mage::getSingleton('core/resource');
     $this->_connection->query("DELETE FROM `{$resource->getTableName('core_resource')}` WHERE `code` = 'customoptions_setup';");
     return $result;
 }
Esempio n. 8
0
 /**
  * Adds events before and after importing.
  *
  * @return boolean
  */
 public function _importData()
 {
     Mage::dispatchEvent($this->_eventPrefix . '_before_import', array('entity_model' => $this, 'data_source_model' => $this->_dataSourceModel, 'uploader' => $this->_getUploader()));
     // Do the actual import.
     parent::_importData();
     Mage::dispatchEvent($this->_eventPrefix . '_after_import', array('entity_model' => $this, 'entities' => $this->_newSku));
     return $this->_newSku;
 }
 /**
  * Common validation
  *
  * @param array $rowData
  * @param int $rowNum
  * @param string|false|null $sku
  */
 protected function _validate($rowData, $rowNum, $sku)
 {
     parent::_validate($rowData, $rowNum, $sku);
     $this->_isUrlKeyValid($rowData, $rowNum, $sku);
 }
Esempio n. 10
0
 /**
  * Validate one specific parameter
  *
  * @param string $typeParameter
  * @param array $rowData
  * @param int $rowNumber
  * @return bool
  */
 protected function _validateSpecificParameterData($typeParameter, array $rowData, $rowNumber)
 {
     $fieldName = self::COLUMN_PREFIX . $typeParameter;
     if ($typeParameter == 'price') {
         if (!empty($rowData[$fieldName]) && !is_numeric(rtrim($rowData[$fieldName], '%'))) {
             $this->_productEntity->addRowError(self::ERROR_INVALID_PRICE, $rowNumber);
             return false;
         }
     } elseif ($typeParameter == 'max_characters') {
         if (!empty($rowData[$fieldName]) && !ctype_digit((string) $rowData[$fieldName])) {
             $this->_productEntity->addRowError(self::ERROR_INVALID_MAX_CHARACTERS, $rowNumber);
             return false;
         }
     }
     return true;
 }
Esempio n. 11
0
 /**
  * Update and insert data in entity table.
  *
  * @param array $entityRowsIn Row for insert
  * @param array $entityRowsUp Row for update
  * @return Mage_ImportExport_Model_Import_Entity_Product
  */
 protected function _saveProductEntity(array $entityRowsIn, array $entityRowsUp)
 {
     $ret = parent::_saveProductEntity($entityRowsIn, $entityRowsUp);
     Mage::dispatchEvent('searchanise_import_save_product_entity_after', array('_newSku' => $ret->_newSku));
     return $ret;
 }
Esempio n. 12
0
 /**
  * Adds events before and after importing.
  *
  * @return boolean
  */
 public function _importData()
 {
     Mage::dispatchEvent($this->_eventPrefix . '_before_import', array('entity_model' => $this, 'data_source_model' => $this->_dataSourceModel));
     $result = parent::_importData();
     Mage::dispatchEvent($this->_eventPrefix . '_after_import', array('entity_model' => $this, 'entities' => $this->_newSku));
     return $result;
 }