Pages

Wednesday 12 November 2014

Magento product slider

1-place the jquery.bxslider folder in magento root js folder.
From: http://bxslider.com/examples/carousel-dynamic-number-slides
2-And place the following code. in your product collection page For jquery:
-----------------------------------------------------------------------------------------------------------------------
<link rel="stylesheet" href="<?php echo $this->getJsUrl()?>jquery.bxslider/jquery.bxslider.css" type="text/css" />
<script src="<?php echo $this->getJsUrl()?>jquery.bxslider/jquery.bxslider.js"></script>
<script type="text/javascript">
jQuery(window).load(function(){
jQuery('.bxslider').bxSlider({
pager:false,
minSlides: 3,
maxSlides: 5,
slideWidth: 240,
slideMargin:10
});
})
</script> 
--------------------------------------------------------------------------------------
For product collection:
<!-- for related product-->    
<div class="block block-related block-related-thumbnails">
<div class="also-bought"><h2 class="section-title padding-right "><?php echo $this->__('CUSTOMER WHO BOUGHT THIS ITEAM ALSO BOUGHT'); ?></h2></div>

<ul class="bxslider">    
<?php
$_productCollection = Mage::getModel('catalog/product')->getCollection();                              
$_productCollection->addAttributeToFilter('status', 1); //enabled
$_productCollection->addAttributeToFilter('visibility', 4); //catalog, search
$_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$_productCollection->setOrder('name', 'ASC');
$_productCollection->getSelect()->limit(10);

?>
<?php  
foreach ($_productCollection as $_product)
{
$model = Mage::getModel('catalog/product');
$product_id = $_product->getId();
$_product = $model->load($product_id);
//echo $_product->getPrice()."<br>";
//echo $_product->getName()."<br>";
$_image=Mage::getModel('catalog/product')->load($product_id);
//echo Mage::helper('catalog/image')->init($_image, 'image')."<br>";
?>
<li><div class="also-bought-product">
<div class="also-bought-product-image"><a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo Mage::helper('catalog/image')->init($_image, 'image')->resize(200,150); ?>"></a></div>
<div class="also-bought-product-name"><?php echo $_product->getName(); ?></div>
<?php $actualprice= Mage::helper('core')->currency($_product->getPrice(),true,false);//with currency symbol
$specialprice= Mage::helper('core')->currency($_product->getSpecialPrice(),true,false);//with currency symbol
$actual_Price = $_product->getPrice();
$special_price = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice(); // Get the Special Price without currency
$specialPriceFromDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialFromDate();// Get the Special Price FROM date
$specialPriceToDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialToDate();// Get the Special Price TO date
$today =  time();// Get Current date ?>
<?php
if ($special_price): ?>
<div class="custom-product-div">
<?php
if ($special_price):
if($today >= strtotime( $specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate)): ?>
<div class="special-price"><?php echo $specialprice; ?></div>
<?php  
endif;
endif;?>        
<div class="actual-price"><?php echo $actualprice; ?></div>
<?php
if ($special_price):
if($today >= strtotime( $specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate)): ?>
<?php // Discount percents output start ?>
<?php if($special_price < $actual_Price ): ?>
<?php $_savePercent = 100 - round(($special_price / $actual_Price)*100); ?>
<p class="special-price yousave">
<span class="price"><?php echo $_savePercent; ?>% <span>OFF</span></span>
</p>
<?php endif; ?>
<?php // Discount percent output end ?>
<?php  
endif;
endif;?>
</div>
<?php else :?>
<div class="custom-product-div"><div class="actualprice"><?php echo $actualprice; ?></div></div>
<?php endif;?>
</div></li>
<?php    
}                                     
?>
</ul>
</div>

No comments:

Post a Comment