0

In Magento 2.2.5, I have Custom Model Collection (followed this tutorial).

In that I want to add the Product Collection into this custom collection by default. How to achieve this.

3
  • Can you please add your code what you have tried before? Commented Oct 5, 2018 at 5:56
  • Same as the tutorial I referred here. mageplaza.com/magento-2-module-development/… Commented Oct 5, 2018 at 6:05
  • @SaravananDS Plz give brief detail what you actually want? where you want to add/embed Or you want standalone product object in model/block ? You question is totally confusing. Commented Oct 5, 2018 at 7:23

1 Answer 1

0

You can override

Magento\Catalog\Model\ResourceModel\Product\Collection class and join your custom collection with using _initSelect() function

Example:

protected function _initSelect()
{
    $this->getSelect()->joinRight(['secondTable' => $this->getTable('custom_table')],'secondTable.id = main_table.entity_id');
    return $this;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.