我正在尝试列出在过去 72 小时内具有特殊起始日期的所有产品。该脚本工作正常,除了超过 400 种产品超时。
我想我加载了太多的集合或者没有正确使用加载的集合,所以我真的只需要一些优化建议。
这是脚本:
<?php
set_time_limit(0);
require_once 'app/Mage.php';
Mage::app('default');
try
{
$products = Mage::getModel('catalog/product')->getCollection()
->setStoreId(1);
$products->addAttributeToFilter('status', 1);
$products->addAttributeToFilter('visibility', 4);
$products->addAttributeToSelect('*');
$prodIds=$products->getAllIds();
$product_count = 0;
$products_changed = 0;
//$product = Mage::getModel('catalog/product');
echo "Price Changes Last 72 Hours<br><br>";
foreach($prodIds as $productId)
{
$product_count++;
//$products->load($productId);
// load product data
$product = Mage::getModel('catalog/product')->load($productId);
$special_price = round($product->getSpecialprice(),2);
$human_readable_date = $product->getSpecialFromDate();
$sku = $product->getSku();
$specialPriceFromDate = strtotime($human_readable_date);
$time_now = microtime(true);
$product_link = "http://www.mydomain.com.au/".$product->getUrlPath();
$date_array = explode( ' ', $human_readable_date);
$short_date = $date_array[0];
if (($time_now - $specialPriceFromDate) < 259200)
{
$products_changed++;
echo "SKU: " . '<a href=' . $product_link . '>' . $sku . '</a>' . " Date Changed: " . $short_date . " New Price $" . $special_price . "<br>";
}
//if ($product_count == 400) exit;
}
}
catch(Exception $e){
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
error_log($e->getMessage(), 1, 'me@mydomain.com.au', $headers);
die($e->getMessage());
}
?>