Skip to main content
deleted 1 character in body
Source Link
sv3n
  • 11.7k
  • 7
  • 41
  • 73

"a more efficient way" is to use product collcections where final price addis already add to. Some numbers here: What is faster - getting raw attribute value or use collection?

Using ->addFinalPrice() will add something like this to collection query ...

, price_index.price, price_index.tax_class_id, price_index.final_price, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS minimal_price, price_index.min_price, price_index.max_price, price_index.tier_price

and

INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0

I'd us a colletion like

$collection = Mage::getResourceModel('catalog/product_collection')
    ->addIdFilter($productIds)
    ->addFinalPrice();

foreach ($collection as $product) {
    $finalPrices[] = $product->getFinalPrice();
}
  • Total Incl. Wall Time (microsec): 2,131,092 microsecs
  • Total Incl. CPU (microsecs): 2,109,925 microsecs
  • Total Incl. MemUse (bytes): 4,776,976 bytes
  • Total Incl. PeakMemUse (bytes): 4,829,112 bytes
  • Number of Function Calls: 103,275

compared to

foreach($productIds as $productId) {
    $finalPrices[] = Mage::getModel('catalog/product')->load($productId)->getFinalPrice();
}
  • Total Incl. Wall Time (microsec): 116,555,318 microsecs
  • Total Incl. CPU (microsecs): 114,323,845 microsecs
  • Total Incl. MemUse (bytes): 22,853,768 bytes
  • Total Incl. PeakMemUse (bytes): 23,126,448 bytes
  • Number of Function Calls: 5,465,676

"a more efficient way" is to use product collcections where final price add already add to. Some numbers here: What is faster - getting raw attribute value or use collection?

Using ->addFinalPrice() will add something like this to collection query ...

, price_index.price, price_index.tax_class_id, price_index.final_price, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS minimal_price, price_index.min_price, price_index.max_price, price_index.tier_price

and

INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0

I'd us a colletion like

$collection = Mage::getResourceModel('catalog/product_collection')
    ->addIdFilter($productIds)
    ->addFinalPrice();

foreach ($collection as $product) {
    $finalPrices[] = $product->getFinalPrice();
}
  • Total Incl. Wall Time (microsec): 2,131,092 microsecs
  • Total Incl. CPU (microsecs): 2,109,925 microsecs
  • Total Incl. MemUse (bytes): 4,776,976 bytes
  • Total Incl. PeakMemUse (bytes): 4,829,112 bytes
  • Number of Function Calls: 103,275

compared to

foreach($productIds as $productId) {
    $finalPrices[] = Mage::getModel('catalog/product')->load($productId)->getFinalPrice();
}
  • Total Incl. Wall Time (microsec): 116,555,318 microsecs
  • Total Incl. CPU (microsecs): 114,323,845 microsecs
  • Total Incl. MemUse (bytes): 22,853,768 bytes
  • Total Incl. PeakMemUse (bytes): 23,126,448 bytes
  • Number of Function Calls: 5,465,676

"a more efficient way" is to use product collcections where final price is already add to. Some numbers here: What is faster - getting raw attribute value or use collection?

Using ->addFinalPrice() will add something like this to collection query ...

, price_index.price, price_index.tax_class_id, price_index.final_price, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS minimal_price, price_index.min_price, price_index.max_price, price_index.tier_price

and

INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0

I'd us a colletion like

$collection = Mage::getResourceModel('catalog/product_collection')
    ->addIdFilter($productIds)
    ->addFinalPrice();

foreach ($collection as $product) {
    $finalPrices[] = $product->getFinalPrice();
}
  • Total Incl. Wall Time (microsec): 2,131,092 microsecs
  • Total Incl. CPU (microsecs): 2,109,925 microsecs
  • Total Incl. MemUse (bytes): 4,776,976 bytes
  • Total Incl. PeakMemUse (bytes): 4,829,112 bytes
  • Number of Function Calls: 103,275

compared to

foreach($productIds as $productId) {
    $finalPrices[] = Mage::getModel('catalog/product')->load($productId)->getFinalPrice();
}
  • Total Incl. Wall Time (microsec): 116,555,318 microsecs
  • Total Incl. CPU (microsecs): 114,323,845 microsecs
  • Total Incl. MemUse (bytes): 22,853,768 bytes
  • Total Incl. PeakMemUse (bytes): 23,126,448 bytes
  • Number of Function Calls: 5,465,676
added 1434 characters in body
Source Link
sv3n
  • 11.7k
  • 7
  • 41
  • 73

You can try"a more efficient way" is to use product collcections where final price add already add to. Some numbers here: What is faster - getting raw attribute value or use collection?

Using ->addFinalPrice() will add something like this to collection query ...

, price_index.price, price_index.tax_class_id, price_index.final_price, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS minimal_price, price_index.min_price, price_index.max_price, price_index.tier_price

and

INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0

I'd us a colletion like

$productIds = array(/* your IDs */);
$collection = Mage::getResourceModel('catalog/product_collection')
    ->addIdFilter($productIds)
    ->addFinalPrice();

foreach ($collection as $product) {
    $finalPrice$finalPrices[] = $product->getFinalPrice();
}
  • Total Incl. Wall Time (microsec): 2,131,092 microsecs
  • Total Incl. CPU (microsecs): 2,109,925 microsecs
  • Total Incl. MemUse (bytes): 4,776,976 bytes
  • Total Incl. PeakMemUse (bytes): 4,829,112 bytes
  • Number of Function Calls: 103,275

compared to

foreach($productIds as $productId) {
    $finalPrices[] = Mage::getModel('catalog/product')->load($productId)->getFinalPrice();
}
  • Total Incl. Wall Time (microsec): 116,555,318 microsecs
  • Total Incl. CPU (microsecs): 114,323,845 microsecs
  • Total Incl. MemUse (bytes): 22,853,768 bytes
  • Total Incl. PeakMemUse (bytes): 23,126,448 bytes
  • Number of Function Calls: 5,465,676

You can try this ...

$productIds = array(/* your IDs */);
$collection = Mage::getResourceModel('catalog/product_collection')
    ->addIdFilter($productIds)
    ->addFinalPrice();

foreach ($collection as $product) {
    $finalPrice = $product->getFinalPrice();
}

"a more efficient way" is to use product collcections where final price add already add to. Some numbers here: What is faster - getting raw attribute value or use collection?

Using ->addFinalPrice() will add something like this to collection query ...

, price_index.price, price_index.tax_class_id, price_index.final_price, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS minimal_price, price_index.min_price, price_index.max_price, price_index.tier_price

and

INNER JOIN catalog_product_index_price AS price_index ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0

I'd us a colletion like

$collection = Mage::getResourceModel('catalog/product_collection')
    ->addIdFilter($productIds)
    ->addFinalPrice();

foreach ($collection as $product) {
    $finalPrices[] = $product->getFinalPrice();
}
  • Total Incl. Wall Time (microsec): 2,131,092 microsecs
  • Total Incl. CPU (microsecs): 2,109,925 microsecs
  • Total Incl. MemUse (bytes): 4,776,976 bytes
  • Total Incl. PeakMemUse (bytes): 4,829,112 bytes
  • Number of Function Calls: 103,275

compared to

foreach($productIds as $productId) {
    $finalPrices[] = Mage::getModel('catalog/product')->load($productId)->getFinalPrice();
}
  • Total Incl. Wall Time (microsec): 116,555,318 microsecs
  • Total Incl. CPU (microsecs): 114,323,845 microsecs
  • Total Incl. MemUse (bytes): 22,853,768 bytes
  • Total Incl. PeakMemUse (bytes): 23,126,448 bytes
  • Number of Function Calls: 5,465,676
Source Link
sv3n
  • 11.7k
  • 7
  • 41
  • 73

You can try this ...

$productIds = array(/* your IDs */);
$collection = Mage::getResourceModel('catalog/product_collection')
    ->addIdFilter($productIds)
    ->addFinalPrice();

foreach ($collection as $product) {
    $finalPrice = $product->getFinalPrice();
}