Data Feed URL PHP String Replace

Apr 18 2024

/

Replacing Part Of A URL In A Data Feed

One day I encountered that the product data feeds I created for a successful online merchant ran into a problem where I needed to reach out to the developers at Wyomind Data Feed Manager to ask their advice.

The Data Feed Problem


The Magento site I was working had changed servers and it created a strange issue with the url structure of the feed and images. It had previously allowed access to the /pub/media folder which was now unavailable. If I remember rightly it was a security change enforced.

The developers had obviously noticed this whilst updating the server and changed the source location for the images across the website during the migration. However, they hadn’t thought about third party integrations such as data feeds and Ebay and Amazon connections.

Essentially, all images could not be found as the /pub/media images were resulting in a 404 Not Found page.

The media files were instead available at the /media folder instead without the /pub/ directory.

The Problem Code


The code at that time was {{parent.image_link index=”0″}} which should pull in the first image from the parent product in Magento into a Google tag called image_link.

The Fix

The guys at Wyomind were really helpful and indicated that if I used a PHP string replace function on that particular field, that would work as expected.

The resulting code looked something like this:
To explain further, the tag is where I’ve declared the image tag. Within that, you can see some php tags then tell each instance of ‘/pub/’ to replace with ‘/’ for my first parent image (denoted by index=”0″). I then had to repeat this action for however many tags containing images I wanted to pull into the feed, adjusting the index number to pull each subsequent image.

After Thoughts

Hopefully this will help anyone with a similar issue in the future without having to go to the trouble of asking developers and thus saving you a cost.

If you have any questions or need help creating a data feed, please feel free to reach out to me and I’ll see if it’s something I can help with.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *