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

Problem adding attribute options that start with a number via REST Api #5715

Closed
johnhird opened this issue Jul 21, 2016 · 14 comments
Closed
Labels
bug report Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@johnhird
Copy link

Steps to reproduce

  1. Via REST API make a POST request to: /V1/products/attributes/{attributeCode}/options
  2. send up new data with label and value that begins with a number e.g. "123 test"

Expected result

  1. new attribute option should be added the same as when label and value begin with a letter.
  2. API result is "StatusCode: OK, Content-Type: application/json; charset=utf-8, Content-Length: 4)"

Actual result

  1. response from API call is: {"message":"Cannot save attribute %1","parameters":["size"]}

This only happens when the attribute options starts with a number.

@johnhird johnhird changed the title Problem adding attribute options that start with a number Problem adding attribute options that start with a number via REST Api Jul 24, 2016
@jakobfdev
Copy link

jakobfdev commented Aug 2, 2016

+1: I can confirm.
Below the 'Cannot save attribute %s' I get the Exception

[Zend_Db_Statement_Exception]) SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (db_name.eav_attribute_option_value, CONSTRAINTEAV_ATTR_OPT_VAL_OPT_ID_EAV_ATTR_OPT_OPT_IDFOREIGN KEY (option_id) REFERENCESeav_attribute_option(option_id) ON DELETE ), query was: INSERT INTOeav_attribute_option_value(option_id,store_id,value) VALUES (?, ?, ?)))

from the Magento\Eav\Model\ResourceModel\Entity\Attribute class.

This problem is not restricted to API calls!

I was using the function add from the Magento\Eav\Model\Entity\Attribute\OptionManagement class.
Meanwhile no problems using value-strings starting with alpha characters.

@SerhiyShkolyarenko SerhiyShkolyarenko self-assigned this Sep 13, 2016
@SerhiyShkolyarenko
Copy link
Contributor

@johnhird @jboka thank you for reporting!
We reproduced the issue and created internal MAGETWO-58338.

@SerhiyShkolyarenko SerhiyShkolyarenko added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Sep 13, 2016
mmansoor-magento pushed a commit that referenced this issue Sep 20, 2016
mmansoor-magento pushed a commit that referenced this issue Sep 20, 2016
Bug
MAGETWO-56699 [GITHUB] Paypal checkout not possible with products that have custom options #5938 - for mainline
MAGETWO-58290 [Github]Empty product option is added on each PUT request #5963
MAGETWO-58136 [Github] Shipping and billing address are not set if order placed with payment action Sale #6438
MAGETWO-55608 [GITHUB] M2.1: Not scrollable picture on mobile / product page #5302
MAGETWO-58285 Ajax error message doesn't display in backend
MAGETWO-58338 [Github]Problem adding attribute options that start with a number via REST Api #5715
MAGETWO-52575 Unable to apply free shipping to specified method when creating order in admin
MAGETWO-57078 [GITHUB] Can't set customer group when creating a new order in the admin. #6162
MAGETWO-58039 Table rate shipping not applying correctly - for mainline
@SerhiyShkolyarenko
Copy link
Contributor

Fix of MAGETWO-58338 is delivered to develop branch. Closing the issue.

@jakobfdev
Copy link

Hi, as far as can see the issue still exists in 2.1.2
How do we know, when the fix is delivered to the composer packages?

@SerhiyShkolyarenko
Copy link
Contributor

SerhiyShkolyarenko commented Oct 17, 2016

In 2.2.0 release, IMHO.

@worldpac
Copy link

Was there a fix here? I see an update to a unit test in MAGETWO-58338, but not to the code that would fix the problem.

@SerhiyShkolyarenko
Copy link
Contributor

@worldpac fix was delivered to develop branch in commits 4f6281d and 21d58ef.

@orozcodiaz
Copy link
Contributor

2.1.6 still experiencing

@abdulmoizbaig
Copy link

This issue is persisting in 2.1.7, i was hoping it must be resolved.

@sedax90
Copy link

sedax90 commented Jul 13, 2017

I have the same error importing attributes with Firegento FastSimpleImport module. I've tried to apply 21d58ef but it doens't work. Is there any workaround?

@MarekKarmelski
Copy link

Problem still exist: https://github.com/magento/magento2/blob/2.1.10-preview/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute.php

You don't add this fix [https://github.com/magento/magento2/commit/21d58ef7b7af29ebfea183dbe5e4a084a5b2c343] to 2.1.9!

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Oct 28, 2017
@Gurdit
Copy link

Gurdit commented Mar 7, 2018

I have created a external file in magneto 2 and it worked

<?php
use Magento\Framework\App\Bootstrap;
 
require __DIR__ . '/app/bootstrap.php';
 
$params = $_SERVER;
 
$bootstrap = Bootstrap::create(BP, $params);
 
try{
$obj = $bootstrap->getObjectManager();

$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

$eavSetupFactory = $obj->create('\Magento\Eav\Setup\EavSetup');
$attributeFactory = $obj->get('\Magento\Catalog\Model\ResourceModel\Eav\Attribute'); 

$attribute_arr = ['35 mm','45 mm','65 mm','aman', 'gurdit' ,'28','39'];


$attributeInfo = $attributeFactory->getCollection()
               ->addFieldToFilter('attribute_code',['eq'=>"size"])
               ->getFirstItem();
 $attribute_id = $attributeInfo->getAttributeId();

 $option=array();
$option['attribute_id'] = $attribute_id;
foreach($attribute_arr as $key=>$value){

	$str = '"'.$value.'"';

    $option['value'][$str][0]= str_replace('"','', $str);
}

$eavSetupFactory->addAttributeOption($option);
}catch(Exception $e){

	echo $e->getMessage();
}
?>

@vetshopdeveloper
Copy link

Still an issue in 2.2.7

@maxxeh1
Copy link

maxxeh1 commented Mar 18, 2020

Still an issue in 2.3.3 and 2.3.4 - please fix. What's the point in InstallData files if we have to create certain values through the admin panel?

slavvka pushed a commit that referenced this issue May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests