title: Magento: How to programatically set the base image to the first image in the list
body: <h1>The problem</h1>
  
  <h2>Current Situation</h2>
  
  <p>I'm having a problem with a third-party ioncube loader encoded feedloader plugin which is no longer supported by the original author (since they went tits-up) and instead of putting in two weeks to completely write it from scratch, I've decided to fix the problems it has after the import has run.</p>
  
  <h2>Compatibility</h2>
  
  <p>The only problem is: I want to write this using functions in the Mage library, not rely on a few custom queries that might break in the next update of Magento or whenever I change something in the database (I just want to get to know Magento's core functions better I guess)</p>
  
  <h2>Problem Diagnosis</h2>
  
  <p>The import does nearly everything correct, except from setting the base image (the small and thumbnail image are set correctly), as you can see in the screenshot below:</p>
  
  <p><img src="https://i.stack.imgur.com/FW7za.png" alt="The first and only image has not been selected as default Base Image"></p>
  
  <p>The actual record in the database is missing for that image.. (so tempted to fix it with a query, but I won't.. I'm going to keep looking for an elegant solution)</p>
  
  <p>Also, the function $product->getMediaGalleryImages() doesn't return any images, so I can't use the solution as suggested by @SKV over at <a href="https://stackoverflow.com/questions/18954265/set-base-image-programmatically">Set Base Image Programmatically</a> .. unless I am doing something wrong.</p>