Fixed: Cannot install sample data in Magento 2, even with authentication keys stored in auth.json

If you’ve tried installing the Magento 2 sample data using the CLI tool, you may get the following message:

# sudo bin/magento sampledata:deploy
./composer.json has been updated
Loading composer repositories with package information

[Composer\Downloader\TransportException]
The 'https://repo.magento.com/packages.json' URL required authentication.
You must be using the interactive console to authenticate

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [packages1] ... [packagesN]

There is an error during sample data deployment.

The solution documented on the Magento 2 Developer hub is to switch to your Magento 2 base directory and run composer update, which will ask for your Magento Connect authentication keys and then store them for you in your ~/.composer/auth.json file.

What happens, however, when you’ve already done that and you still get the same error? Well then you have to start doing your research, which will bring you to this bug report.

Since I cloned from master and the bug has only been fixed in develop (as of this writing), the only solution if you want to install the sample data is to manually apply the patch referenced in the bug report yourself.

Once that was done, sample data installation proceeded with no problems.

Magento: Create Free Shipping Rule

In Admin panel:

  1. Create a new Shopping Cart Price Rule.
  2. On the conditions tab, specify your conditions.
  3. On the Actions tab, set ‘Free Delivery’ to something other than ‘No’
  4. Save rule.
  5. Enable Free Shipping shipping method in System > Configuration.
  6. Set Minimum Order Amount to something ridiculously high.
  7. Save configuration.
  8. Test your rule.

Fixed: TypeError: $(…) is null

Recently I had to use Prototype JS to listen to an onchange event on a select box and toggle the display of some other elements on the page accordingly.

The code worked fine in Firebugs’ console, but I was getting this error when I had added my code to the HTML:

TypeError: $(...) is null

Usually this error means that the library hasn’t been included, so the $() function doesn’t exist, but the library definitely was included on the page.

After some research, I came across the solution – always put code which observes on a specific DOM element after the element has been created. I had put my JavaScript before the HTML it was working with. Moving it after the same HTML made it work. That also explains why it worked perfectly in the console – because the DOM has already been loaded in it’s entirety.

A simple mistake to make perhaps, but it’s a crucial difference between browser languages like JavaScript and interpreted server-side languages like PHP.

Add an attribute, assign to the General group and to multiple attribute sets


/** @var Mage_Catalog_Model_Resource_Setup $this */
$installer = $this;
$installer->startSetup();

$installer->addAttribute('catalog_product', 'delivery_cutoff_date', array(
'type' => 'datetime',
'input' => 'date',
'class' => 'validate-date',
'backend' => 'eav/entity_attribute_backend_datetime',
'label' => 'Delivery Cut-off Date',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'visible_on_front' => false,
'used_for_price_rules' => false,
'group' => 'General',
'attribute_set' => array('Accessories', 'caps', 'Clearance', 'Curtains', 'Default', 'Electrical',
'Electronics', 'Parts', 'Seats', 'Swivels', 'Trim', 'Window fitting kit',
'Windows')
));

$installer->endSetup();