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
我刚刚建立了一个Magento多店,我正在试图弄清楚如何在我的主页上展示这三家商店的产品。问题是我的代码只显示当前商店的帖子。例如:商店(1)显示商店的商品(1)商店(2)显示商店(2)的商品但是我不需要这样。我需要所有商店的所有产品
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 个解决方案
#1
0
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.
Magento为产品使用平面表,因此每个商店都有一个数据库表,只有为该商店启用的产品。使用此原理,无法使用默认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).
为了让您走上正轨:您需要根据catalog_product表(不是平面)进行自己的查询。
#2
0
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;
在一个与magento无关的外部文件中(我把它放在root中)我称之为magento(在外面,所以我能够使用它的全部功能,而不必担心限制),就像这样;
<?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.
注意:感谢glist.phtml显示所有产品,这是一个简单的list.phtml文件编辑,以满足我的需要。
Yo!
呦!
#1
0
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.
Magento为产品使用平面表,因此每个商店都有一个数据库表,只有为该商店启用的产品。使用此原理,无法使用默认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).
为了让您走上正轨:您需要根据catalog_product表(不是平面)进行自己的查询。
#2
0
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;
在一个与magento无关的外部文件中(我把它放在root中)我称之为magento(在外面,所以我能够使用它的全部功能,而不必担心限制),就像这样;
<?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.
注意:感谢glist.phtml显示所有产品,这是一个简单的list.phtml文件编辑,以满足我的需要。
Yo!
呦!