如何将两者结合起来

时间:2015-05-15 08:24:47

标签: php magento

请帮助我,我做2个foreach。而这个外观变成了双重。

<?php
$_product = $this->getProduct();
if ($this->getItems()->getSize()) {
    $related_prods = Mage::getModel('catalog/product')
            ->getCollection()
            ->addAttributeToSelect('condition')
            ->addAttributeToFilter('entity_id', array('in' => $_product->getRelatedProductIds()));
    foreach ($this->getItems() as $_item) {
        foreach ($related_prods as $related) {
            ?>
            <li class="item col-lg-12 border-ngisor">
                <div class="col-lg-6">
                    <div class="product">
                        <div class="product-details">
                            <p class="product-name"><a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->escapeHtml($_item->getName()) ?></a></p>
                            <?php echo $this->getPriceHtml($_item, true, '-related') ?>
                            <?php if ($this->helper('wishlist')->isAllow()) : ?>
                                <a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a>
                                <?php endif; ?>
                        </div>
                    </div>
                </div>
                <div class="col-lg-6">
                    <?php echo $related->getData('condition'); ?>
                </div>
            </li>
            <?php
        }
    }
}
?>

可以解释如何将两者结合起来 有两个foreach,一个foreach到另一个foreach 在foreach中遇到问题。

0 个答案:

没有答案