views:

51

answers:

1

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-&gt;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-&gt;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-&gt;getMainTable()
#4 /home/users/A000456/shoppingonline.be/www.shoppingonline.be/app/code/core/Mage/Core/Model/Abstract.php(306): Mage_Core_Model_Mysql4_Abstract-&gt;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)

A: 

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)?

Joseph Mastey
I know, but I've been doin it the entire time with a bunch of ajax stuff and so far everything worked perfectly. I think I'm just gonna throw my rates array in the core currency module's submodule of webservicex. I know modifing code isn't a good idea, but this project I'm doing is full of this kind of stuff and just a 1 time thing anyway. And as long as I don't break the existing code, there shouldn't be any problem.Thanks for replying though.
Rakward