How to check uniquenes of color options when adding a color magento 2?Retrieve Product Attribute Label in event catalog_entity_attribute_save_beforeChange Product Description when clicking Color SwatchProduct image according to selected color option on cart page MagentoHow to add color picker to watches?How to change Magento 2 backend color?How color swatches work?how to create two different form to customer registration magento 2Customise the scrip of export Magento 2Override export page under system data transfer export magento 2how to create a dropdown attribute for product with dynamic options M2How to display options of custom attribute product magento 2?
Difference between > and >> when used with a named pipe
Did Milano or Benatar approve or comment on their namesake MCU ships?
Does an ice chest packed full of frozen food need ice?
Why was the Sega Genesis marketed as a 16-bit console?
Were Alexander the Great and Hephaestion lovers?
Someone whose aspirations exceed abilities or means
Taxi Services at Didcot
How did old MS-DOS games utilize various graphic cards?
A curious prime counting approximation or just data overfitting?
Second (easy access) account in case my bank screws up
How to handle self harm scars on the arm in work environment?
Grover algorithm for a database search: where is the quantum advantage?
How to construct an hbox with negative height?
Is counterpoint still used today?
Confusion around using "des" in sentences
Using "subway" as name for London Underground?
How does an ordinary object become radioactive?
PhD - Well known professor or well known school?
What to do when surprise and a high initiative roll conflict with the narrative?
Character descriptions
Should an arbiter claim draw at a K+R vs K+R endgame?
Should I give professor gift at the beginning of my PhD?
Impedance ratio vs. SWR
Share calendar details request from manager's manager
How to check uniquenes of color options when adding a color magento 2?
Retrieve Product Attribute Label in event catalog_entity_attribute_save_beforeChange Product Description when clicking Color SwatchProduct image according to selected color option on cart page MagentoHow to add color picker to watches?How to change Magento 2 backend color?How color swatches work?how to create two different form to customer registration magento 2Customise the scrip of export Magento 2Override export page under system data transfer export magento 2how to create a dropdown attribute for product with dynamic options M2How to display options of custom attribute product magento 2?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want that when i add an existing color an exception will be raised so how to proceed and which file do i have to override and thanks in advance.
magento2 color-swatches unique-constraint
add a comment |
I want that when i add an existing color an exception will be raised so how to proceed and which file do i have to override and thanks in advance.
magento2 color-swatches unique-constraint
add a comment |
I want that when i add an existing color an exception will be raised so how to proceed and which file do i have to override and thanks in advance.
magento2 color-swatches unique-constraint
I want that when i add an existing color an exception will be raised so how to proceed and which file do i have to override and thanks in advance.
magento2 color-swatches unique-constraint
magento2 color-swatches unique-constraint
edited May 30 at 8:40
TN98
8810
8810
asked May 30 at 8:26
Developper Magento Developper Magento
616212
616212
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can create a custom function to check color value already exists or not as follows:
protected $_resource;
public function __construct(
MagentoFrameworkAppResourceConnection $resource
)
$this->_resource = $resource;
public function checkColorExists($color)
$connection = $this->_resource->getConnection(MagentoFrameworkAppResourceConnection::DEFAULT_CONNECTION);
$result = $connection->fetchAll("SELECT DISTINCT value FROM `eav_attribute_option_value` WHERE option_id IN (SELECT option_id FROM `eav_attribute_option` WHERE `attribute_id` = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'color'))");
foreach ($result as &$value)
$value = $value['value'];
if (in_array($color, $result))
// Throw exception
else
return true;
Hope this may helpful!
do i have to put this code in observer event catalog_entity_attribute_save_before to check or in other place and thanks for your replay
– Developper Magento
May 30 at 9:33
Thanks for the upvote. I have not tried yet catalog_entity_attribute_save_before event, but yes ofcourse try once. And if works fine, then please accept this answer.
– Dhara Bhatti
May 30 at 9:36
ok i will check this immediatly
– Developper Magento
May 30 at 9:42
i can't understand this part of your code foreach ($result as &$value) $value = $value['value']; what that mean
– Developper Magento
May 30 at 9:48
Please do echo "<pre>"; print_r($result); before and after foreach. You will get idea.
– Dhara Bhatti
May 30 at 9:50
|
show 13 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276699%2fhow-to-check-uniquenes-of-color-options-when-adding-a-color-magento-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can create a custom function to check color value already exists or not as follows:
protected $_resource;
public function __construct(
MagentoFrameworkAppResourceConnection $resource
)
$this->_resource = $resource;
public function checkColorExists($color)
$connection = $this->_resource->getConnection(MagentoFrameworkAppResourceConnection::DEFAULT_CONNECTION);
$result = $connection->fetchAll("SELECT DISTINCT value FROM `eav_attribute_option_value` WHERE option_id IN (SELECT option_id FROM `eav_attribute_option` WHERE `attribute_id` = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'color'))");
foreach ($result as &$value)
$value = $value['value'];
if (in_array($color, $result))
// Throw exception
else
return true;
Hope this may helpful!
do i have to put this code in observer event catalog_entity_attribute_save_before to check or in other place and thanks for your replay
– Developper Magento
May 30 at 9:33
Thanks for the upvote. I have not tried yet catalog_entity_attribute_save_before event, but yes ofcourse try once. And if works fine, then please accept this answer.
– Dhara Bhatti
May 30 at 9:36
ok i will check this immediatly
– Developper Magento
May 30 at 9:42
i can't understand this part of your code foreach ($result as &$value) $value = $value['value']; what that mean
– Developper Magento
May 30 at 9:48
Please do echo "<pre>"; print_r($result); before and after foreach. You will get idea.
– Dhara Bhatti
May 30 at 9:50
|
show 13 more comments
You can create a custom function to check color value already exists or not as follows:
protected $_resource;
public function __construct(
MagentoFrameworkAppResourceConnection $resource
)
$this->_resource = $resource;
public function checkColorExists($color)
$connection = $this->_resource->getConnection(MagentoFrameworkAppResourceConnection::DEFAULT_CONNECTION);
$result = $connection->fetchAll("SELECT DISTINCT value FROM `eav_attribute_option_value` WHERE option_id IN (SELECT option_id FROM `eav_attribute_option` WHERE `attribute_id` = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'color'))");
foreach ($result as &$value)
$value = $value['value'];
if (in_array($color, $result))
// Throw exception
else
return true;
Hope this may helpful!
do i have to put this code in observer event catalog_entity_attribute_save_before to check or in other place and thanks for your replay
– Developper Magento
May 30 at 9:33
Thanks for the upvote. I have not tried yet catalog_entity_attribute_save_before event, but yes ofcourse try once. And if works fine, then please accept this answer.
– Dhara Bhatti
May 30 at 9:36
ok i will check this immediatly
– Developper Magento
May 30 at 9:42
i can't understand this part of your code foreach ($result as &$value) $value = $value['value']; what that mean
– Developper Magento
May 30 at 9:48
Please do echo "<pre>"; print_r($result); before and after foreach. You will get idea.
– Dhara Bhatti
May 30 at 9:50
|
show 13 more comments
You can create a custom function to check color value already exists or not as follows:
protected $_resource;
public function __construct(
MagentoFrameworkAppResourceConnection $resource
)
$this->_resource = $resource;
public function checkColorExists($color)
$connection = $this->_resource->getConnection(MagentoFrameworkAppResourceConnection::DEFAULT_CONNECTION);
$result = $connection->fetchAll("SELECT DISTINCT value FROM `eav_attribute_option_value` WHERE option_id IN (SELECT option_id FROM `eav_attribute_option` WHERE `attribute_id` = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'color'))");
foreach ($result as &$value)
$value = $value['value'];
if (in_array($color, $result))
// Throw exception
else
return true;
Hope this may helpful!
You can create a custom function to check color value already exists or not as follows:
protected $_resource;
public function __construct(
MagentoFrameworkAppResourceConnection $resource
)
$this->_resource = $resource;
public function checkColorExists($color)
$connection = $this->_resource->getConnection(MagentoFrameworkAppResourceConnection::DEFAULT_CONNECTION);
$result = $connection->fetchAll("SELECT DISTINCT value FROM `eav_attribute_option_value` WHERE option_id IN (SELECT option_id FROM `eav_attribute_option` WHERE `attribute_id` = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'color'))");
foreach ($result as &$value)
$value = $value['value'];
if (in_array($color, $result))
// Throw exception
else
return true;
Hope this may helpful!
answered May 30 at 9:18
Dhara BhattiDhara Bhatti
427112
427112
do i have to put this code in observer event catalog_entity_attribute_save_before to check or in other place and thanks for your replay
– Developper Magento
May 30 at 9:33
Thanks for the upvote. I have not tried yet catalog_entity_attribute_save_before event, but yes ofcourse try once. And if works fine, then please accept this answer.
– Dhara Bhatti
May 30 at 9:36
ok i will check this immediatly
– Developper Magento
May 30 at 9:42
i can't understand this part of your code foreach ($result as &$value) $value = $value['value']; what that mean
– Developper Magento
May 30 at 9:48
Please do echo "<pre>"; print_r($result); before and after foreach. You will get idea.
– Dhara Bhatti
May 30 at 9:50
|
show 13 more comments
do i have to put this code in observer event catalog_entity_attribute_save_before to check or in other place and thanks for your replay
– Developper Magento
May 30 at 9:33
Thanks for the upvote. I have not tried yet catalog_entity_attribute_save_before event, but yes ofcourse try once. And if works fine, then please accept this answer.
– Dhara Bhatti
May 30 at 9:36
ok i will check this immediatly
– Developper Magento
May 30 at 9:42
i can't understand this part of your code foreach ($result as &$value) $value = $value['value']; what that mean
– Developper Magento
May 30 at 9:48
Please do echo "<pre>"; print_r($result); before and after foreach. You will get idea.
– Dhara Bhatti
May 30 at 9:50
do i have to put this code in observer event catalog_entity_attribute_save_before to check or in other place and thanks for your replay
– Developper Magento
May 30 at 9:33
do i have to put this code in observer event catalog_entity_attribute_save_before to check or in other place and thanks for your replay
– Developper Magento
May 30 at 9:33
Thanks for the upvote. I have not tried yet catalog_entity_attribute_save_before event, but yes ofcourse try once. And if works fine, then please accept this answer.
– Dhara Bhatti
May 30 at 9:36
Thanks for the upvote. I have not tried yet catalog_entity_attribute_save_before event, but yes ofcourse try once. And if works fine, then please accept this answer.
– Dhara Bhatti
May 30 at 9:36
ok i will check this immediatly
– Developper Magento
May 30 at 9:42
ok i will check this immediatly
– Developper Magento
May 30 at 9:42
i can't understand this part of your code foreach ($result as &$value) $value = $value['value']; what that mean
– Developper Magento
May 30 at 9:48
i can't understand this part of your code foreach ($result as &$value) $value = $value['value']; what that mean
– Developper Magento
May 30 at 9:48
Please do echo "<pre>"; print_r($result); before and after foreach. You will get idea.
– Dhara Bhatti
May 30 at 9:50
Please do echo "<pre>"; print_r($result); before and after foreach. You will get idea.
– Dhara Bhatti
May 30 at 9:50
|
show 13 more comments
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276699%2fhow-to-check-uniquenes-of-color-options-when-adding-a-color-magento-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown