当前我正在使用拍卖模块在网上商店工作。这个拍卖模块有自己的一套代表拍卖和他们的出价的实体。主要实体是ProductAuction模型。该模型与Magento的Catalog_Product模型有关系。加载相应的实体,同时加载集合
无处不在收集产品必须加载ProductAuctions收集后加载。
现在我不得不写一些异国情调的查询来加载特定的拍卖组合与类别和搜索查询。现在,我首先必须加载属于给定类别和搜索查询的产品集合,然后加载属于相应产品集合的活动拍卖。
在某些情况下,我无法重新使用加载的产品集,然后必须执行另一个查询来加载相应的拍卖产品。
最糟糕的情况我将不得不执行三个大的查询并处理在一个查询中应该可能的结果集。
是否有可能在Magento中加载集合中的相关实体,就像任何体面的ORM会与One-2-One,Many-2-One和其他关系一样?
我还没有找到任何这方面的例子,但我无法想象这在Magento中是不可能的。
感谢您的任何帮助。
== ==编辑
的示例代码有点展现我此刻在做什么:
/**
* Build the correct query to load the product collection for
* either the search result page or the catalog overview page
*/
private function buildProductCollectionQuery() {
/**
* @var Mage_CatalogSearch_Model_Query
*/
$searchQuery = Mage::helper('catalogsearch')->getQuery();
$store_id = Mage::app()->getStore()->getId();
$productIds = Mage::helper('auction')->getProductAuctionIds($store_id);
$IDs = array();
$productIds = array();
$collection = Mage::getModel('auction/productauction')
->getCollection()
->addFieldToFilter(
'status', array('in' => array(4))
);
if (count($collection)) {
foreach ($collection as $item) {
$IDs[] = $item->getProductId();
}
}
$collection = Mage::getResourceModel('catalog/product_collection')
->addFieldToFilter('entity_id',array('in'=> $IDs))
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addTaxPercents()
->addStoreFilter();
if($searchQuery != null) {
$collection->addAttributeToFilter(array(
array('attribute' => 'name', 'like'=>'%' . $searchQuery->getQueryText() . '%'),
array('attribute' => 'description', 'like'=>'%' . $searchQuery->getQueryText() . '%')
)
);
// @TODO This should be done via the Request object, but the object doesn't see the cat parameter
if(isset($_GET['cat']) ) {
$collection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['cat']));
}
}
return $collection;
}
有没有你不使用任何连接特定的原因是什么? –
已经尝试了几种方法,并且尽管连接工作正常,但我只能将其作为数据数组而不是代表对象。我需要域模型对象... – pderaaij
好吧,如果你需要它们,你必须加载所有的对象,以正确的方式加入它们会给你所有必需的起点 –