magento - 自定义 table 加入 catalog/product

magento - custom table join with catalog/product

我在我的自定义 table sellerrequest 中有 seller_id 字段作为外键。主要参考文献在 customer/customer_collection collection 中。我想在 seller_id 的管理网格中显示卖家名称。我不确定如何加入两个 collection,但我尝试使用 -

$collection = Mage::getModel("wallets/sellerrequest")
                ->join(
                        'customer/customer_collection',
                        'seller_id=main_table.seller_id'
                        )
                ->getCollection();

但是,它不起作用。这是错误的方法吗?任何帮助表示赞赏。

谢谢。

试试这个

$collection = Mage::getModel("wallets/sellerrequest")->getCollection();
        $collection->getSelect()->joinLeft(
            array('cust' => $collection->getTable('customer/customer_collection')),
            'cust.seller_id = main_table.seller_id');

希望这可以 help.By 我还没有尝试过的方式。但同样适用于 me.See 集合中的数据,以检查您是否获得了正确的数据。

这是我试过的另一个例子。

 protected function _prepareCollection(){

        $collection = Mage::getModel('children/children')->getCollection();        
        $collection->getSelect()->joinLeft('schools', 'schools.school_id = main_table.school_id', array('school_name'));

         $collection->addFieldToFilter('main_table.customer_id', array('in' => $this->_getCustomer()->getId()));

        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

在这里,我将 "schools" table 加入到我的 children model.In 我的案例中 table 之间的公共键是 school_id。这对我有用,检查一下并进行一些修改以满足您的要求。