【问题标题】:Magento: Display products with group pricesMagento:以团体价格显示产品
【发布时间】:2015-01-08 11:43:42
【问题描述】:

我需要展示有团价的产品。 我目前所拥有的就是这个。

首先我加载产品集合。

<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_collectionSize = $_productCollection->count();
?>

然后,我只检查两件事。如果用户登录,客户群。

<?php if(Mage::getSingleton('customer/session')->isLoggedIn()){
// Get group Id
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
//Get customer Group name
$group = Mage::getModel('customer/group')->load($groupId);
$var_customer_group = $group->getCode();
$product = Mage::getModel('catalog/product')->load($productId);
}?>

<?php if ($var_customer_group == "Wholesale")
        { ?> 

然后我用我的产品建立了一个列表。

<ul>
   <?php foreach ($_productCollection as $_product): ?>
   <li>
   </li>
   <?php endforeach ?>
</ul>
   <?php } ?>

我如何在$_productCollection 中查看哪些产品有团价。 任何帮助将不胜感激!

【问题讨论】:

    标签: php magento collections


    【解决方案1】:

    我设法得到了我所要求的。如果您开始跳出框框思考,这实际上非常简单。 我会提供代码来帮助其他有同样问题的人。

    首先,添加产品的集合。

    <?php
        $_productCollection=$this->getLoadedProductCollection();
        $_collectionSize = $_productCollection->count();
    ?>
    

    那么,

    <?php foreach ($_productCollection as $_product): ?>
        <?php $product_id = $_product->getId();
              $arrayofproductsID = Mage::getModel('catalog/product')->load($product_id);
              $groupPrices = $arrayofproductsID->getData('group_price');
        ?>
        <?php if(($groupPrices[0][price])) { ?> <-- //Here happens the check if there is a group price.
            <li> ... </li>
        <?php } ?>
    <?php endforeach ?>
    

    【讨论】:

      猜你喜欢
      • 2015-02-02
      • 1970-01-01
      • 2015-10-08
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 2014-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多