<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php $sidedeals_number = Mage::getStoreConfig('multipledeals/sidebar_configuration/sidedeals_number'); ?>
<?php $display_qty = Mage::getStoreConfig('multipledeals/sidebar_configuration/display_qty'); ?>
<?php $display_past_deals = Mage::getStoreConfig('multipledeals/configuration/past_deals'); ?>
<?php $items = $this->getItems(); ?>

<?php if (count($items)!=0 && $sidedeals_number!=0 && Mage::getStoreConfig('multipledeals/configuration/enabled')): ?>
<div class="block block-deals">
    <div class="block-title">
        <strong><span><?php echo $this->__('Multiple deals') ?></span></strong>
    </div>
    <div class="block-content">
        <ol class="mini-products-list" id="block-deals">
        <?php $i = 0; foreach($items as $_item): $i++; ?>
			<?php $item_url = $_item->getProductUrl(); ?>
			<?php $multipledeals = Mage::getModel('multipledeals/multipledeals')->getCollection()->addFieldToFilter('status', array('eq' => 3))->addFieldToFilter('product_id', array('eq' => $_item->getId()))->getFirstItem(); ?>
            <li class="item">
                    <a href="<?php echo $item_url; ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(60) ?>" width="60" height="60" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
                    <div class="product-details">
                        <p class="product-name"><a href="<?php echo $item_url; ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a></p>
						<?php if (Mage::getStoreConfig('multipledeals/sidebar_configuration/display_price') && ($_item->getTypeId()=='simple' || $_item->getTypeId()=='virtual' || $_item->getTypeId()=='downloadable' || $_item->getTypeId()=='configurable')): ?>
							<?php echo $this->getPriceHtml($_item, true, '-deal') ?>
						<?php endif; ?>
						<?php if ($multipledeals->getId()!='' && ($_item->getTypeId()=='simple' || $_item->getTypeId()=='virtual' || $_item->getTypeId()=='downloadable') && $display_qty): ?>
							<span class="deal-qty"><b><?php echo $multipledeals->getDealQty(); ?> item(s)</b> left!</span>
						<?php endif; ?>
                    </div>
            </li>
			<?php if ($sidedeals_number<=$i) break; ?>
        <?php endforeach; ?>
        </ol>
		<div class="actions">
			<div class="left" style="margin-right:7px;font-weight:bold">View: </div><a href="<?php echo $this->getUrl('multipledeals/index/list'); ?>"><?php echo $this->__('All Deals') ?></a><?php if ($display_past_deals): ?><div style="float:left;padding:0px 5px 0px 5px;">||</div><a href="<?php echo $this->getUrl('multipledeals/index/recent'); ?>"><?php echo $this->__('Past Deals') ?></a><?php endif; ?>
		</div>
        <script type="text/javascript">decorateList('block-deals', 'none-recursive')</script>
    </div>
</div>
<?php endif; ?>
