Skip to content

Instantly share code, notes, and snippets.

@seansan
Created June 25, 2016 10:13
Show Gist options
  • Save seansan/9d370f5679937c51fa00e86c23521b40 to your computer and use it in GitHub Desktop.
Save seansan/9d370f5679937c51fa00e86c23521b40 to your computer and use it in GitHub Desktop.
Shopper theme full bestseller list support
<?php
/**
* Product list template
*
* @see Mage_Catalog_Block_Product_List
*/
?>
<?php
$_productCollection = $this->getCollection();
$helper = $this->helper('shoppersettings/image');
$_storeId = Mage::app()->getStore()->getCode();
$_header = $this->getHeader() ?: "Bestselling products"; // get from parameter in CMS block
$_image_type = 'image'; //'small_image'
$reg_img = 'thumbnail';
$hov_img = 'small_image';
$colcount = 3;
$cms_id = $this->helper('shoppersettings')->getCurrentCmsPage();
if ( !$cms_id ) {
$pageLayout = $this->getLayout()->getBlock('root')->getTemplate();
if ( strpos($pageLayout, '2columns') ) {
$grid_class = 'two_columns_' . Mage::getStoreConfig('shoppersettings/catalog/grid_columns_2col');
$colcount = Mage::getStoreConfig('shoppersettings/catalog/grid_columns_2col');
} else {
$grid_class = 'one_column_' . Mage::getStoreConfig('shoppersettings/catalog/grid_columns_1col');
$colcount = Mage::getStoreConfig('shoppersettings/catalog/grid_columns_1col');
}
} else {
if ( $cms_id == 'shopper_home' ) {
$grid_class = 'one_column_' . Mage::getStoreConfig('shoppersettings/catalog/grid_columns_1col');
$colcount = Mage::getStoreConfig('shoppersettings/catalog/grid_columns_1col');
} else {
$grid_class = 'two_columns_' . Mage::getStoreConfig('shoppersettings/catalog/grid_columns_2col');
$colcount = Mage::getStoreConfig('shoppersettings/catalog/grid_columns_2col');
}
}
$colcount = $this->getColcount() ?: $colcount; // get from parameter in CMS block
$custom_img_width = 1144;
$imgX = (int)round($custom_img_width/$colcount); /* CUSTOM CODE */
$imgY = (int)round($helper->calculateHeight($imgX));
?>
<?php if($_productCollection->count()): ?>
<div class="category-products" id="custom_bestsellers">
<div class="header_title theme-bgcolor">
<span>
<?php echo $this->__($_header) ?>
</span>
</div>
<?php $_collectionSize = $_productCollection->count(); ?>
<ul class="products-grid <?php echo $grid_class; ?>">
<?php foreach ($_productCollection as $_product): ?>
<li class="item">
<div class="regular">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()); ?>" class="product-image">
<?php echo $this->helper('shoppersettings')->getLabel($_product); ?>
<?php /** data-srcX2="<?php echo $this->helper('catalog/image')->init($_product, $_image_type)->resize($imgX*2, $imgY*2) ?>" **/ ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, $reg_img)->resize($imgX, $imgY) ?>" data-srcX2="<?php echo $this->helper('catalog/image')->init($_product, $reg_img)->resize($imgX*2, $imgY*2) ?>" width="<?php echo $imgX; ?>" height="<?php echo $imgY; ?>" alt="<?php echo $this->htmlEscape($_product->getName()); ?>" title="<?php echo $this->htmlEscape($_product->getName()); ?>" srcset="<?php echo $this->helper('catalog/image')->init($_product, $reg_img)->resize($imgX, $imgY) ?> 1x, <?php echo $this->helper('catalog/image')->init($_product, $reg_img)->resize(2*$imgX, 2*$imgY) ?> 2x" />
<?php $PackLabel = $_product->getAttributeText('products_in_pack'); ?>
<?php if($PackLabel && $PackLabel > 1): ?>
<div class="package-label <?php echo $PackLabel; ?>-pack thbackground">
<span class="frontend-value"><?php echo $PackLabel; ?>-pack</span>
</div>
<?php endif; ?>
<?php if($_product->getData('manufacturer')): /* Custom code adds brand name */ ?>
<div class="product_brand_name <?php echo $_storeId; ?> thbackground"><?php echo $_product->getAttributeText('manufacturer'); ?></div>
<?php endif; ?>
</a>
<div class="product-info">
<div class="button-container">
<?php if($_product->isSaleable()): ?>
<?php if (Mage::getStoreConfig('shoppersettings/ajax/cart')) : ?>
<?php if ( !($_product->getTypeInstance(true)->hasRequiredOptions($_product) || $_product->isGrouped()) ) { ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart ajax-cart" data-url="<?php echo $this->getAddToCartUrl($_product); ?>" data-id="<?php echo $_product->getId(); ?>"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php } else { ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart show-options" data-id="<?php echo $_product->getId(); ?>"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php } ?>
<?php else: ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php endif; ?>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
<a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_product->getName(); ?></a>
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
</div>
<div class="hover">
<?php if (Mage::getStoreConfig('shoppersettings/ajax/cart') && false) : //quick view button ?>
<a href='<?php echo $this->getUrl('ajax/index/options',array('product_id'=>$_product->getId()));?>' data-fancybox-group="gallery" class='fancybox quick-view' id='fancybox<?php echo $_product->getId()?>' rel='nofollow'><?php echo $this->__('quick view')?></a>
<?php else : ?>
<a href='<?php echo $_product->getProductUrl(); ?>' class='quick-view'><?php echo $this->__('quick view')?></a>
<?php endif; ?>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()); ?>" class="product-image">
<?php echo $this->helper('shoppersettings')->getLabel($_product); ?>
<?php
$_product->load('media_gallery');
$back_img = null; // $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'back');
if ( $back_img ) : ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, $hov_img, $back_img->getFile())->resize($imgX, $imgY) ?>" width="<?php echo $imgX; ?>" height="<?php echo $imgY; ?>" alt="<?php echo $this->htmlEscape($_product->getName()); ?>" title="<?php echo $this->htmlEscape($_product->getName()); ?>" srcset="<?php echo $this->helper('catalog/image')->init($_product, $hov_img, $back_img->getFile())->resize($imgX, $imgY) ?> 1x, <?php echo $this->helper('catalog/image')->init($_product, $hov_img, $back_img->getFile())->resize(2*$imgX, 2*$imgY) ?> 2x" />
<?php else : ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, $hov_img)->resize($imgX, $imgY) ?>" width="<?php echo $imgX; ?>" height="<?php echo $imgY; ?>" alt="<?php echo $this->htmlEscape($_product->getName()); ?>" title="<?php echo $this->htmlEscape($_product->getName()); ?>" srcset="<?php echo $this->helper('catalog/image')->init($_product, $hov_img)->resize($imgX, $imgY) ?> 1x, <?php echo $this->helper('catalog/image')->init($_product, $hov_img)->resize(2*$imgX, 2*$imgY) ?> 2x" />
<?php endif; ?>
</a>
<?php if (Mage::getStoreConfig('sales/msrp/enabled')) : ?>
<?php echo $this->getPriceHtml($_product, true); ?>
<?php else : ?>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()); ?>">
<?php echo $this->helper('shoppersettings/data')->priceFormat( $this->getPriceHtml($_product, true) ); ?>
</a>
<?php endif; ?>
<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
<a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_product->getName(); ?></a>
<?php if($_product->getRatingSummary()){ echo $this->getReviewsSummaryHtml($_product); } ?>
<div class="button-container">
<?php if($_product->isSaleable()): ?>
<?php if (Mage::getStoreConfig('shoppersettings/ajax/cart')) : ?>
<?php if ( !($_product->getTypeInstance(true)->hasRequiredOptions($_product) || $_product->isGrouped()) ) { ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart ajax-cart" data-url="<?php echo $this->getAddToCartUrl($_product); ?>" data-id="<?php echo $_product->getId(); ?>"><span><span><em></em><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php } else { ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart show-options" data-id="<?php echo $_product->getId(); ?>"><span><span><em></em><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php } ?>
<?php else: ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><em></em><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php endif; ?>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
<span class="ajax_loading" id='ajax_loading<?php echo $_product->getId()?>'><img src='<?php echo $this->getSkinUrl('images/ajax-loader.gif')?>' width=16 height=16 alt='loader image' /></span>
</div>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
<?php
/**
* @version 1.0 12.0.2012
* @author Queldorei http://www.queldorei.com <[email protected]>
* @copyright Copyright (C) 2010 - 2012 Queldorei
*/
class Queldorei_ShopperSettings_Block_Bestsellers extends Mage_Catalog_Block_Product_Abstract
{
public function __construct(){
parent::_construct();
$this->setData('bestsellers', Mage::getStoreConfig('shoppersettings/catalog/bestsellers'));
}
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getBestsellers()
{
$id = $this->getData('bestsellers');
if ( empty($id) ) return null;
$productIds = explode(',',$this->getData('bestsellers'));
$products = Mage::getModel("catalog/product")
->getCollection()
->addUrlRewrite()
->addStoreFilter()
->addAttributeToSelect("*")
->addAttributeToFilter('entity_id', array('in' => $productIds));
return $products;
}
public function getIdsArr($element){
return $element['product_id'];
}
public function getProductIds($collection){
$product_ids=array_map(array($this,"getIdsArr"), $collection->getData());
return $product_ids;
}
public function getOneProduct($productid) {
$collection = Mage::getModel('catalog/product')->load($productid);
if($collection->getVisibility()!=1){
if(!$this->getOutofStock()){
if($collection->isSalable()){
return $collection;
}
else{
return false;
}
}
else{
return $collection;
}
}else{
return false;
}
}
}
{{block type="bestseller/bestseller" header="Recently bought" colcount=4 daysback=30 limit=12 category=76 template="catalog/product/bestsellerlist.phtml"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment