dqr3883 2012-11-26 15:04
浏览 74
已采纳

Magento多店 - 展示所有商店的产品

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条回答 默认 最新

  • dphphvs496524 2012-11-28 16:41
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化