Skip to content

2.4 : When saving a product using the product repository, the price is not saved #13639

Closed
@kanduvisla

Description

@kanduvisla

I'm trying to programmatically create a product, but upon the first save, the price is not saved, thus returning 'NULL'. On a second save (with the identical object), the price gets saved.

Preconditions

  1. Magento 2.4-develop
  2. php v 7.2

Steps to reproduce

/** @var \Magento\Catalog\Model\Product $product */
$product = $this->productFactory->create();
$product->setSku('abc');
$product->setName('Name');
$product->setPrice(9.95);
$product->setAttributeSetId(4);

// Save once, the price does not get saved:
$this->productRepository->save($product);

// Check if the product is saved:
$product = $this->productRepository->get('abc');
$this->assertEquals('abc', $product->getSku());          // passes
$this->assertEquals('Name', $product->getName());  // passes
$this->assertEquals(9.95, $product->getPrice());  // fails (null does not equal 9.95

When I add an extra save()-instruction it works:

// Save twice, the price gets saved:
$this->productRepository->save($product);
$this->productRepository->save($product);

Expected result

The price should be saved in the first run

Actual result

The price only gets saved the second time the save()-method is executed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ApiUse with concrete module component label E.g. "Component: Api" + "Catalog"Component: CatalogEvent: dmcdindia1Fixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: 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: P2A defect with this priority could have functionality issues which are not to expectations.Progress: PR in progressProgress: doneReproduced 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 releaseReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S2Major restrictions or short-term circumventions are required until a fix is available.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions