Created
June 21, 2018 13:26
-
-
Save sreichel/9ddf5c831a5dd30f43b05f6cc53892e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Amasty_Finder_Block_Product extends Mage_Core_Block_Template | |
{ | |
public function getProdctfinderCollection() | |
{ | |
return Mage::helper('amfinder/product')->getProductfinderCollection($this->getFinderId(), $this->getProductId()); | |
} | |
public function getProductId() | |
{ | |
if (!$this->hasData('product_id')) { | |
if ($currentProduct = Mage::registry('current_product')) { | |
$this->setProductId($currentProduct->getId()); | |
} | |
} | |
return $this->_getData('product_id'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Amasty_Finder_Helper_Product extends Mage_Core_Helper_Abstract | |
{ | |
/** | |
* @return Varien_Data_Collection | |
*/ | |
public function getProductfinderCollection($finderId, $productId) | |
{ | |
$collection = new Varien_Data_Collection(); | |
$order = array(); | |
$columns = Mage::getModel('amfinder/dropdown')->getCollection() | |
->addFieldToFilter('finder_id', $finderId) | |
->getSize(); | |
$resource = Mage::getSingleton('core/resource'); | |
$read = $resource->getConnection('core_write'); | |
$select = $read->select() | |
->from( | |
array('map' => $resource->getTableName('amfinder/map')), | |
array('sku') | |
); | |
for ($i = 1; $i <= $columns; $i++) { | |
$prev = 'value' . ($i - 1); | |
$alias = 'value' . $i; | |
$name = 'name' . $i; | |
$order[] = $name; | |
if ($i === 1) { | |
$select->joinInner( | |
array($alias => $resource->getTableName('amfinder/value')), | |
"{$alias}.value_id = map.value_id", | |
array($name => 'name') | |
); | |
} else { | |
$select->joinInner( | |
array($alias => $resource->getTableName('amfinder/value')), | |
"{$alias}.value_id = {$prev}.parent_id", | |
array($name => 'name') | |
); | |
} | |
} | |
$select->where('pid = ?', $productId); | |
$select->order(array_reverse($order)); | |
$query = $read->query($select); | |
while ($row = $query->fetch()) { | |
$item = new Varien_Object($row); | |
$collection->addItem($item); | |
} | |
return $collection; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<block type="amfinder/product" name="product.amfinder" template="amfinder/product.phtml"> | |
<action method="setFinderId"><value>1</value></action> | |
</block> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $collection = $this->getProdctfinderCollection(); ?> | |
<?php if (!$collection->getSize()): ?> | |
<div class="vehiclefits_compa"> | |
<?php echo $this->__('There are no vehicle compatibilities for this article.') ?> | |
</div> | |
<?php else: ?> | |
<div class="vehiclefits_compa"> | |
<h3><?php echo $this->__('The article is compatible with the vehicle configurations listed below.') ?></h3> | |
</div> | |
<table class="data-table" id="product-vaf-table"> | |
<thead> | |
<tr> | |
<th><?php echo $this->__('Make') ?></th> | |
<th><?php echo $this->__('Model') ?></th> | |
<th><?php echo $this->__('Year') ?></th> | |
<th><?php echo $this->__('Radio') ?></th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php foreach ($collection as $item): ?> | |
<tr class="item"> | |
<td><?php echo $item->getName4() ?></td> | |
<td><?php echo $item->getName3() ?></td> | |
<td><?php echo $item->getName2() ?></td> | |
<td><?php echo $item->getName1() ?></td> | |
</tr> | |
<?php endforeach; ?> | |
</tbody> | |
</table> | |
<script type="text/javascript">decorateTable('product-vaf-table')</script> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment