簡體   English   中英

Magento 1.9 從多個商店獲取產品集合時使用錯誤的平面表

[英]Magento 1.9 using wrong flat table when getting productcollection from multiple stores

我有一個 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()addStoreFilter()對所選表沒有任何影響。

我有什么想念的嗎?

謝謝!

由於我找不到這個問題的原因,所以我找到了解決這個問題的方法。

$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,這對我來說非常有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM