Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow import of empty attributes #13472

Merged
merged 10 commits into from
Jul 3, 2018
Merged

Allow import of empty attributes #13472

merged 10 commits into from
Jul 3, 2018

Conversation

PieterCappelle
Copy link
Contributor

Allow import of empty attributes in Magento2 import functionality. See internal number MAGETWO-61593.

Fixed Issues (if relevant)

  1. CatalogImportExport doesn't support empty row values #7468

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@PieterCappelle
Copy link
Contributor Author

Any progress on this issue? Unit tests are failing but is because of Travis :)

@magento-engcom-team
Copy link
Contributor

@PieterCappelle thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@dmanners
Copy link
Contributor

Hi @PieterCappelle for feedback from testing.

There is no human-readable validation message when "custom_options" is set to "EMPTYVALUE" even if there was no value before. When you setup the "custom_options" field to "EMPTYVALUE" you end up with the notice Notice: Undefined index: required in /var/www/html/pr/app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php on line 1124

import-notice-custom-options

There is a validation for name, SKU and price properties on Backend, however for unknown reasons Merchant is able to create products without price using WebAPI.
Why not to disallow unsetting name, SKU and price via Import?

  1. Set "EMPTYVALUE" for SKU but leave "url_key" to be "simple1".
  1. Url key: '%s' was already generated for an item with the SKU: '%s'. You need to specify the unique URL key manually in row(s): 1

import-url-key

  1. Set "EMPTYVALUE" for SKU and "url_key"
    Press "Check Data" and get 'File is valid! To start import process press "Import" button' message.
    Press "Import" button and you will see this error:
  1. Imported resource (image) could not be downloaded from external resource due to timeout or access permissions in row(s): 1

import-image-error

  1. Navigate to Products > Inventory > Catalog and look that there we created a new product

import-product-with-no-name

I think that if we have validation for empty values in the backend we should have the same validation in the import.

@okorshenko okorshenko modified the milestones: March 2018, April 2018 Apr 16, 2018
@okorshenko okorshenko modified the milestones: April 2018, May 2018 May 18, 2018
@okorshenko okorshenko removed this from the May 2018 milestone May 31, 2018
@dmanners
Copy link
Contributor

dmanners commented Jun 6, 2018

I have updated this PR so that it now includes the deletion of custom options via the csv using the empty value option added by @PieterCappelle

Pieter Cappelle and others added 9 commits June 6, 2018 13:36
…learEmptyData if statement

Updating the formatting for the new if in clearEmptyData so that it fits the coding standards.
…product options match expected style

 - if product options is equal to our new empty value constant than do not try to process it as normal
@magento-engcom-team
Copy link
Contributor

Hi @PieterCappelle. Thank you for your contribution.
We will aim to release these changes as part of 2.3.0.
Please check the release notes for final confirmation.

@dweerd
Copy link

dweerd commented Aug 7, 2018

Does this work for all types of attributes? I have applied this patch to a magento 2.2.5 instance, and although this does work for text fields, it doesn't work as expected for boolean fields and dropdown fields.

Empty values for these kinds of fields are saved as NULL, causing them to be displayed as 'No' on the product details page. If I remove the records with value NULL from the catalog_product_entity_int table, they are no longer displayed on the product details page, as expected.

As a quick fix, I have extended Magento\CatalogImportExport\Model\Import\Product::_saveProductAttributes like so:

protected function _saveProductAttributes(array $attributesData)
{
	parent::_saveProductAttributes($attributesData);

	foreach ($attributesData as $tableName => $skuData) {
		$this->_connection->delete($tableName, ['value IS NULL']);
	}

	return $this;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants