Magento 2: How to set default option in configurable options?How to set default value in custom option in magento2Set default configurable selection in Magento 2.1Magento 2: How to set minimum amount option by default in product detail page for configurable options?How to set default option on configurable product dropdown attribute?Multi-select select option value issue Optionshow to set default color configurable productMagento2 override admin js fileSet default configurable selection in Magento 2.1How to make options default for multiselect attribute in Magento 2How to remove bundle options from product when loading the admin edit view?Default Custom Options by CategoryIf a configurable product has only one option available, should it automatically select it?Set first configurable product as default image
What is required to make GPS signals available indoors?
Finding the error in an argument
What historical events would have to change in order to make 19th century "steampunk" technology possible?
How can saying a song's name be a copyright violation?
Mathematica command that allows it to read my intentions
How does a dynamic QR code work?
Is it possible to map the firing of neurons in the human brain so as to stimulate artificial memories in someone else?
Can a virus destroy the BIOS of a modern computer?
How much mains leakage does an Ethernet connection to a PC induce, and what is the operating leakage path?
How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?
How to remove border from elements in the last row?
Does int main() need a declaration on C++?
Getting extremely large arrows with tikzcd
How to prevent "they're falling in love" trope
Am I breaking OOP practice with this architecture?
How to stretch the corners of this image so that it looks like a perfect rectangle?
Using "tail" to follow a file without displaying the most recent lines
What is the fastest integer factorization to break RSA?
Finitely generated matrix groups whose eigenvalues are all algebraic
Notepad++ delete until colon for every line with replace all
files created then deleted at every second in tmp directory
Processor speed limited at 0.4 Ghz
How to travel to Japan while expressing milk?
Should I tell management that I intend to leave due to bad software development practices?
Magento 2: How to set default option in configurable options?
How to set default value in custom option in magento2Set default configurable selection in Magento 2.1Magento 2: How to set minimum amount option by default in product detail page for configurable options?How to set default option on configurable product dropdown attribute?Multi-select select option value issue Optionshow to set default color configurable productMagento2 override admin js fileSet default configurable selection in Magento 2.1How to make options default for multiselect attribute in Magento 2How to remove bundle options from product when loading the admin edit view?Default Custom Options by CategoryIf a configurable product has only one option available, should it automatically select it?Set first configurable product as default image
How to set drops downs on configurable products to be set to the first option rather than please select.
I have tried below code:
<script>
require(['jquery', 'jquery/ui'], function($)
$('.product-add-form .field select').each(function(i, obj)
$(obj).find('option:eq(1)').prop('selected', true);
);
);
</script>
However, this fails unless I time it out a bit which feels messy. It also does not update price when using this method.
magento2 product multiselect-attribute
add a comment |
How to set drops downs on configurable products to be set to the first option rather than please select.
I have tried below code:
<script>
require(['jquery', 'jquery/ui'], function($)
$('.product-add-form .field select').each(function(i, obj)
$(obj).find('option:eq(1)').prop('selected', true);
);
);
</script>
However, this fails unless I time it out a bit which feels messy. It also does not update price when using this method.
magento2 product multiselect-attribute
You can try Rakesh's answer described below link. Hope it helps. magento.stackexchange.com/questions/142242/…
– Abhishek Panchal
Aug 14 '17 at 14:29
This is for swatches i have looked into this.
– harri
Aug 14 '17 at 14:29
add a comment |
How to set drops downs on configurable products to be set to the first option rather than please select.
I have tried below code:
<script>
require(['jquery', 'jquery/ui'], function($)
$('.product-add-form .field select').each(function(i, obj)
$(obj).find('option:eq(1)').prop('selected', true);
);
);
</script>
However, this fails unless I time it out a bit which feels messy. It also does not update price when using this method.
magento2 product multiselect-attribute
How to set drops downs on configurable products to be set to the first option rather than please select.
I have tried below code:
<script>
require(['jquery', 'jquery/ui'], function($)
$('.product-add-form .field select').each(function(i, obj)
$(obj).find('option:eq(1)').prop('selected', true);
);
);
</script>
However, this fails unless I time it out a bit which feels messy. It also does not update price when using this method.
magento2 product multiselect-attribute
magento2 product multiselect-attribute
edited Jan 24 '18 at 9:24
harri
asked Aug 14 '17 at 14:22
harriharri
3,0311655
3,0311655
You can try Rakesh's answer described below link. Hope it helps. magento.stackexchange.com/questions/142242/…
– Abhishek Panchal
Aug 14 '17 at 14:29
This is for swatches i have looked into this.
– harri
Aug 14 '17 at 14:29
add a comment |
You can try Rakesh's answer described below link. Hope it helps. magento.stackexchange.com/questions/142242/…
– Abhishek Panchal
Aug 14 '17 at 14:29
This is for swatches i have looked into this.
– harri
Aug 14 '17 at 14:29
You can try Rakesh's answer described below link. Hope it helps. magento.stackexchange.com/questions/142242/…
– Abhishek Panchal
Aug 14 '17 at 14:29
You can try Rakesh's answer described below link. Hope it helps. magento.stackexchange.com/questions/142242/…
– Abhishek Panchal
Aug 14 '17 at 14:29
This is for swatches i have looked into this.
– harri
Aug 14 '17 at 14:29
This is for swatches i have looked into this.
– harri
Aug 14 '17 at 14:29
add a comment |
2 Answers
2
active
oldest
votes
Override configurable.js within the Configurable Products Module. The following code can be placed at around line 370 of configurable.js:
if (i == 0)
this.options.values[attributeId] = options[i].id;
This is placed at the end of options loop so that the default option is set just after the first option is created for each attribute / select.
In the case that options were set in url the code for updating defaults was needed to run again to set the values correctly which can be achieved by adding below just outside of the loop:
if (window.location.href.indexOf('#') !== -1) this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1));
This is placed just after the for loop for options so that it's run just once at the end of the option creation.
So _fillSelect within configurable.js now should look like below:
_fillSelect: function (element)
var attributeId = element.id.replace(/[a-z]*/, ''),
options = this._getAttributeOptions(attributeId),
prevConfig,
index = 1,
allowedProducts,
i,
j;
this._clearSelect(element);
element.options[0] = new Option('', '');
element.options[0].innerHTML = this.options.spConfig.chooseText;
prevConfig = false;
if (element.prevSetting)
prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex];
if (options)
for (i = 0; i < options.length; i++)
allowedProducts = [];
if (prevConfig)
for (j = 0; j < options[i].products.length; j++)
// prevConfig.config can be undefined
if (prevConfig.config &&
prevConfig.config.allowedProducts &&
prevConfig.config.allowedProducts.indexOf(options[i].products[j]) > -1)
allowedProducts.push(options[i].products[j]);
else
allowedProducts = options[i].products.slice(0);
if (allowedProducts.length > 0)
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this._getOptionLabel(options[i]), options[i].id);
if (typeof options[i].price !== 'undefined')
element.options[index].setAttribute('price', options[i].prices);
element.options[index].config = options[i];
index++;
//new code here - updates the value to first option
if (i == 0)
this.options.values[attributeId] = options[i].id;
//new code here checks if configurations are set in url and resets them if needed
if (window.location.href.indexOf('#') !== -1) this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1));
,
Original file:
vendor/magento/module-configurable-product/view/frontend/web/js/configurable.js
Location when overridden in theme:
app/design/frontend/ThemeVendor/Theme/Magento_ConfigurableProduct/web/js/configurable.js
add a comment |
Override vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js
to your theme
your theme file location will be:
app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js
change _RenderControls() function
just wrinte below code at the end of this function
var swatchLength = $('.swatch-attribute').length;
if(swatchLength >= 1)
if($('.swatch-attribute').hasClass("size"))
$('.swatch-option').first().trigger('click');
http://prntscr.com/n6qo62
add a comment |
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%2f189088%2fmagento-2-how-to-set-default-option-in-configurable-options%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Override configurable.js within the Configurable Products Module. The following code can be placed at around line 370 of configurable.js:
if (i == 0)
this.options.values[attributeId] = options[i].id;
This is placed at the end of options loop so that the default option is set just after the first option is created for each attribute / select.
In the case that options were set in url the code for updating defaults was needed to run again to set the values correctly which can be achieved by adding below just outside of the loop:
if (window.location.href.indexOf('#') !== -1) this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1));
This is placed just after the for loop for options so that it's run just once at the end of the option creation.
So _fillSelect within configurable.js now should look like below:
_fillSelect: function (element)
var attributeId = element.id.replace(/[a-z]*/, ''),
options = this._getAttributeOptions(attributeId),
prevConfig,
index = 1,
allowedProducts,
i,
j;
this._clearSelect(element);
element.options[0] = new Option('', '');
element.options[0].innerHTML = this.options.spConfig.chooseText;
prevConfig = false;
if (element.prevSetting)
prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex];
if (options)
for (i = 0; i < options.length; i++)
allowedProducts = [];
if (prevConfig)
for (j = 0; j < options[i].products.length; j++)
// prevConfig.config can be undefined
if (prevConfig.config &&
prevConfig.config.allowedProducts &&
prevConfig.config.allowedProducts.indexOf(options[i].products[j]) > -1)
allowedProducts.push(options[i].products[j]);
else
allowedProducts = options[i].products.slice(0);
if (allowedProducts.length > 0)
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this._getOptionLabel(options[i]), options[i].id);
if (typeof options[i].price !== 'undefined')
element.options[index].setAttribute('price', options[i].prices);
element.options[index].config = options[i];
index++;
//new code here - updates the value to first option
if (i == 0)
this.options.values[attributeId] = options[i].id;
//new code here checks if configurations are set in url and resets them if needed
if (window.location.href.indexOf('#') !== -1) this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1));
,
Original file:
vendor/magento/module-configurable-product/view/frontend/web/js/configurable.js
Location when overridden in theme:
app/design/frontend/ThemeVendor/Theme/Magento_ConfigurableProduct/web/js/configurable.js
add a comment |
Override configurable.js within the Configurable Products Module. The following code can be placed at around line 370 of configurable.js:
if (i == 0)
this.options.values[attributeId] = options[i].id;
This is placed at the end of options loop so that the default option is set just after the first option is created for each attribute / select.
In the case that options were set in url the code for updating defaults was needed to run again to set the values correctly which can be achieved by adding below just outside of the loop:
if (window.location.href.indexOf('#') !== -1) this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1));
This is placed just after the for loop for options so that it's run just once at the end of the option creation.
So _fillSelect within configurable.js now should look like below:
_fillSelect: function (element)
var attributeId = element.id.replace(/[a-z]*/, ''),
options = this._getAttributeOptions(attributeId),
prevConfig,
index = 1,
allowedProducts,
i,
j;
this._clearSelect(element);
element.options[0] = new Option('', '');
element.options[0].innerHTML = this.options.spConfig.chooseText;
prevConfig = false;
if (element.prevSetting)
prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex];
if (options)
for (i = 0; i < options.length; i++)
allowedProducts = [];
if (prevConfig)
for (j = 0; j < options[i].products.length; j++)
// prevConfig.config can be undefined
if (prevConfig.config &&
prevConfig.config.allowedProducts &&
prevConfig.config.allowedProducts.indexOf(options[i].products[j]) > -1)
allowedProducts.push(options[i].products[j]);
else
allowedProducts = options[i].products.slice(0);
if (allowedProducts.length > 0)
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this._getOptionLabel(options[i]), options[i].id);
if (typeof options[i].price !== 'undefined')
element.options[index].setAttribute('price', options[i].prices);
element.options[index].config = options[i];
index++;
//new code here - updates the value to first option
if (i == 0)
this.options.values[attributeId] = options[i].id;
//new code here checks if configurations are set in url and resets them if needed
if (window.location.href.indexOf('#') !== -1) this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1));
,
Original file:
vendor/magento/module-configurable-product/view/frontend/web/js/configurable.js
Location when overridden in theme:
app/design/frontend/ThemeVendor/Theme/Magento_ConfigurableProduct/web/js/configurable.js
add a comment |
Override configurable.js within the Configurable Products Module. The following code can be placed at around line 370 of configurable.js:
if (i == 0)
this.options.values[attributeId] = options[i].id;
This is placed at the end of options loop so that the default option is set just after the first option is created for each attribute / select.
In the case that options were set in url the code for updating defaults was needed to run again to set the values correctly which can be achieved by adding below just outside of the loop:
if (window.location.href.indexOf('#') !== -1) this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1));
This is placed just after the for loop for options so that it's run just once at the end of the option creation.
So _fillSelect within configurable.js now should look like below:
_fillSelect: function (element)
var attributeId = element.id.replace(/[a-z]*/, ''),
options = this._getAttributeOptions(attributeId),
prevConfig,
index = 1,
allowedProducts,
i,
j;
this._clearSelect(element);
element.options[0] = new Option('', '');
element.options[0].innerHTML = this.options.spConfig.chooseText;
prevConfig = false;
if (element.prevSetting)
prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex];
if (options)
for (i = 0; i < options.length; i++)
allowedProducts = [];
if (prevConfig)
for (j = 0; j < options[i].products.length; j++)
// prevConfig.config can be undefined
if (prevConfig.config &&
prevConfig.config.allowedProducts &&
prevConfig.config.allowedProducts.indexOf(options[i].products[j]) > -1)
allowedProducts.push(options[i].products[j]);
else
allowedProducts = options[i].products.slice(0);
if (allowedProducts.length > 0)
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this._getOptionLabel(options[i]), options[i].id);
if (typeof options[i].price !== 'undefined')
element.options[index].setAttribute('price', options[i].prices);
element.options[index].config = options[i];
index++;
//new code here - updates the value to first option
if (i == 0)
this.options.values[attributeId] = options[i].id;
//new code here checks if configurations are set in url and resets them if needed
if (window.location.href.indexOf('#') !== -1) this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1));
,
Original file:
vendor/magento/module-configurable-product/view/frontend/web/js/configurable.js
Location when overridden in theme:
app/design/frontend/ThemeVendor/Theme/Magento_ConfigurableProduct/web/js/configurable.js
Override configurable.js within the Configurable Products Module. The following code can be placed at around line 370 of configurable.js:
if (i == 0)
this.options.values[attributeId] = options[i].id;
This is placed at the end of options loop so that the default option is set just after the first option is created for each attribute / select.
In the case that options were set in url the code for updating defaults was needed to run again to set the values correctly which can be achieved by adding below just outside of the loop:
if (window.location.href.indexOf('#') !== -1) this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1));
This is placed just after the for loop for options so that it's run just once at the end of the option creation.
So _fillSelect within configurable.js now should look like below:
_fillSelect: function (element)
var attributeId = element.id.replace(/[a-z]*/, ''),
options = this._getAttributeOptions(attributeId),
prevConfig,
index = 1,
allowedProducts,
i,
j;
this._clearSelect(element);
element.options[0] = new Option('', '');
element.options[0].innerHTML = this.options.spConfig.chooseText;
prevConfig = false;
if (element.prevSetting)
prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex];
if (options)
for (i = 0; i < options.length; i++)
allowedProducts = [];
if (prevConfig)
for (j = 0; j < options[i].products.length; j++)
// prevConfig.config can be undefined
if (prevConfig.config &&
prevConfig.config.allowedProducts &&
prevConfig.config.allowedProducts.indexOf(options[i].products[j]) > -1)
allowedProducts.push(options[i].products[j]);
else
allowedProducts = options[i].products.slice(0);
if (allowedProducts.length > 0)
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this._getOptionLabel(options[i]), options[i].id);
if (typeof options[i].price !== 'undefined')
element.options[index].setAttribute('price', options[i].prices);
element.options[index].config = options[i];
index++;
//new code here - updates the value to first option
if (i == 0)
this.options.values[attributeId] = options[i].id;
//new code here checks if configurations are set in url and resets them if needed
if (window.location.href.indexOf('#') !== -1) this._parseQueryParams(window.location.href.substr(window.location.href.indexOf('#') + 1));
,
Original file:
vendor/magento/module-configurable-product/view/frontend/web/js/configurable.js
Location when overridden in theme:
app/design/frontend/ThemeVendor/Theme/Magento_ConfigurableProduct/web/js/configurable.js
edited Aug 8 '18 at 18:59
answered Aug 14 '17 at 15:07
harriharri
3,0311655
3,0311655
add a comment |
add a comment |
Override vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js
to your theme
your theme file location will be:
app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js
change _RenderControls() function
just wrinte below code at the end of this function
var swatchLength = $('.swatch-attribute').length;
if(swatchLength >= 1)
if($('.swatch-attribute').hasClass("size"))
$('.swatch-option').first().trigger('click');
http://prntscr.com/n6qo62
add a comment |
Override vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js
to your theme
your theme file location will be:
app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js
change _RenderControls() function
just wrinte below code at the end of this function
var swatchLength = $('.swatch-attribute').length;
if(swatchLength >= 1)
if($('.swatch-attribute').hasClass("size"))
$('.swatch-option').first().trigger('click');
http://prntscr.com/n6qo62
add a comment |
Override vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js
to your theme
your theme file location will be:
app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js
change _RenderControls() function
just wrinte below code at the end of this function
var swatchLength = $('.swatch-attribute').length;
if(swatchLength >= 1)
if($('.swatch-attribute').hasClass("size"))
$('.swatch-option').first().trigger('click');
http://prntscr.com/n6qo62
Override vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js
to your theme
your theme file location will be:
app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js
change _RenderControls() function
just wrinte below code at the end of this function
var swatchLength = $('.swatch-attribute').length;
if(swatchLength >= 1)
if($('.swatch-attribute').hasClass("size"))
$('.swatch-option').first().trigger('click');
http://prntscr.com/n6qo62
answered 2 mins ago
Jigs ParmarJigs Parmar
1,132423
1,132423
add a comment |
add a comment |
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%2f189088%2fmagento-2-how-to-set-default-option-in-configurable-options%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
You can try Rakesh's answer described below link. Hope it helps. magento.stackexchange.com/questions/142242/…
– Abhishek Panchal
Aug 14 '17 at 14:29
This is for swatches i have looked into this.
– harri
Aug 14 '17 at 14:29