Closed Nuranto closed 11 months ago
Hi @Nuranto. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hello @Nuranto,
Thanks for the report and collaboration!
We need some more information in order to reproduce the issue. As per my understanding, the method $this->getOrderId()
is calling 3 times in the below function:
We can save the value of the output of $this->getOrderId()
and use it wherever required. Am I on the same page? Or please let us know the steps to reproduce the issue.
Thanks
Hello @engcom-Hotel,
I'm not sure we're on the same page. Calling $this->getOrderId()
is not an issue to me.
Issue is when we call Magento\Sales\Model\OrderRepository::get()
:
You can see on line 137 that the order is loaded from database.
But line 144 is calling those two lines :
Result is that when we call Magento\Sales\Model\OrderRepository::get()
, the order gets loaded from database 3 times instead of 1. (that's actually more than 3 times, but I've created distinct issues for each concerned modules)
I think the best thing to do is to replace ->setOrderId($order->getEntityId())
by ->setOrder($order)
here :
and refactor Magento\Sales\Model\Order\ShippingAssignmentBuilder
accordingly :
order
setOrder($order) { $this->order = $order; return $this; }
methodRefactor create
method :
public function create()
{
$shippingAssignments = null;
if (!$this->order && $this->getOrderId()) {
// we can keep this logic to avoid breaking change
$this->order = $this->orderFactory->create()->load($this->getOrderId());
}
if ($this->order) {
/** @var ShippingAssignmentInterface $shippingAssignment */
$shippingAssignment = $this->shippingAssignmentFactory->create();
$shipping = $this->shippingBuilderFactory->create();
$shipping->setOrder($this->order); // We replace setOrderId by setOrder here
$shippingAssignment->setShipping($shipping->create());
$shippingAssignment->setItems($this->order->getItems());
$shippingAssignment->setStockId($this->order->getStockId());
//for now order has only one shipping assignment
$shippingAssignments = [$shippingAssignment];
}
return $shippingAssignments;
}
and finally refactor Magento\Sales\Model\Order\ShippingBuilder
the same way.
Hello @Nuranto,
Thanks for the detailed explanation!
We have debugged the code via following the below steps:
My Account
page$this->orderFactory->create()->load($this->getOrderId())
is calling 3 times for order id 2
. Below is the MySQL query fetched from db.log:
SELECT `sales_order`.* FROM `sales_order` WHERE (`sales_order`.`entity_id`='2')
SELECT `sales_order`.* FROM `sales_order` WHERE (`sales_order`.`entity_id`='2')
SELECT `sales_order`.* FROM `sales_order` WHERE (`sales_order`.`entity_id`='2')
Hence confirming the issue.
Thanks
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-7656 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
The internal team start working on. the issue
Hi @o-iegorov. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
Summary
Magento 2.4.5-p1
Loading order through repository loads the order three times from DB :
Loads the order from database, then calls setShippingAssignments() which calls TaxManagement::getShippingAssignmentBuilderDependency() which loads the order from database again.
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Sales/Model/Order/ShippingBuilder.php#L79
and
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Sales/Model/Order/ShippingAssignmentBuilder.php#L79
Examples
Steps to reproduce
https://github.com/magento/magento2/blob/9ef88b46ff666673623e3f04d969c46ecf396cad/app/code/Magento/Sales/Model/Order/ShippingAssignmentBuilder.php#L79
https://github.com/magento/magento2/blob/9ef88b46ff666673623e3f04d969c46ecf396cad/app/code/Magento/Sales/Model/Order/ShippingBuilder.php#L79
My Account
page$this->orderFactory->create()->load($this->getOrderId())
is calling 3 times for order id2
. Below is the MySQL query fetched from db.log:Proposed solution
I guess line
$shippingAssignments->setOrderId($order->getEntityId());
should be replaced somehow by$shippingAssignments->setOrder($order);
Release note
No response
Triage and priority