Skip to content

Commit

Permalink
Version 1.6.9: Added an event which allows you to generate custom pro…
Browse files Browse the repository at this point in the history
…duct autocomplete HTML
  • Loading branch information
jeroenvermeulen committed Jan 21, 2015
1 parent eec17d9 commit 5d72f90
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,36 @@ function _toHtml()
if (empty( $productIds )) {
return parent::_toHtml();
} else {
$html =
'<ul class="product_suggest"><li style="display: none"></li>'; // Magento by default starts with a hidden <li>, don't know why.
$productCollection = $products = Mage::getModel( 'catalog/product' )->getCollection()->addAttributeToFilter(
'entity_id',
array( 'in' => $productIds )
)->addAttributeToSelect( array( 'name', 'thumbnail', 'product_url' ) );
$counter = 0;
foreach ($productCollection as $product) {
$rowClass = ( ++$counter ) % 2 ? 'odd' : 'even';
$html .= sprintf( '<li title="%s" class="%s" data-url="%s">',
htmlentities( $product->getName() ),
$rowClass,
htmlentities( $product->getProductUrl() ) );
$html .= '<span class="suggestions-productimage">';
$html .= sprintf(
'<img src="%s" />',
htmlentities( Mage::helper( 'catalog/image' )->init( $product, 'thumbnail' )->resize( '50' ) )
);
$html .= '</span>';
$html .= '<span class="suggestions-productname">';
$html .= htmlentities( Mage::helper( 'core/string' )->truncate( $product->getName(), 100 ) );
$html .= '</span>';
$html .= '</li>';
// Magento by default starts with a hidden <li>, don't know why.
$html = '<ul class="product_suggest"><li style="display: none"></li>';
$transport = new Varien_Object();
$transport->setHtml(null); // Event listener can fill this with HTML, <li> tags.
Mage::dispatchEvent( 'jeroenvermeulen_solarium_get_product_suggest_html',
array('product_ids'=>$productIds,'transport'=>$transport) );
if ( !is_null($transport->getHtml()) ) {
$html .= $transport->getHtml();
} else {
$productCollection = $products = Mage::getModel( 'catalog/product' )
->getCollection()
->addAttributeToFilter( 'entity_id', array('in'=>$productIds) )
->addAttributeToSelect( array('name','thumbnail','product_url') );
$counter = 0;
foreach ($productCollection as $product) {
$rowClass = ( ++$counter ) % 2 ? 'odd' : 'even';
$imageUrl = Mage::helper( 'catalog/image' )->init( $product, 'thumbnail' )->resize( '50' );
$showName = Mage::helper( 'core/string' )->truncate( $product->getName(), 100 );
$html .= sprintf( '<li title="%s" class="%s" data-url="%s">',
htmlentities($product->getName()),
$rowClass,
htmlentities($product->getProductUrl()) );
$html .= '<span class="suggestions-productimage">';
$html .= sprintf( '<img src="%s" />', htmlentities( $imageUrl ) );
$html .= '</span>';
$html .= '<span class="suggestions-productname">';
$html .= htmlentities( $showName );
$html .= '</span>';
$html .= '</li>';
}
}
$html .= '</ul>';
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/JeroenVermeulen/Solarium/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<config>
<modules>
<JeroenVermeulen_Solarium>
<version>1.6.8</version>
<version>1.6.9</version>
</JeroenVermeulen_Solarium>
</modules>
<global>
Expand Down

0 comments on commit 5d72f90

Please sign in to comment.