Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix > Exception #0 (BadMethodCallException): Missing required argument $msrpPriceCalculators of Magento\Msrp\Pricing\MsrpPriceCalculator. #22197

Conversation

lfluvisotto
Copy link
Contributor

@lfluvisotto lfluvisotto commented Apr 8, 2019

Description (*)

Fix > Exception #0 (BadMethodCallException): Missing required argument $msrpPriceCalculators of Magento\Msrp\Pricing\MsrpPriceCalculator.

The possible solution is a workaround for the case of modules Magento_MsrpConfigurableProduct and Magento_MsrpGroupedProduct are disabled.

Fixed Issues (if relevant)

#22090 MsrpPriceCalculator exception after upgrade to 2.3.1

#22190: Exception (BadMethodCallException): Missing required argument $msrpPriceCalculators of Magento\Msrp\Pricing\MsrpPriceCalculator.

Manual testing scenarios (*)

  1. Disable Magento_MsrpConfigurableProduct and Magento_MsrpGroupedProduct modules, Magento_Msrp should work properly.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@m2-assistant
Copy link

m2-assistant bot commented Apr 8, 2019

Hi @lfluvisotto. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@ghost
Copy link

ghost commented Apr 8, 2019

@lfluvisotto unfortunately, only members of the maintainers team are allowed to assign developers to the pull request

1 similar comment
@ghost
Copy link

ghost commented Apr 8, 2019

@lfluvisotto unfortunately, only members of the maintainers team are allowed to assign developers to the pull request

@lfluvisotto lfluvisotto requested a review from orlangur April 8, 2019 15:25
@davidverholen
Copy link
Member

@lfluvisotto I think it should be sufficient to set the default value in the constructor to an empty array
This way the value is not required anymore which would fix the first error.

/**
 * @param array $msrpPriceCalculators
 */
public function __construct(array $msrpPriceCalculators = [])
{
     $this->msrpPriceCalculators = $this->getMsrpPriceCalculators($msrpPriceCalculators);
}

The foreach in getMsrpPriceCalculators then just does nothing (if the other modules are disabled) and the getMsrpPriceValue should fall back to the default case $msrp = (float)$product->getMsrp();

@lfluvisotto lfluvisotto force-pushed the 2.3-develop-BadMethodCallException branch from 040f206 to 7522b53 Compare April 8, 2019 16:20
@lfluvisotto
Copy link
Contributor Author

@davidverholen

Sure, nice, I did the change.

…t of Magento\Msrp\Pricing\MsrpPriceCalculator.
@lfluvisotto lfluvisotto force-pushed the 2.3-develop-BadMethodCallException branch from 7522b53 to 1c98b32 Compare April 8, 2019 16:53
@lfluvisotto lfluvisotto requested a review from orlangur April 8, 2019 16:54
@magento-engcom-team
Copy link
Contributor

Hi @orlangur, thank you for the review.
ENGCOM-4706 has been created to process this Pull Request

@VasylShvorak VasylShvorak self-assigned this Apr 12, 2019
@VasylShvorak
Copy link
Contributor

✔️ QA passed

@cds-magento2
Copy link

cds-magento2 commented Apr 16, 2019

Is there an eta for a fix release? We are trying to upgrade to 2.3.1 and getting this error.
We are also seeing this error: report.CRITICAL:
Type Error occurred when creating object: Magento\Msrp\Pricing\MsrpPriceCalculator {"exception":"[object] (Magento\Framework\Exception\RuntimeException(code: 0): Type Error occurred when creating object: Magento\Msrp\Pricing\MsrpPriceCalculator at /opt/magento/demo/releases/20190416153530/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:124)"} []

@orlangur
Copy link
Contributor

@cds-magento2 you can use fix from this PR, it is pretty trivial. Fix will be released no earlier than 2.3.2 is out.

@janmyszkier
Copy link

janmyszkier commented Apr 18, 2019

this PR doesn't solve the initial isue which is passing null into the method in the first place.
if you pass a null it will still try to pas it to $this->getMsrpPriceCalculators as null (because you HAVE PROVIDED null. defaul values only work when you didn't pass anything.

\Magento\Msrp\Pricing\MsrpPriceCalculator::getMsrpPriceCalculators will also fail for the same reason the argument being null because it also requires an array and will throw the same error as
\Magento\Msrp\Pricing\MsrpPriceCalculator::__construct

Please make a testcase for PR a requirement.
simple code as this:

<?php
declare(strict_types=1);
class Test {
  function test1($argument = []){
    var_dump($argument);
  }
}

$test = new Test();
$test->test1(null);

would confirm the value is STILL null after providing the default values of [] and this PR doesn't completely solve the issue.

@davidverholen
Copy link
Member

@janmyszkier are you sure? why would someone pass null to it? The object manager should (and normally does) pass nothing if there is no di configuration and so the default value should be taken

@orlangur
Copy link
Contributor

@janmyszkier,

the initial issue which is passing null into the method in the first place

I believe you didn't understand root cause of the issue correctly, try more :)

@magento-engcom-team magento-engcom-team merged commit 1c98b32 into magento:2.3-develop Apr 18, 2019
@m2-assistant
Copy link

m2-assistant bot commented Apr 18, 2019

Hi @lfluvisotto, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

magento-engcom-team pushed a commit that referenced this pull request Apr 18, 2019
…uired argument $msrpPriceCalculators of Magento\Msrp\Pricing\MsrpPriceCalculator. #22197
@magento-engcom-team magento-engcom-team added this to the Release: 2.3.2 milestone Apr 18, 2019
@janmyszkier
Copy link

@orlangur truth is: the issue with passing null is different from initial comment in this thread (my bad), the issue with null is still there for multicurrency setup though but since I fixed this internally with an override I'll wait for 2.3.2 and maybe submit separate issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants