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?
2 Answers 2
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
-
Thanks, now I can finally play with my Module install script without having to delete the messed up versions 20 times an hour :)Chris Morris– Chris Morris2013年09月18日 08:49:30 +00:00Commented Sep 18, 2013 at 8:49
-
3Setting the store is not mandatory.Tim Bezhashvyly– Tim Bezhashvyly2013年09月18日 09:04:05 +00:00Commented Sep 18, 2013 at 9:04
-
1AFAIK, It's mandatory in case if you want some write operation to the database.MagePsycho– MagePsycho2013年09月18日 13:39:56 +00:00Commented Sep 18, 2013 at 13:39
-
1@MagePsycho Only mandatory for updates to the product and category entities.benmarks– benmarks2014年02月06日 21:56:01 +00:00Commented Feb 6, 2014 at 21:56
-
@ChrisMorris this script will not trigger the update workflow. You will want to call
Mage_Core_Model_Resource_Setup::applyAllUpdates()benmarks– benmarks2014年02月06日 21:56:55 +00:00Commented Feb 6, 2014 at 21:56
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();