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

Get sitemap product images from image cache, if available #9082

Merged
merged 19 commits into from
Jun 22, 2017
Merged

Get sitemap product images from image cache, if available #9082

merged 19 commits into from
Jun 22, 2017

Conversation

sambolek
Copy link
Contributor

@sambolek sambolek commented Mar 31, 2017

Product images in sitemap are currently always pulled directly from gallery attributes by querying the database, whilst on frontend, we're using cached versions of the (that can potentially be stored somewhere else).

This can present an issue if google doesn't want to index images in the sitemap, as their URL is different than the one on product pages.

Description

In sitemap, product image URLs are now being pulled by using product helper, that can serve cached image, if available. This is in line to what we see on the frontend, on product page.

Fixed Issues (if relevant)

  1. sitemap image URLs do not match with those on product pages #7504

Manual testing scenarios

  1. Create a product and set an image on it
  2. Set up and generate a sitemap
  3. Observe that product image URL in sitemap is direct URL to pub/media/catalog/product http://prntscr.com/eqw82x
  4. Observe that images on the product page are being pulled from image cache folder http://prntscr.com/eqw90a
  5. After the fix, images are being pulled via product image helper and are in line to the way product page behaves http://prntscr.com/eqw8kl

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)

@adragus-inviqa
Copy link
Contributor

Please use the ::class accessor, never strings.

E.g.

// like this
ObjectManager::getInstance()->get(\Magento\Catalog\Model\Product::class);

// NOT like this
ObjectManager::getInstance()->get('Magento\Catalog\Model\Product');

@sambolek
Copy link
Contributor Author

sambolek commented Apr 1, 2017

Hi @adragus-inviqa
thanks for the suggestion, wasn't aware of this.

Got any suggestions for PHPCS reporting warnings for too long line length, like 9c44917#diff-2cc96b8b46600260b67449219e565125R76

should those lines be ignored with "@codingStandardsIgnoreStart" comments or is there another solution I missed?

@adragus-inviqa
Copy link
Contributor

They all seem to have the 'http://localhost/pub/media/catalog/product/cache/c9e0b0ef589f3508e5ba515cde53c5ff/ common root, so I'd extract that into a class constant/property/anything, and concat with the rest.

For me, @codingStandardsIgnoreStart means So what if it's ugly?!: I don't particularly like it.

@sambolek
Copy link
Contributor Author

sambolek commented Apr 1, 2017

How can I get some more info about why the previous build failed? https://travis-ci.org/magento/magento2/builds/217516099

The message doesn't help much:
The command "test $TEST_SUITE = "static" && TEST_FILTER='--filter "Magento\Test\Php\LiveCodeTest"' || true" exited with 0.

@ishakhsuvarov
Copy link
Contributor

@sambolek I would suggest running unit tests on local env to see what is the problem in this case.

* @param string $image
* @return mixed
*/
protected function getProductImageUrl($image)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest making this private, as Magento discourages inheritance-based APIs.

@@ -396,9 +396,28 @@ protected function _getAllProductImages($product, $storeId)
* Get media config
*
* @return \Magento\Catalog\Model\Product\Media\Config
* @deprecated No longer used, as we're getting full image URL from getProductImageUrl method
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add @see annotation with the reference to the updated implementation.

@@ -396,9 +396,28 @@ protected function _getAllProductImages($product, $storeId)
* Get media config
*
* @return \Magento\Catalog\Model\Product\Media\Config
* @deprecated No longer used, as we're getting full image URL from getProductImageUrl method
*/
protected function _getMediaConfig()
{
return $this->_mediaConfig;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you have eliminated all of the usages for this dependency.
Now you could also deprecate the property and remove all type hints to it.

@@ -607,11 +607,12 @@ protected function _getUrl($url, $type = \Magento\Framework\UrlInterface::URL_TY
* Get media url
*
* @param string $url
* @return string
* @return string $url
* @deprecated No longer used, as we're generating product image URLs inside collection instead
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a @see annotation with the reference to the new approach

*/
protected function getProductImageUrl($image)
{
$productObject = ObjectManager::getInstance()->get(\Magento\Catalog\Model\Product::class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding these as an optional constructor injections

@sambolek
Copy link
Contributor Author

Fixed issues mentioned in review. Waiting for CI build to finish, but tested ok locally.

Please let me know if there's anything else to fix (except potentially failed tests).

@magento-team magento-team merged commit 1a7fb83 into magento:develop Jun 22, 2017
magento-team pushed a commit that referenced this pull request Jun 22, 2017
magento-team pushed a commit that referenced this pull request Jun 22, 2017
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.

5 participants