Skip to content

Instantly share code, notes, and snippets.

@philwinkle
Last active February 24, 2016 08:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philwinkle/6f9982ca4f3a5a0a88ab to your computer and use it in GitHub Desktop.
Save philwinkle/6f9982ca4f3a5a0a88ab to your computer and use it in GitHub Desktop.
product->load as an antipattern?
<?php

require('app/Mage.php');
Mage::app();


$product = Mage::getModel('catalog/product')->getCollection()->getFirstItem();

var_dump($product->getData('media_gallery'));
//=>NULL

$product->load('media_gallery');

var_dump($product->getData('media_gallery'));
//=>Array

Output:

NULL
array(2) {
  ["images"]=>
  array(1) {
    [0]=>
    array(8) {
      ["value_id"]=>
      string(5) "59846"
      ["file"]=>
      string(27) "/8/1/81044_Punchy_Peach.jpg"
      ["label"]=>
      string(0) ""
      ["position"]=>
      string(0) ""
      ["disabled"]=>
      string(0) ""
      ["label_default"]=>
      NULL
      ["position_default"]=>
      NULL
      ["disabled_default"]=>
      NULL
    }
  }
  ["values"]=>
  array(0) {
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment