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

Don't use $rate as an object (it is an array) #30052

Closed
wants to merge 4 commits into from
Closed

Don't use $rate as an object (it is an array) #30052

wants to merge 4 commits into from

Conversation

flancer64
Copy link
Contributor

Description (*)

$rate is an array and it does not contain id item. We can use rate's code item as part of id for HTML nodes.

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 are green)

`$rate` is an array and it does not contain `id` item. We can use rate's `code` item as part of `id` for HTML nodes.
@m2-assistant
Copy link

m2-assistant bot commented Sep 15, 2020

Hi @flancer64. 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 give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@Stepa4man
Copy link
Contributor

@magento run all tests

Copy link
Contributor

@Stepa4man Stepa4man left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @flancer64
Thanks for your contribution

Could you, please take a look at my comments?

Comment on lines 62 to 65
<?php
$rateCode = strtolower($rate['code']);
$rateId = str_replace(' ', '-', $rateCode);
?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, don't hold logic in the template. Can you put this to view Model?

$rateCode = strtolower($rate['code']);
$rateId = str_replace(' ', '-', $rateCode);
?>
<tr id="rate-<?= /* @noEscape */ $rateId ?>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we keep $rateId as the name of the variable?

@Stepa4man Stepa4man added the Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests label Sep 15, 2020
@flancer64
Copy link
Contributor Author

Hello, @Stepa4man .

Sorry, I cannot "move logic from template to view Model". I don't know what a right logic should be here. I've just fixed the bug. Someone wrote this:

$rate->getId()

for array $rate. It interrupts templates rendering.

I'm sorry again, but I have no answer to question "Why should we keep $rateId as the name of the variable?" :( You shouldn't. It just my own choice.

Please, feel free to reject this pull request if it doesn't match your rules.

@sidolov sidolov added Priority: P3 May be fixed according to the position in the backlog. Risk: low Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Sep 16, 2020
@engcom-Golf
Copy link
Contributor

Hi, @flancer64, are you able to continue with this pull request?
As a unique value, you can use tax_id field and if it is still necessary you can move logic to view model and use in this template.
Instructions can be found by the following link View models

Also could you please cover your code changes with an MFTF test? You can use the following Magento Functional Testing Framework Guide to get acquainted with it.
If you have any additional questions or appointments feel free to ask, I will try to help,

Thank you!

@engcom-Golf engcom-Golf self-assigned this Sep 23, 2020
@flancer64
Copy link
Contributor Author

@engcom-Golf , I cannot use tax_id. There was no such field under debugger in the structure. I don't know why this field was omitted on rate data selection from DB but it was:

image

I agree that the better way is to use tax_id field here instead of code but we need to fix code that selects data from DB first. I'm sorry, but It's too deep for me, I don't have so much free time to check side effects. I've created this "dirty fix" and it's pretty enough for me and my projects.

@flancer64
Copy link
Contributor Author

Maybe we can use position field or even 'foreach' loop index here.

@engcom-Golf
Copy link
Contributor

@flancer64, please look at \Magento\Tax\Model\ResourceModel\Calculation::getCalculationProcess method. There should be an ability to add rate id to the output array.

@flancer64
Copy link
Contributor Author

Thanks, @engcom-Golf . This is the way.

This SQL is composed to select rates data in \Magento\Sales\Block\Adminhtml\Order\Totals\Tax::getFullTaxInfo:

SELECT
	`main_table` .*
FROM
	`sales_order_tax` AS `main_table`
WHERE
	(main_table.order_id = 1234)
ORDER BY
	`process` ASC

so, we can use sales_order_tax.tax_id as identifier for tax items.

@engcom-Golf
Copy link
Contributor

@magento run all tests

@engcom-Golf
Copy link
Contributor

Hi, @flancer64, thank you for your changes, but as we can see from failed tests, this approach is not acceptable. I have made some investigations and found that rates are taken not only from the database. So tax_id can be not present in rates array. Suppose we can use 'for each' loop index, as you have proposed before.

@flancer64
Copy link
Contributor Author

Suppose we can use 'for each' loop index, as you have proposed before.

@engcom-Golf , done.

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Oct 28, 2020

Seems like this PR fixes #30094.

We also have another PR #30516 that fixes this issue, so probably the only one PR will be accepted.

The main reason why this issue appeared - it wasn't covered with automated tests.

@Morgy93 Morgy93 mentioned this pull request Oct 28, 2020
6 tasks
Copy link
Contributor

@engcom-Delta engcom-Delta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flancer64 sorry for delay
Due to Magento Definition of Done all code must be covered by tests.

Could you add automation test that cover your changes?

@flancer64
Copy link
Contributor Author

@engcom-Delta , I'm sorry, I couldn't.

@ihor-sviziev
Copy link
Contributor

Hi @flancer64,

I just analyzed another solution that we have - seems like array index solution potentially might cause ID duplication, as in some other place on the page might be same id rate-1, or rate-0. I believe using random string is better and this approach is used in #30516.

I'm closing this PR as we just have better solution for the same issue in #30516.

Thank you so much for your contribution!

@m2-assistant
Copy link

m2-assistant bot commented Nov 5, 2020

Hi @flancer64, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests Component: Sales Priority: P3 May be fixed according to the position in the backlog. Release Line: 2.4 Risk: low Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants