Magento getSingleton() vs getModel() issue

前端 未结 5 1114
时光取名叫无心
时光取名叫无心 2020-12-24 03:30

I want to loop over an array of product IDs in Magento. In the loop I am displaying some custom attributes of the products as:

foreach ($products as $product         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-24 04:14

    You´ll find the difference between getModel() and getSingleton() in the other answers.

    But if you want to speed up your code, assuming you have a collection, do the following:

    $products->addAttributeToSelect('credits');
    
    foreach ($products as $product) {
       echo '
    ' . $product->getCredits(); }

    So you don´t have to load every product, which is very time-consuming.

提交回复
热议问题