3
votes

I've just set up a Magento multi-store, and I'm trying to figure out how to display products from those 3 stores in my homepage. Problem is that my code is only showing the posts from the current store. ex: store (1) shows products of store (1) store (2) shows products of store (2) but I don't need it that way. I need all products from all stores

here's my code, so far. Could somebody help me?

<?php 
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->setVisibility(array(2,3,4))                   
->setOrder('created_at', 'desc')
->setPage(1, 20)
->setStoreId('1');
?>

<?php foreach($_productCollection as $_product) : ?>

<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(250, 150); ?>" alt="" />
<a href="<?php echo $_product->getProductUrl(); ?>"> <?php echo $_product->getName(); ?> </a>
<div class="grddescription"><?php echo $_product->getDescription(); ?>

<?php endforeach; ?>

thank you, fellas!

2
Why not just remove setStoreId ?user487772
unfortunately with or without it is the same thing... doesn't workAntonio Gallo

2 Answers

0
votes

Magento uses flat tables for the products, so you will have a database table for each store with only the products that are enabled for that store. Going with this principe, it is not possible to get all products using default Magento.

To get you on the right track: You'll need to make you own query to do this based on the catalog_product tables (not flat).

0
votes

I found a way to get it work!

in a external file which does not have nothing to do with magento (I placed it in root) I call magento (in the outside, so I'm able to use all of it's feat without having to worry about limitations) like this;

<?php 
    define('MAGENTOO', realpath('/var/wwweb/magento/'));
    require_once(MAGENTOO . '/app/Mage.php');
    $app = Mage::app();
?>

than with this;

<?php
    $products = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status', 1);

    $block = Mage::getSingleton('core/layout')->createBlock('catalog/product_list')
    ->setTemplate('/catalog/product/glist.phtml')
    ->setCollection($products);

    echo $block->toHtml();
?>

I'm able to get all the products from all the sites!

Note: all the products are displayed thanks to glist.phtml which is a simple list.phtml file edited to fit my needs.

Yo!