Skip to content

Instantly share code, notes, and snippets.

@kingsloi
Last active August 29, 2015 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingsloi/93c33fc6f155f0ade797 to your computer and use it in GitHub Desktop.
Save kingsloi/93c33fc6f155f0ade797 to your computer and use it in GitHub Desktop.
Mangeto 1.9 CE - aheadWorks Blog - Assign a Featured Product to a Blog post that appears in the sidebar
<!--
// add this to:
// app/design/frontend/*skin*/default/layout/aw_blog.xml
// in <blog_post_view>
-->
<reference name="right">
<block type="blog/post" name="featured.product" template="aw_blog/featuredproduct.phtml" before="-"/>
</reference>
<?php
// add this to
// app/code/community/AW/Blog/Model/Blog.php
public function getFeaturedProductId()
{
$content = $this->getData('featured_product_id');
return $content;
}
<?php
// create this file in
// app/design/frontend/*skin*/default/template/aw_blog/featuredproduct.phtml
$post = $this->getPost();
$productID = $post->getFeaturedProductId();
if($productID):
$_product = Mage::getModel('catalog/product')->load($productID);
?>
<div class="block block-list block-blog block-featured-product">
<div class="block-title">
<strong><span>Featured Product</span></strong>
</div>
<div class="block-content">
<div class="product">
<div class="product-image">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_product->getName()) ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200) ?>" width="200" height="200" alt="<?php echo $this->escapeHtml($_product->getName()) ?>" />
</a>
</div>
<div class="product-description">
<h3 class="product-name">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_product->getName()) ?>"><?php echo $this->escapeHtml($_product->getName()) ?></a>
</h3>
<p><?php echo strip_tags(Mage::helper('core/string')->truncate($_product->getShortDescription(), '200')); ?></p>
<a title="<?php echo $this->__('Learn More') ?>" href="<?php echo $this->getAddToCartUrl($_product) ?>" class="btn btn-primary">
<?php echo $this->__('Learn More') ?>
</a>
</div>
</div>
</div>
</div>
<?php endif; ?>
ALTER TABLE aw_blog ADD featured_product_id INT( 10 ) after tags
<?php
// add this to
// app/code/community/AW/Blog/Block/Manage/Blog/Edit/Tab/Form.php
// FEATURED PRODUCT
$products = array(''=>'None');
$productsCollection = Mage::getModel('catalog/product')->getCollection();
$productsCollection->addAttributeToSelect('name');
foreach($productsCollection as $product) {
$products[] = (array(
'label' => (string)$product->getName(),
'value' => $product->getId()
));
}
$fieldset->addField('featured_product_id', 'select', array(
'label' => Mage::helper('cms')->__('Featured Product'),
'required' => false,
'name' => 'featured_product_id',
'values' => $products,
'after_element_html' => 'Featured Product to appear in the sidebar',
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment