Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6633621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:50:04+00:00 2026-05-25T22:50:04+00:00

Currenty I’m working on a webshop using an auction module. This auction module has

  • 0

Currenty I’m working on a webshop using an auction module. This auction module has its own set of entities representing an auction and their bids. The main entity is the ProductAuction model. This model has an relation to the Catalog_Product model of Magento.

Everywhere the collection is loaded the products have to be loaded after the collection of ProductAuctions has been loaded.

Now I have to write some exotic queries to load a specific sets of auctions in combination with category and search queries. Now I first have to load a collection of products belonging to the given category and search query, then load the active auctions belonging to the set of corresponding products.

In some scenarios I can’t reuse the set of loaded products and then have to execute another query to load the products corresponding the auctions.

Worst case I’ll have to execute three big queries and process the resultsets which should be possible in one query.

Is it possible in Magento to load relating entities within a collection, just like any decent ORM would do with One-2-One, Many-2-One and other relations?

I haven’t found any example of this, but I can’t imagine this isn’t possible in Magento.

Thanks for any help on this.

== EDIT ==

A bit of example code to show what I’m doing at the moment:

/**
 * 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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:50:04+00:00Added an answer on May 25, 2026 at 10:50 pm

    Managed to come up with a solution. I now use the following code to get all the information I need. Still I’m surprised it is so hard to create instances of relating objects like any normal ORM would do. But perhaps I am expecting too much of Magento..

    Anyway, this is the code I use now:

    /**
     * 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();
    
        $collection = Mage::getResourceModel('catalog/product_collection')
                                            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
                                            ->addAttributeToSelect(array('product_id' => 'entity_id'))
                                            ->joinTable(array('productauction' => 'auction/productauction'), 'product_id=entity_id', array('start_time' => 'productauction.start_time','end_time' => 'productauction.end_time','entity_id' => 'productauction.productauction_id', 'product_id' => 'product_id'))
                                            ->joinTable(array('auction' => 'auction/auction'), 'product_id = entity_id', array('last_bid' => 'MAX(auction.price)'), 'auction.productauction_id = productauction.productauction_id', 'inner')
                                            ->addMinimalPrice()
                                            ->addTaxPercents()
                                            ->addStoreFilter()
                                            ->setPage((int) $this->getRequest()->getParam('p', 1), 1);
    
        $currentCategory = Mage::registry('current_category');
        if( $currentCategory != null ) {
            $collection->addCategoryFilter($currentCategory);
        }
    
        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']) );
            }
        }
    
        $collection->getSelect()->group('productauction.productauction_id');
        return $collection;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currenty working on a shipping module extension that is used for an order-import
I'm using this TCanvas to draw cursors for my mice Canv := TCanvas.Create; Canv.Handle
I am currenty writing my master's thesis about monitoring of distributed systems. For this
A legacy app I am working on currenty takes ~2hours to build. The project
I'm currently using OpenGL on Android to draw set width lines, which work great
After I create a new UIButton at runtime, and set its titleLabel's text, the
I am currenty using Apache's HttpComponents including the HttpAsyncClient beta, but I was wondering.
Currenty, I'm using the following code to get the country, postal code, locality and
Im currenty develoding a website using mvc 3 razor but have a little problem.
Edit: This is currenty kinda resolved, Instead of struggling with the problem, I started

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.