Magento中新建添加了special price的产品模块

1,721 人次阅读
没有评论

共计 1658 个字符,预计需要花费 5 分钟才能阅读完成。

Magneto中新建special price页面这个功能模块用到的应该不多,现在的商城基本都是所有的产品的会加上special price。国外有些商城可能会用到这个功能,放假的时候查了些资料,现在分享下这个功能模块。

在app/design/frontend/default/你的主题/template/catalog/product中新建special.phtml,加入

<?php
include_once 'app/Mage.php';
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));

$_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addMinimalPrice()
            ->addStoreFilter();

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($_productCollection);

$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);

$_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
    ->addAttributeToFilter('special_to_date', array('or'=> array(
    0 => array('date' => true, 'from' => $tomorrowDate),
    1 => array('is' => new Zend_Db_Expr('null')))
    ), 'left');

foreach($_productCollection as $_product){
    if($_product->getData('special_price')!=null){
        echo '<img src="'.$this->helper('catalog/image')->init($_product, 'thumbnail')->resize(75).'" alt="'.$_product->getName().'" /><br />';
        echo $_product->getName().'<br />';

    $specialPrice = $_product->getData('special_price');
    $orignalPrice = $_product->getData('price');
        echo number_format($specialPrice, 2)."<br/>";
        echo number_format($orignalPrice, 2)."<br/>";                    
        echo '<a href="http://www.yourwebsite.com/magento/checkout/cart/add?product='.$_product->getId().'&qty;=1">Add To Cart</a><br />';
    }
}
?>

这个只是实现了基本功能,样式布局方面还需要修改。有什么问题欢迎一起探讨

正文完
 0