|
<?php |
|
|
|
class Mage_Catalog_Block_Product_List_Related extends Mage_Catalog_Block_Product_Abstract |
|
{ |
|
/** |
|
* Default toolbar block name |
|
* |
|
* @var string |
|
*/ |
|
protected $_defaultToolbarBlock = 'catalog/product_list_toolbar'; |
|
|
|
/** |
|
* Product Collection |
|
* |
|
* @var Mage_Eav_Model_Entity_Collection_Abstract |
|
*/ |
|
protected $_productCollection; |
|
|
|
/** |
|
* Retrieve loaded category collection |
|
* |
|
* @return Mage_Eav_Model_Entity_Collection_Abstract |
|
*/ |
|
protected function _getProductCollection() |
|
{ |
|
|
|
if (isset($_GET['p'])) {$page = $_GET['p'];}else{$page = 1;}; |
|
$product = Mage::registry('product'); |
|
/* @var $product Mage_Catalog_Model_Product */ |
|
|
|
$this->_itemCollection = $product->getRelatedProductCollection() |
|
->addAttributeToSort('name', 'asc') |
|
->addStoreFilter() |
|
->setPage($page,20) |
|
; |
|
|
|
$this->_addProductAttributesAndPrices($this->_itemCollection); |
|
|
|
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection)->addVisibleFilterToCollection($this->_itemCollection); |
|
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection); |
|
|
|
foreach ($this->_itemCollection as $product) { |
|
$product->setDoNotUseCategoryId(true); |
|
} |
|
|
|
$this->_productCollection = $this->_itemCollection; |
|
|
|
return $this->_productCollection; |
|
} |
|
|
|
|
|
/** |
|
* Retrieve loaded category collection |
|
* |
|
* @return Mage_Eav_Model_Entity_Collection_Abstract |
|
*/ |
|
public function getLoadedProductCollection() |
|
{ |
|
return $this->_getProductCollection(); |
|
} |
|
|
|
/** |
|
* Retrieve current view mode |
|
* |
|
* @return string |
|
*/ |
|
public function getMode() |
|
{ |
|
return $this->getChild('toolbar')->getCurrentMode(); |
|
} |
|
|
|
/** |
|
* Need use as _prepareLayout - but problem in declaring collection from |
|
* another block (was problem with search result) |
|
*/ |
|
protected function _beforeToHtml() |
|
{ |
|
/*$toolbar = $this->getLayout()->createBlock('catalog/product_vergelijker_toolbar', microtime()); |
|
if ($toolbarTemplate = $this->getToolbarTemplate()) { |
|
$toolbar->setTemplate($toolbarTemplate); |
|
}*/ |
|
$toolbar = $this->getToolbarBlock(); |
|
|
|
// called prepare sortable parameters |
|
$collection = $this->_getProductCollection(); |
|
|
|
// use sortable parameters |
|
if ($orders = $this->getAvailableOrders()) { |
|
$toolbar->setAvailableOrders($orders); |
|
} |
|
if ($sort = $this->getSortBy()) { |
|
$toolbar->setDefaultOrder($sort); |
|
} |
|
if ($modes = $this->getModes()) { |
|
$toolbar->setModes($modes); |
|
} |
|
|
|
// set collection to tollbar and apply sort |
|
$toolbar->setCollection($collection); |
|
|
|
$this->setChild('toolbar', $toolbar); |
|
Mage::dispatchEvent('catalog_block_product_vergelijker_collection', array( |
|
'collection'=>$this->_getProductCollection(), |
|
)); |
|
|
|
$this->_getProductCollection()->load(); |
|
Mage::getModel('review/review')->appendSummary($this->_getProductCollection()); |
|
return parent::_beforeToHtml(); |
|
} |
|
|
|
/** |
|
* Retrieve Toolbar block |
|
* |
|
* @return Mage_Catalog_Block_Product_Vergelijker_Toolbar |
|
*/ |
|
public function getToolbarBlock() |
|
{ |
|
if ($blockName = $this->getToolbarBlockName()) { |
|
if ($block = $this->getLayout()->getBlock($blockName)) { |
|
return $block; |
|
} |
|
} |
|
$block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime()); |
|
return $block; |
|
} |
|
|
|
/** |
|
* Retrieve list toolbar HTML |
|
* |
|
* @return string |
|
*/ |
|
public function getToolbarHtml() |
|
{ |
|
return $this->getChildHtml('toolbar'); |
|
} |
|
|
|
public function setCollection($collection) |
|
{ |
|
$this->_productCollection = $collection; |
|
return $this; |
|
} |
|
|
|
public function addAttribute($code) |
|
{ |
|
$this->_getProductCollection()->addAttributeToSelect($code); |
|
return $this; |
|
} |
|
|
|
public function getPriceBlockTemplate() |
|
{ |
|
return $this->_getData('price_block_template'); |
|
} |
|
|
|
/** |
|
* Retrieve Catalog Config object |
|
* |
|
* @return Mage_Catalog_Model_Config |
|
*/ |
|
protected function _getConfig() |
|
{ |
|
return Mage::getSingleton('catalog/config'); |
|
} |
|
|
|
/** |
|
* Prepare Sort By fields from Category Data |
|
* |
|
* @param Mage_Catalog_Model_Category $category |
|
* @return Mage_Catalog_Block_Product_Vergelijker |
|
*/ |
|
public function prepareSortableFieldsByCategory($category) { |
|
if (!$this->getAvailableOrders()) { |
|
$this->setAvailableOrders($category->getAvailableSortByOptions()); |
|
} |
|
$availableOrders = $this->getAvailableOrders(); |
|
if (!$this->getSortBy()) { |
|
if ($categorySortBy = $category->getDefaultSortBy()) { |
|
if (!$availableOrders) { |
|
$availableOrders = $this->_getConfig()->getAttributeUsedForSortByArray(); |
|
} |
|
if (isset($availableOrders[$categorySortBy])) { |
|
$this->setSortBy($categorySortBy); |
|
} |
|
} |
|
} |
|
|
|
|
|
return $this; |
|
} |
|
} |