1

I have created a collection factory

$collection = $this->_productCollectionFactory->create()
            ->addAttributeToFilter('status', '1')
            ->addAttributeToFilter('featured', '1')
            ->addAttributeToFilter('type_id',["neq"=>"configurable"]);

and after this i calling load() function

$collection->addAttributeToSelect('*')->load();

and after that applying JOIN's

$collection->getSelect()->join(
                ['cp' => $collection->getTable('custom_product')], 'e.entity_id = cp.marketplace_product_id'
        );

some other JOIN's


$collection->getSelect()->orderRand()->limit(8);

In collection query i am getting perfect query with JOIN table's data.

foreach ($collection as $key => $data){
    $responce[$key]['custom_price'] = $data->getCustomSpecialPrice();
}

I am getting all custom_special_price and other JOIN fields DATA IN Query But not in foreach.

But when i don't use load() function it gives me data using get method ,But when i do use load() function it doesn't.

So my question is why Magento loads data in Query ? But not in Object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.