Magento2: Cron gets wrong base media URL

Created on 3 Apr 2017  路  16Comments  路  Source: magento/magento2

Preconditions

  1. Magento: 2.1.5
  2. PHP: 7

Steps to reproduce

  1. Set up Magento with pub folder as webroot
  2. Set email logo in Content > Design > Configuration > Edit > Transactional Emails > Logo Image
  3. Have a cron (custom) send an email

Expected result

  1. Email is received with all images showing.

Actual result

  1. No images show.
  2. Path to images contain: "/pub/"

The image above is set in config, but the issue will also happen for product image urls generated by:

return $this->_imageHelper->init($product, $type, $attributes)
            ->setImageFile($imageFile)->resize(208, 260)->save()->getUrl();

or images included with directives:

<img src="{{media url="wysiwyg/emails/mailer-footer.png"}}" alt="{{trans "Thank you, %store_name" store_name=$store.getFrontendName()}}!" />

You can force the media url in config:
Stores > Configuration > Web
But that shouldn't be necessary.

Magento\Store\Model\Store->getBaseUrl(...) returns wrong value.

Customer Confirmed Format is valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report

Most helpful comment

We experienced the same problem, where the media paths in the generated sitemap.xml file were incorrect when the sitemap.xml was generated by the cronjob, if you generate it manually, the paths were correct.

Solution from @MrDaar fixed it for us, but it shouldn't contain the forward slash in the middle, it should be:

  • {{unsecure_base_url}}media/
  • {{secure_base_url}}media/

All 16 comments

We're experiencing the same issue with the built-in product stock alert module, which generates its emails via cron.

Just noted that this is a duplicate of #8868.

@scottsb

You can force the media url in config:
Stores > Configuration > Web

So if you set the config value in control centre it'll also be fine.

Base URL for User Media Files {{unsecure_base_url}}media/
Secure Base URL for User Media Files {{secure_base_url}}media/

_(edited)_

I attempted that, but it didn't seem to resolve the issue for me. Either I did something wrong, forgot to clear my cache or it's another issue with single-store mode (_maybe_ related to #8137).

We experienced the same problem, where the media paths in the generated sitemap.xml file were incorrect when the sitemap.xml was generated by the cronjob, if you generate it manually, the paths were correct.

Solution from @MrDaar fixed it for us, but it shouldn't contain the forward slash in the middle, it should be:

  • {{unsecure_base_url}}media/
  • {{secure_base_url}}media/

@MrDaar, thank you for your report.
We've created internal ticket(s) MAGETWO-82739 to track progress on the issue.

Hi @MrDaar
We are now closing this as a duplicate of https://github.com/magento/magento2/issues/8868

Thank you for participation

Hi,

Thank you for your solutions, I've been debugging this problem for a moment now!
The only thing is that I also had to change the web/(un)secure/base_static_url paths to {{(un)secure_base_url}}static/ to make it work.

I can corroborate that setting the base_static_url path to {{(un)secure_base_url}}static/ solves the issue for me. The config that needs to be set probably depends if your images are in media or static folder.

@magento-engcom-team give me 2.3-develop instance

Hi @nahuelsanchez. Thank you for your request. I'm working on Magento 2.3-develop instance for you

Hi @nahuelsanchez, here is your Magento instance.
Admin access: https://i-9111-2-3-develop.engcom.dev.magento.com/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

WHAT IS THIS MAGIC?

In have to add cron process in extension ,which can shown in a cron_schedule tabel.
how can i add? in Magento1 Googleshopping Extension.

Was this page helpful?
0 / 5 - 0 ratings