我有一個 Magento 1.9 安裝,有 4 個商店(2 個網站,每個有 2 個商店)。對于出口,我需要通過商店獲取所有產品。
所以這就是我嘗試的:
/** @var Mage_Core_Model_Store[] */
$stores = Mage::app()->getStores();
foreach ($stores as $store) {
if (!$store->getIsActive()) {
continue;
}
Mage::app()->setCurrentStore($store);
/** @var Mage_Catalog_Model_Resource_Product_Collection */
$productCollection = Mage::getModel('catalog/product')->getCollection();
$productCollection->setStore($store);
$productCollection->addStoreFilter($store);
$productCollection->addAttributeToSelect(['id']);
// some more filters
$productCollection->load();
foreach ($productCollection->getItems() as $item) {
// do some stuff
}
}
我catalog_product_flat啟用了表格。
當我為我除錯查詢時,我$productCollection發現它為第一個商店使用了正確的平面表,但之后它總是使用之前運行的商店的平面表。
商店 1 ->catalog_product_flat_1
商店 2 ->catalog_product_flat_1
商店 3 ->catalog_product_flat_2
商店 4 ->catalog_product_flat_3
順便說一句:我注意到,setStore()andaddStoreFilter()對所選表沒有任何影響。
有什么我想念的嗎?
謝謝!
uj5u.com熱心網友回復:
由于我找不到此問題的原因,因此我找到了解決此問題的解決方法。
$resource = Mage::getResourceModel('catalog/product_flat');
$select = $resource->getReadConnection()
->select('entity_id')
->from(['table' => $resource->getMainTable()], 'entity_id')
->where('table.status = 1');
// some more filters
$results = $resource->getReadConnection()->fetchAll($select);
此查詢使用正確的平面表,因為我只需要產品 ID,這對我來說非常有效。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/459456.html
標籤:马金托 magento-1.9
