0
有什麼方法可以在使用直接SQL的腳本中轉換使用magento模型和集合的腳本。將基於Magento模型的腳本轉換爲SQL
我知道這是可能的,因爲相當一切:),問題是關於一種簡單直觀的方式,讓我從腳本中獲取查詢,然後在直接DB腳本中重用。
爲什麼?我希望能有一個更快的腳本。
代碼示例?
假設這個腳本:
function getProd() {
$collection = Mage::getModel('catalog/product')
->getCollection()
->addTierPriceData();
return $collection;
}
function getTier($prod) {
$t_1 = false;
$_tierPrices = $prod->getTierPrice();
if ($_tierPrices) {
$_firstTier = array_slice($_tierPrices, 0, 1);
if (isset($_firstTier[0]))
$t_1 = $_firstTier[0]['price'];
}
return $t_1;
}
function exec() {
$collection = getProd();
$i = 0;
foreach ($collection as $prod) {
$class = ($i % 2 == 0) ? '' : 'class="odd"';
$t1 = 0;
if ($t1 = getTier($prod)) {
$prod = mage::getModel('catalog/product')->load($prod->getId());
$prod->setPrice($t1);
$prod->save();
if ($safe)
set_time_limit(60);
}
}
}
exec();
基本上我想處理具有層次價格的所有產品和替代產品的主要價格與該層的價格。
這個腳本在12000個產品上花了9小時以上,所以我猜SQL方法會更快,但需要我研究DB結構。
所以如果任何人有一個很好的方法來轉換這個在PHP/SQL腳本,將是巨大的(更多的東西,只有打印集合查詢)
對不起,我剛剛完成更新問題。 回答結構不僅僅是$ collection-> getSelect();是wellcome ...例如更新查詢呢? – WonderLand