Skip to content

#29721 :- Logo is always 170 pixels wide, regardless of actual size #29746

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

Conversation

konarshankar07
Copy link
Contributor

Description (*)

This PR will fix the issue with the logo width if the logo width is added from the design configuration

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Logo is always 170 pixels wide, regardless of actual size #29721

Manual testing scenarios (*)

  1. Login to Admin
  2. Content -> Configuration -> Global -> Edit -> Header
  3. Upload 800x300 example logo image (attached to issue)
  4. Enter 800 in Logo Attribute Width
  5. Enter 300 in Logo Attribute Height
  6. Save Configuration
  7. Clear cache
  8. Go to frontend and inspect logo dimensions

Expected Result

Logo is 800 pixels wide
image

Questions or comments

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)

@m2-assistant
Copy link

m2-assistant bot commented Aug 26, 2020

Hi @konarshankar07. 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

@konarshankar07
Copy link
Contributor Author

@magento run all tests

Copy link
Contributor

@lbajsarowicz lbajsarowicz left a comment

Choose a reason for hiding this comment

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

Just 2 minor adjustments.

'design/header/logo_width',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
return $logoWidth ? (int) $logoWidth : $this->_data['logo_width'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't that better to cast type to int for whole line just in case there's string in _data?

* Retrieve logo width
* @return int
*/
public function getLogoImageWidth()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use type hint for method?

@konarshankar07
Copy link
Contributor Author

@magento run all tests

@konarshankar07
Copy link
Contributor Author

@magento run all tests

*
* @return int
*/
public function getLogoImageWidth() :int
Copy link
Contributor

Choose a reason for hiding this comment

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

should we change it to getLogoImageWidth(): int instead of getLogoImageWidth() :int

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I know - the standard says about : int.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lbajsarowicz is right and its mentioned in the PSR-12
image
For more information :- https://www.php-fig.org/psr/psr-12/
But I don't know that we started following the PSR-12 standards?

Copy link
Contributor

Choose a reason for hiding this comment

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

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

@lbajsarowicz lbajsarowicz left a comment

Choose a reason for hiding this comment

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

Just two minor things :)

Return value of Magento\Theme\Block\Html\Header\Logo::getLogoImageWidth() must be of the type int, string returned - Change the implementation to return int values (the parenthesis has to be around the value)

Comment on lines 96 to 121
public function testGetLogoImageWidth()
{
$scopeConfigWithLogoWidthArgument = $this->getMockForAbstractClass(ScopeConfigInterface::class);
$scopeConfigWithLogoWidthArgument->expects($this->any())->method('getValue')->willReturn(null);

$scopeConfigWithoutLogoWidthArgument = $this->getMockForAbstractClass(ScopeConfigInterface::class);
$scopeConfigWithoutLogoWidthArgument->expects($this->once())->method('getValue')->willReturn(800);

$objectManager = new ObjectManager($this);
$argumentsWithLogoWidth = [
'scopeConfig' => $scopeConfigWithLogoWidthArgument,
'_data' => [
'logo_width' => 200
]
];
$blockWithLogoWidthArgument = $objectManager->getObject(Logo::class, $argumentsWithLogoWidth);

$this->assertEquals('200', $blockWithLogoWidthArgument->getLogoWidth());

$argumentsWithoutLogoWidth = [
'scopeConfig' => $scopeConfigWithoutLogoWidthArgument
];
$blockWithoutLogoWidthArgument = $objectManager->getObject(Logo::class, $argumentsWithoutLogoWidth);

$this->assertEquals('800', $blockWithoutLogoWidthArgument->getLogoWidth());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you split that test into 2:

  • testGetLogoImageWidthWhenImageWidthConfigured
  • testGetLogoImageWidthWhenImageWidthNotConfigured

That gives us 2 benefits:

  • When it fails - we exactly know which case fails
  • The test is easier to read and understand.

You can additionally split that into sections:

  • // Given - The environmental / mocked elements (eg. ScopeConfig)
  • // When - The call to tested method
  • // Then - Assertions (comparison of expected to actual results)

{
$logoWidth = $this->_scopeConfig->getValue(
'design/header/logo_width',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's import class there and make it inline.

@JosephLeedy
Copy link

I'm getting an error stating that getImageLogoWidth() tried to return a string instead of an integer. The following change resolved it:

-        return (int)$logoWidth ? $logoWidth : $this->_data['logo_width'];
+        return (int)($logoWidth ? $logoWidth : $this->_data['logo_width']);

@lbajsarowicz
Copy link
Contributor

@JosephLeedy That was exactly what I thought saying: "Change the implementation to return int values (the parenthesis has to be around the value)" Thanks!

@konarshankar07
Copy link
Contributor Author

@magento run all tests

1 similar comment
@konarshankar07
Copy link
Contributor Author

@magento run all tests

@gabrieldagama
Copy link
Contributor

The risk was set tolow due to: the suggested changes shouldn't impact other areas.

@sidolov
Copy link
Contributor

sidolov commented Sep 9, 2020

@konarshankar07 please, take a look at the review comments! Thanks!

@konarshankar07
Copy link
Contributor Author

Hello @sidolov ..
I already addressed the review changes
Thanks

lbajsarowicz
lbajsarowicz previously approved these changes Sep 11, 2020
Copy link
Contributor

@lbajsarowicz lbajsarowicz left a comment

Choose a reason for hiding this comment

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

✔️ Thanks for the Contribution.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz, thank you for the review.
ENGCOM-8182 has been created to process this Pull Request
✳️ @lbajsarowicz, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@engcom-Bravo
Copy link
Contributor

✔️ QA Passed

Manual testing scenario:

  1. Login to Admin
  2. Content -> Configuration -> Global -> Edit -> Header
  3. Upload 800x300 example logo image (attached to issue)
  4. Enter 800 in Logo Attribute Width
  5. Enter 300 in Logo Attribute Height
    configuration
  6. Save Configuration
  7. Clear cache
  8. Go to frontend and inspect logo dimensions

Result AFTER switching to PR
after1

❌ Result BEFORE switching to PR
before

Checked also on Blank theme
blank

@engcom-Bravo engcom-Bravo added the QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope label Sep 23, 2020
@engcom-Foxtrot engcom-Foxtrot self-assigned this Sep 23, 2020
@engcom-Foxtrot
Copy link
Contributor

SVC failure should be approved.

@ghost ghost dismissed lbajsarowicz’s stale review September 23, 2020 11:19

Pull Request state was updated. Re-review required.

@oviliz
Copy link

oviliz commented Nov 4, 2020

Oh dear... :(

@denchev
Copy link
Contributor

denchev commented Dec 2, 2020

I see the issue is fixed upstream and will eventually be widely available but in the meantime, I want to post a workaround for people who can't wait or cannot afford to upgrade.

  1. Create (if you don't have it) a file "app/design/frontend/Vendor/Theme/Magento_Theme/layout/default.xml"
  2. Add the following code within the tag:
    <referenceBlock name="logo"> <arguments> <argument name="logo_width" xsi:type="number">0</argument> </arguments> </referenceBlock>

This will force the getLogoWidth() check to start working.

@puntable
Copy link

puntable commented Feb 1, 2021

I see the issue is fixed upstream and will eventually be widely available but in the meantime, I want to post a workaround for people who can't wait or cannot afford to upgrade.

  1. Create (if you don't have it) a file "app/design/frontend/Vendor/Theme/Magento_Theme/layout/default.xml"
  2. Add the following code within the tag:
    <referenceBlock name="logo"> <arguments> <argument name="logo_width" xsi:type="number">0</argument> </arguments> </referenceBlock>

This will force the getLogoWidth() check to start working.

If you have multiple sites using the same theme, but with different logo size, you have a problem...

@mrtuvn
Copy link
Contributor

mrtuvn commented Jun 19, 2021

4531c76
Seem issue already resolved internals by adobe. The fix already delivered to 2.4-develop branch. Not only storefront but also in logo email
CC: @konarshankar07 @gwharton
Also anyone involed in this topics

@tuna2smc
Copy link
Contributor

tuna2smc commented Sep 6, 2021

e1aaf74
Can you check your work with this latest update in commit
@konarshankar07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: Theme Priority: P3 May be fixed according to the position in the backlog. QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope 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.

Logo is always 170 pixels wide, regardless of actual size