[英]Load Remote Data Source into Magento Admin Products Grid
I am trying to essentially create a split screen view, one grid of a remote repository full of products, and another alongside it showing the local repository in a grid. 我试图基本上创建一个分屏视图,一个充满产品的远程存储库网格,另一个显示网格中的本地存储库。
I think that essentially sums it up, I'll give partial credit if you can tell me how to simply incorporate the remote source into the grid... I think I could handle it from there even. 我认为这基本上总结了一下,如果你能告诉我如何简单地将远程源合并到网格中,我会给予部分功劳......我想我甚至可以从那里处理它。 Please be thoughtful, I don't really want to hear how to configure my resources in the config.xml, I already can do that with a remote database, i just can't get the objects/collections to load from it.
请慎重,我真的不想听到如何在config.xml中配置我的资源,我已经可以用远程数据库来做,我只是无法从中加载对象/集合。
Thanks guys. 多谢你们。
OK-- So for those of us who've tried something like this, the first thing you realize is that when you want more than one database as a source in your module... you actually need 2 modules to do so (someone chime in and correct me if i'm wrong). 好的 - 所以对于我们这些尝试过这样的事情的人来说,你首先意识到当你想要一个以上的数据库作为你模块中的一个源时......你实际上需要2个模块才能这样做(有人会发出声音)如果我错了,请纠正我。
Step 1: Create a "dummy" module to connect with your remote database. 步骤1:创建一个“虚拟”模块以连接远程数据库。 This module should pretty much just contain etc/ and Model/ -- there's no real need for anything else.
这个模块应该只包含etc /和Model / - 没有其他任何东西真正需要。 My config.xml looks as follows:
我的config.xml如下所示:
<config>
<modules>
<Mage_RepoDummy>
<version>0.1.0</version>
</Mage_RepoDummy>
</modules>
<global>
<resources>
<repodummy_write>
<connection>
<use>repodummy_database</use>
</connection>
</repodummy_write>
<repodummy_read>
<connection>
<use>repodummy_database</use>
</connection>
</repodummy_read>
<repodummy_setup>
<connection>
<use>core_setup</use>
</connection>
</repodummy_setup>
<repodummy_database>
<connection>
<host><![CDATA[localhost]]></host>
<username><![CDATA[brandrepo]]></username>
<password><![CDATA[*******]]></password>
<dbname><![CDATA[brandrepo]]></dbname>
<model>mysql4</model>
<type>pdo_mysql</type>
<active>1</active>
</connection>
</repodummy_database>
</resources>
<models>
<repodummy>
<class>Mage_RepoDummy_Model</class>
<resourceModel>repodummy_mysql4</resourceModel>
</repodummy>
<repodummy_mysql4>
<class>Mage_RepoDummy_Model_Mysql4</class>
<entities>
<product>
<table>catalog_product_entity</table>
</product>
</entities>
</repodummy_mysql4>
</models>
</global>
<adminhtml>
</adminhtml>
Now you'll need the following model and resource files: 现在您需要以下模型和资源文件:
/Model/Product.php
/Model/Mysql4/Product.php
/Model/Mysql4/Product/Collection.php
In Product.php: 在Product.php中:
class Mage_RepoDummy_Model_Product extends Mage_Catalog_Model_Abstract
{
public function _construct()
{
$this->_init('repodummy/product', 'entity_id');
}
}
In Mysql4/Product.php 在Mysql4 / Product.php中
class Mage_RepoDummy_Model_Mysql4_Product extends Mage_Catalog_Model_Resource_Abstract
{
public function __construct()
{
parent::__construct();
$this->setType(Mage_Catalog_Model_Product::ENTITY)
->setConnection('repodummy_read', 'repodummy_write');
$this->_productWebsiteTable = $this->getTable('catalog/product_website');
$this->_productCategoryTable = $this->getTable('catalog/category_product');
}
}
And In Mysql4/Product/Collection.php 并在Mysql4 / Product / Collection.php中
class Mage_RepoDummy_Model_Mysql4_Product_Collection extends Mage_Catalog_Model_Resource_Collection_Abstract {
protected function _construct()
{
$this->_init('repodummy/product');
}
}
Just barebones type stuff, like you'd do for any basic model in Magento. 只是准系统类型的东西,就像你在Magento的任何基本模型。 Now from another module, that's rigged to any other database, probably/possibly your local instance, you can access this remote data store by invoking your dummy object, if you wanted to test this just do something simple like:
现在从另一个模块,它被绑定到任何其他数据库,可能/可能是您的本地实例,您可以通过调用您的虚拟对象来访问此远程数据存储,如果您想测试它只是做一些简单的事情:
$test = Mage::getModel('repodummy/product')->load(10367);
die("::".$test->getSku()."::");
...and this model should function just like your typical product model for the most part, except you're using a remote database, happy coding! ...这个模型应该像大多数情况下的典型产品模型一样运行,除了你使用远程数据库,快乐编码!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.