$optionLabel->setStoreId(0);
$optionLabel->setLabel('new_color');
$option->setLabel('new_color');
$option->setStoreLabels(array($optionLabel));
$this->productAttributeOptionManagement->add('color', $option);
}
Until Magento 2.1.7 the plugin did not trigger beforeSave function in swatches/Model/Plugin/EavAttribute and the Import data had not to match visual swatch data structure, it was imported
Since Magento 2.1.8 the function is renamed to beforeBeforeSave and the plugin triggers it,
so the Import data has to follow data structure of visual swatch, but since it is a API Import there is no entry in database and the new Option does not get imported
We are closing this issue because we cannot reproduce this issue as described. If you have questions, please refer to a question and answer site, such as Stack Exchange and the Magento Forums, where Magento community members can quickly provide recommendations and advice.
It seems that's the same problem as #10707, could you leave the issue open until it's solved?
@slavkodick why keep two issues for the same problem open?
What is the definition of 'fixed' here? With the latest Swatch module from 2.2-develop
we can import a new Swatch Option via the API method, however the required Admin value is empty: Magento\Catalog\Api\ProductAttributeOptionManagementInterface::add
I do not see anywhere in the \Magento\Eav\Api\Data\AttributeOptionInterface
to append Swatch information?
For example:
{
"option": {
"label": "API Test Label",
"value": "API Test Value",
"sort_order": 0,
"is_default": false,
"store_labels": [
{
"store_id": 0,
"label": "API Test Label Store 0"
},
{
"store_id": 1,
"label": "API Test Label Store 1"
}
]
}
}
Results in a half-populated Option:
Am I missing something?
i am also facing same issue could not find node to add hex code or image
url: http://{domain_name}/index.php/rest/V1/products/attributes/{attribute_code}/options
Method: POST
{
"option": {
"label": "default store label",
"value": "46477",
"sort_order": 0,
"is_default": false,
"store_labels": [
{
"store_id": 1,
"label": "en store label"
},
{
"store_id": 2,
"label": "NL store label"
},
{
"store_id": 3,
"label": "DE store label"
},
{
"store_id": 4,
"label": "FR store label"
}
]
}
}
Reopening for recheck by @magento-engcom-team.
@slavkodick, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
@magento-admin @magento-devops @magento-engcom-team I am facing the same issue. In Postman we are sending a soap request to create a new 'option' for a text/swatch attribute.
Post Body:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:def="XXX/soap/all?services=catalogProductAttributeOptionManagementV1" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<def:catalogProductAttributeOptionManagementV1AddRequest>
<attributeCode>d_textswatch</attributeCode>
<option>
<sortOrder>0</sortOrder>
<isDefault>false</isDefault>
<label>HelloE472</label>
<value/>
<store_labels>
<store_id>0</store_id>
<label>HelloE472_0</label>
</store_labels>
</option>
</def:catalogProductAttributeOptionManagementV1AddRequest>
</soap:Body>
</soap:Envelope>
With Magento 2.2.4 I am getting the error "Cannot save attribute %1". With Magento 2.2.0 I am getting response "true" but the option is not being created in Magento. See here
@magento-engcom-team Since you are unable to reproduce, please explain how you add an option with a hex code to an swatch attribute by using the rest api. YOU WILL NOT BE ABLE TO DO THIS, thats how you reproduce it. Next time please read the issue fully.
This is completely ridiculous!!
If the REST API is not supporting the creation of Visual Swatches with swatch options, you should write it down here!
This has been reproduced on a vanilla 2.3.3 installation running the standard demo data/Luma theme:
Steps to reproduce:
Example Payload
{
"option": {
"label": "Red",
"is_default": "false",
"sort_order": 0,
"store_labels": [
{
"store_id": 1,
"label": "Red"
}
]
}
}
eav_attribute_option_swatch
and observe a record is missing for the new attribute valueeav_attribute_option_swatch
Hi @engcom-Delta. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hi guys,
I tested this ticket on Magento Fresh 2.3 and found the problem of the issue.
My solution: after saved option to attribute, we will need to get option_id and add to swatch data, like this :
public function add($entityType, $attributeCode, $option)
{
if (empty($attributeCode)) {
throw new InputException(__('The attribute code is empty. Enter the code and try again.'));
}
$attribute = $this->attributeRepository->get($entityType, $attributeCode);
if (!$attribute->usesSource()) {
throw new StateException(__('The "%1" attribute doesn\'t work with options.', $attributeCode));
}
$optionLabel = $option->getLabel();
$optionId = $this->getOptionId($option);
$options = [];
$options['value'][$optionId][0] = $optionLabel;
$options['order'][$optionId] = $option->getSortOrder();
if (is_array($option->getStoreLabels())) {
foreach ($option->getStoreLabels() as $label) {
$options['value'][$optionId][$label->getStoreId()] = $label->getLabel();
}
}
if ($option->getIsDefault()) {
$attribute->setDefault([$optionId]);
}
$attribute->setOption($options);
try {
$this->resourceModel->save($attribute);
if ($optionLabel && $attribute->getAttributeCode()) {
$this->setOptionValue($option, $attribute, $optionLabel);
if($this->swatchHelper->isSwatchAttribute($attribute)) {
$this->saveSwatchValue($option, $attribute, $optionLabel);
}
}
} catch (\Exception $e) {
throw new StateException(__('The "%1" attribute can\'t be saved.', $attributeCode));
}
return $this->getOptionId($option);
}
private function saveSwatchValue(
\Magento\Eav\Api\Data\AttributeOptionInterface $option,
\Magento\Eav\Api\Data\AttributeInterface $attribute,
string $optionLabel
){
$optionId = $attribute->getSource()->getOptionId($optionLabel);
if ($optionId) {
$swatch['value'] = [$optionId => ''];
$attribute->unsOption();
$attribute->setSwatch($swatch);
$attribute->save();
} elseif (is_array($option->getStoreLabels())) {
foreach ($option->getStoreLabels() as $label) {
if ($optionId = $attribute->getSource()->getOptionId($label->getLabel())) {
$swatch['value'] = [$optionId => ''];
$attribute->unsOption();
$attribute->setSwatch($swatch);
$attribute->save();
break;
}
}
}
}
Hi @harperruss, thank you for your report. Unfortunately, I am not able to reproduce issue by steps you described on clean 2.4-develop.
Manual testing scenario:
{
"option": {
"label": "red",
"value": "#ff0000",
"is_default": "false",
"sort_order": 0,
"store_labels": [
{
"store_id": 1,
"label": "red default"
}
]
}
}
Result:
:heavy_check_mark: Color is added to Swatch on attribute edit page
Are you still facing this issue on the latest 2.4-develop
branch?
@engcom-Delta If you don't send the "value" in the payload or try null or "" it will not create a record in eav_attribute_option_swatch.
We are using visual swatches but the image is coming from the swatch image attribute attached to the product not as a hex colour defined against the attribute:
{
"option": {
"label": "red",
"is_default": "false",
"sort_order": 0,
"store_labels": [
{
"store_id": 1,
"label": "red default"
}
]
}
}
Or
{
"option": {
"label": "red",
"value": "",
"is_default": "false",
"sort_order": 0,
"store_labels": [
{
"store_id": 1,
"label": "red default"
}
]
}
}
Or
{
"option": {
"label": "red",
"value": null,
"is_default": "false",
"sort_order": 0,
"store_labels": [
{
"store_id": 1,
"label": "red default"
}
]
}
}
This is on 2.3.3 not 2.4
@harperruss could reproduce the issue in 2.4-develop
branch?
@diazwatson It looks like this has been fixed in 2.3.4
https://devdocs.magento.com/guides/v2.3/release-notes/release-notes-2-3-4-open-source.html#swatches
@harperruss it looks like, although it does not mention the commit where this was fixed, so we cannot see what was the actual fix. Is it possible for you to test in 2.3.4?
@harperruss how do you attach the Swatch image to the option?
Do you need to pass the image path in value or the base64 image encoding?
I only manage to attach a color via the HEX value.
@vincentteyssier No idea I'm afraid, it's not something I have needed to do
@harperruss if only they would have proper doc...
Guys I am closing this issue as it seems to be fixed.
Please feel free to re open if you thing is needed.
Most helpful comment
This is completely ridiculous!!
If the REST API is not supporting the creation of Visual Swatches with swatch options, you should write it down here!