I'm developing a page that displays all the products that have a special price set.
This would be easy if I had a "normal" setup, but my store only shows Grouped Products. All the Simple Products are merely SKU's that are associated with the Grouped Product. The grouped products contains all the general information like desription, product name, etc, and the Simple Products contain information like SKU, Price, VAT, etc.
With this in mind, I thought I would just pull all the simple products that have a special price and load their "parent" grouped product.
Which works, but a new problem arises: there are grouped products with more than one special price SKU associated. Meaning, that product will display twice, thrice, or even more on the page. That makes sense considering my code:
<?php $storeId = Mage::app()->getStore()->getStoreId(); ?>
<?php
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$special= Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', array('neq'=>1))
->addAttributeToFilter('special_price', array('neq'=>''))
->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToSort('special_from_date', 'desc');
$special->load();
?>
<div class="cat-misc">
<?php $_columnCount = 4;?>
<?php foreach ($special as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<?php $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($_product->getId()); ?>
<?php if(isset($parentIds[0])):?>
<?php foreach ($parentIds as $parentId): ?>
<?php $parent = Mage::getModel('catalog/product')->load($parentId); ?>
<?php if ($parent->getStoreId() == $storeId): ?>
<?php $_product = Mage::getModel('catalog/product')->load($parentId);?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<div class="produtos_wrapper">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(158, 158); ?>" width="158" height="158" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" /></a>
<?php
$newFromDate = Mage::getModel('catalog/product')->load($_product->getID())->getNewsFromDate();
$newToDate = Mage::getModel('catalog/product')->load($_product->getID())->getNewsToDate();
$now = date("Y-m-d H:m:s");
if($newFromDate < $now && $newToDate > $now) {
echo "<div id='simbolo_novo' class='simbolo_novo'></div>";
}
?>
<div class="titulos_wrapper">
<p class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a><br /><span class="subtitulo"><?php echo nl2br($_product->getShortDescription()); ?></span> </p>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
</div>
</div>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<?php endif; ?>
</ul-->
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach; ?>
<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
My question is, how would I limit this script to show a Grouped Product only once?