3

On a specific product I cannot save any changes at all, I always get the error:

Invalid option value

I believe this is down to the custom options and probably this issue: https://github.com/magento/magento2/issues/4085

I was on 2.1.0rc3 when the error occurred and have since upgraded to 2.1.1

It's not just that I can't save custom options, I can't save any changes at all even to basic fields such as product name.

Maybe the issue is something else, but I can't find any clues in the logs and the error message is not very helpful.

4

When you have a product with more than 20 values for a custom options Magento adds pagination to this option. See screenshot attached. Below right, pagination. If you want to save this product you have to go through every page of every custom option of that product.

Technical explantion, Magento is using dynamic rows to load this behaviour, if you don't open the second, or third page, the input fields are not added to the HTML. When you save the product those options aren't in the POST values. In the POST Magento is checking if the values are equal but they aren't, because they are not added to the HTML. So the quick fix for now is to go through every page of every custom option and then you can save the product

enter image description here

  • thanks @zeeshan khuwaja you have saved my time thank you so much yar – Nagaraju Kasa Oct 24 '17 at 5:35
  • Hi Zeeshan Khuwaja, I have imported the custom options from another product which has got 31. While the product is being saved, the sort order for last 11 custom option is not set. I have worked out as you said, thank you it worked well!... Is there any fix could be given for saving the custom options with sort order without traversing through the pagination. – Haritha Dec 30 '17 at 7:45
  • Open your server's php.ini file with root user, search for max_input_vars and set its value as 100000 and it will solve your problem. max_input_vars = 100000 – user53816 Feb 1 '18 at 5:56
  • I am using the mageworx advance product option extension and still there is no pagination.Still i am not able to save the product.it show me 'invalid custom option ' error.Have you any solution? – Sunny Rahevar Nov 20 '18 at 11:15
2

I have the same issue, we have customize the code and override the file.

For override core file we need to follow the step:
/vendor_name/module_name/etc/di.xml

 <?xml version="1.0"?>
  <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <preference for="Magento\Catalog\Model\Product\Option\Validator\Select" type="Vendor_name\Module_name\Model\Product\Option\Validator\Select" />
  </config>

Add this file in Model: vendor_name/Module_name/Model/Product/Option/Validator/Select

<?php
namespace Vendor_name\Module_name\Model\Product\Option\Validator;

class Select extends \Magento\Catalog\Model\Product\Option\Validator\Select
{
/**
 * Validate option price
 *
 * @param string $priceType
 * @param int $price
 * @param int $storeId
 * @return bool
 */
protected function isValidOptionPrice($priceType, $price, $storeId)
{
    // we should be able to remove website values for default store fallback
    if ($storeId > \Magento\Store\Model\Store::DEFAULT_STORE_ID && $priceType === null && $price === null) {
        return true;
    }

    if (!$priceType && !$price) {
        return true;
    }
    if (!$this->isInRange($priceType, $this->priceTypes) || $this->isNegative($price)) {
        return false;
    }

    return true;
 }
}
  • Nice code... It's work perfectly....Thank you @Karthik – Sumit Gupta Apr 5 '18 at 6:11
  • 1
    Welcome @SumitGupta – karthik Apr 5 '18 at 6:12
1

Open your server's php.ini file with root user, search for max_input_vars and set its value as 100000 and it will solve your problem.

max_input_vars = 100000
0

I had the same issue. My solution is to fill in the SKU values for the costumisable options that you added to your product.

As I understand this error accurs only if you have a big number of custom options in your product. According to my experience about 20 values divided between 2-3 customisable options does not result in error. 50 values for 4-5 options results in this error. However as mentioned before, if you fill in the specific SKU (they can even be all the same) you can save the product without any problems.

Hope it helps!

0

For reference, in versions without paging with multiple stores and over 1000 fields on a particular page - a solution that I've come accross is to increase PHP max_input_vars, which will allow PHP to process more than the default (from memory it was 1000) number of fields at one time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.