Skip to content

Unable to save edited product when max_sale_qty is Magento's default #23319

Closed
@sol0mandra

Description

@sol0mandra

Preconditions (*)

  1. Install Magento Open Source 2.3.1

Steps to reproduce (*)

  1. Go to admin area
  2. Go to Stores->Configuration->Catalog->Inventory->Product Stock Options
  3. Edit the global default to be 0
  4. Save the config
  5. Open create a simple product form and fill in minimum required data
  6. Open the advanced inventory popup
  7. Uncheck the checkbox "use_config_max_sale_qty"
  8. Observe the default value of 0 in max_sale_qty field
  9. Do not edit the default provided
  10. Click Save

Expected result (*)

  1. Product is successfully saved

Actual result (*)

  1. Save is not happening, validation is failed due to validate-grater-then-0 on max_sale_qty field.

This value however comes from the cataloginventory's db_schema (module-catalog-inventory/etc/db_schema.xml):

<table name="cataloginventory_stock_item" resource="default" engine="innodb" comment="Cataloginventory Stock Item">
...
<column xsi:type="decimal" name="max_sale_qty" scale="4" precision="12" unsigned="false" **nullable="false"
                default="0"** comment="Max Sale Qty"/>
...
</table>

While in the same module, in magento/module-catalog-inventory/view/adminhtml/ui_component/product_form.xml:

<field name="max_sale_qty" formElement="input">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="value" xsi:type="object">Magento\CatalogInventory\Model\Source\StockConfiguration</item>
        </item>
    </argument>
    <settings>
        <scopeLabel>[GLOBAL]</scopeLabel>
        <validation>
            <rule name="**validate-greater-than-zero**" xsi:type="boolean">true</rule>
        </validation>
        <label translate="true">Maximum Qty Allowed in Shopping Cart</label>
        <dataScope>max_sale_qty</dataScope>
    </settings>
</field>

And in the same module, inmodule-catalog-inventory/etc/adminhtml/system.xml:

<section id="cataloginventory" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
...
<group id="item_options" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
...
<field id="max_sale_qty" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                    <label>Maximum Qty Allowed in Shopping Cart</label>
                    <validate>**validate-number**</validate>
                </field>


So, there is inconsistency - if 0 is allowed as value for max_sale_qty. If 0 is set from the start as default, there shouldn't be validation that would forbid it on the frontend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: InventoryFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentProgress: PR CreatedIndicates that Pull Request has been created to fix issueReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions