1

This is a weird request but I've done it before and it worked wonders.

I have a need to make a custom PHP file in my sites root folder. I need to give this file access to all of the magento functions inside.

$setup = new Mage_Eav_Model_Entity_Setup(‘core_setup’);

I did this once before successfully when I wrote a script to parse a massive database of trading cards into useful data then has the php script automatically add the cards to the database.

My problem is I did this on a old version of XMAPP that I sadly lost the backup files of when my pc died.

What files do I need to include in a blank php file to have access to the required magento core functions?

4

Try this

umask(0);
require 'app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

Now Magento is all fired upp and ready to go

5
  • Thanks, now I can finally play with my Module install script without having to delete the messed up versions 20 times an hour :) Sep 18 '13 at 8:49
  • 3
    Setting the store is not mandatory.
    – user487772
    Sep 18 '13 at 9:04
  • 1
    AFAIK, It's mandatory in case if you want some write operation to the database.
    – MagePsycho
    Sep 18 '13 at 13:39
  • 1
    @MagePsycho Only mandatory for updates to the product and category entities.
    – benmarks
    Feb 6 '14 at 21:56
  • @ChrisMorris this script will not trigger the update workflow. You will want to call Mage_Core_Model_Resource_Setup::applyAllUpdates()
    – benmarks
    Feb 6 '14 at 21:56
5

I use this one in my /cron/ folder:

<?php

session_start();
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
setlocale(LC_TIME, 'en_US');
umask(0);

$compilerConfig = 'includes/config.php';
if (file_exists($compilerConfig)) {
    include($compilerConfig);
}

$mageFilename = dirname(__FILE__) . '/../app/Mage.php';

require_once $mageFilename;

Mage::setIsDeveloperMode(true);

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

// If you're going to use store view emulation:
Mage::app()->getLocale();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.