-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Question: Object Manager objects' get methods return 1 #1760
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
Comments
At least one thing that is wrong on first glance is that you are printing the return value of |
Thank @Vinai! I was not aware of the second param to print_r. I figured out my error though. $orderID = $session->getLastOrderId() returns an integer while loadByIncrementId() looks for the string with leading zeros. Calling: loadByIncrementId("0000000".$orderID); temporarily fixed it, but I'll look for a method that returns the id as the full string. |
Great! Just a plain old |
No I was unaware - what is the better way? |
You simply declare the dependencies you need in your class constructor, and they will be automatically injected when your class in created by the object manager. public function __construct(\Magento\Sales\Model\OrderFactory $orderFactory)
{
$this->orderFactory = $orderFactory;
} Now, every time you need an order instance, you call $order = $this->orderFactory->create()->load($orderId); Since you where working in a core class and outputting HTML in a PHP class I assumed you where just playing around, which is fine. But if you want to do real customizations, that is not the best thing to do. |
Thanks for all the help @Vinai! That worked, but for anyone else looking at this, I also had to add the field above the constructor. /**
* @var \Magento\Sales\Model\OrderFactory
*/
protected $orderFactory; |
Hi @CoreyCole. Thank you for your report.
The fix will be available with the upcoming 2.4.2 release. |
…ed Media Gallery" disabled #29632
Hello, I'm trying to print data to the success page about the most recent order placed. In
app/code/Magento/Checkout/Controller/Onepage/Success.php
I've added the following php:I know it's working to some degree. The page is loading without errors and in the admin panel, I confirmed that the order is being placed with the printed $orderID with valid data. However, only the $orderID seems to be printing correctly. The output div comes out as follows:
Sorry if this is a rudimentary question, but I've been struggling with this for a while. I can't find any pages in the php developer guide docs about interacting with the model. What am I doing wrong?
The text was updated successfully, but these errors were encountered: