Magento 自定义货币保存?

发布于 2024-09-14 08:58:40 字数 1898 浏览 3 评论 0原文

我试图在 magento 的单独 php 文件中获取一些货币汇率并保存它们:

<?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();
        }

错误:

<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 />

我原来是发生这种情况的 save() 方法。

想法?不知道从哪里开始调试这个。如果我知道汇率存储在哪里也可以,这样我就可以手动插入它们...

(我从 Mage_Directory_Model_Currency_Import_Abstract 类中获取代码,通过 magento 界面正常保存效果很好)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆那么伤 2024-09-21 08:58:40

当您需要保存目录/currency_rate 时,似乎您正在尝试保存目录/货币。最简单的方法是在您创建的目录/货币模型上使用 saveRates 方法。 IE

Array
(
    [USD] => Array
        (
            [CAD] => 1.07
            [GBP] => .63
            [EUR] => .71
        )

)
$currency = Mage::getModel('directory/currency')->saveRates($currencies);

Seems like you're trying to save the directory/currency when you need to save a directory/currency_rate. Simplest way to do that is to use the saveRates method on the directory/currency model that you create. i.e.

Array
(
    [USD] => Array
        (
            [CAD] => 1.07
            [GBP] => .63
            [EUR] => .71
        )

)
$currency = Mage::getModel('directory/currency')->saveRates($currencies);
沙沙粒小 2024-09-21 08:58:40

我的第一个想法是,在另一个 PHP 文件的上下文中启动 Magento,但没有 Magento 在引导自身时提供的所有修复程序,似乎有风险。

阻力最小的途径是,除了极少数例外,让 Magento 成为 Magento 并做它的事情,黑客攻击越少越好。考虑到这一点,您是否可以设置 Magento 控制器/操作并从那里调用此数据,甚至远程使用它(例如使用 file_get_contents)?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文