Skip to content

setHasOptions when save product #25754

Open
@bernd-reindl

Description

@bernd-reindl

Preconditions (*)

Magento 2.3.3 & 2.3-develop

Steps to reproduce (*)

Check values in the catalog_product_entity table before

  1. Load a product (type_id 'bundle') in a custom module ($model->load($entityId);)
  2. change any value ($model->setAnyValue('test');)
  3. save the product (model->save();)

You can use this code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productFactory = $objectManager->create('\Magento\Catalog\Model\ProductFactory');
$product = $productFactory->create();
$sku = 'testbundle';
$product->load($product->getIdBySku($sku));
$product->setSku('Test1234');
$product->save();

Expected result (*)

  1. the fields 'has_options' and 'required_options' should not changed because there are no modifications in custom options or bundle options.

Actual result (*)

  1. the fields 'has_options' and 'required_options' has changed to 0 (before save it was 1) because in module-catalog/Model/Product.php in function 'beforeSave' the values for 'has_options' and 'required_options' was set to false. But i think this values should only changed if 'canAffectOptions()' returns true. Else 'canAffectOptions()' would not make any sense. See comment (Set false, ONLY if options have been affected by Options tab and Type instance tab)

My solution is to comment out '$this->setHasOptions(false);' ans '$this->setRequiredOptions(false);' at the beginning of beforeSave because this values will be set to false later by condition '} elseif ($this->canAffectOptions()) {'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ModelEvent: mm20inIssue: 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 developmentPriority: P3May be fixed according to the position in the backlog.Progress: dev in progressReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions