I’m trying to get some currency exchange rates in a seperate php file in magento and saving them:
<?php
// Initiate application
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::app();
// Code to create my $rates array
/** CODE **/
foreach ($rates as $currencyCode => $currencyRates) {
Mage::getModel('directory/currency')
->setId($currencyCode)
->setRates($currencyRates)
->save();
}
Error:
<br />
<b>Fatal error</b>: Uncaught exception 'Mage_Core_Exception' with message 'Cannot retrieve entity config: directory/currency' in /home/users/A000456/shoppingonline.be/www.shoppingonline.be/app/Mage.php:550
Stack trace:
#0 /home/users/A000456/shoppingonline.be/www.shoppingonline.be/app/code/core/Mage/Core/Model/Resource.php(161): Mage::throwException('Cannot retrieve...')
#1 /home/users/A000456/shoppingonline.be/www.shoppingonline.be/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(265): Mage_Core_Model_Resource->getTableName('directory/curre...')
#2 /home/users/A000456/shoppingonline.be/www.shoppingonline.be/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(247): Mage_Core_Model_Mysql4_Abstract->getTable('currency')
#3 /home/users/A000456/shoppingonline.be/www.shoppingonline.be/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(402): Mage_Core_Model_Mysql4_Abstract->getMainTable()
#4 /home/users/A000456/shoppingonline.be/www.shoppingonline.be/app/code/core/Mage/Core/Model/Abstract.php(306): Mage_Core_Model_Mysql4_Abstract->save( in <b>/home/users/A000456/shoppingonline.be/www.shoppingonline.be/app/Mage.php</b> on line <b>550</b><br />
I turns out to be the save()-method where this happens.
Thoughts? Not sure where to start debugging this. If I knew where the rates were being stored would also be ok so I’d could insert them by hand …
(I took the code from the Mage_Directory_Model_Currency_Import_Abstract class, normal saving through magento interface works fine)
My first thought is that starting Magento in the context of another PHP file, but without all the fixins that Magento provides when bootstrapping itself, seems risky.
The path of least resistance is, with very few exceptions, do let Magento be Magento and do its thing, the less hacking the better. With that in mind, is it possible for you to set up a Magento controller/action and invoke this data from there, or even consume it remotely (e.g. using
file_get_contents)?