A-A+

magento前台显示最新订单下的产品信息及订单信息插件

2012年08月24日 灵犀一指 magento前台显示最新订单下的产品信息及订单信息插件已关闭评论 阅读 1,051 人 次

Magento可以实现在前台显示最新下订单信息,有插件下载。

效果如下:


block

[php]
<?php
class Brandintheeast_ViewOrder_Block_View extends Mage_Core_Block_Template {

public function __construct(){
parent::__construct ();
$showOrdersNum=mage::getStoreConfig("vieworder/viewordermes/show_order_count");
$orders = Mage::getResourceModel ( 'sales/order_collection' )
->addAttributeToFilter ( 'state', array ('in' => Mage::getSingleton ( 'sales/order_config' )
->getVisibleOnFrontStates () ) )
->addAttributeToSort ( 'created_at', 'desc' )
->setpage(1,$showOrdersNum);
$this->setOrders ($orders);
}

public function getItems() {
$items = array ();
$order = $this->getLastOrder ();
$limit = 5;

if ($order) {
$website = Mage::app ()->getStore ()->getWebsiteId ();
foreach ( $order->getParentItemsRandomCollection ( $limit ) as $item ) {
if ($item->getProduct () && in_array ( $website, $item->getProduct ()->getWebsiteIds () )) {
$items [] = $item;
}
}
}

return $items;
}

public function getOrdersOneProduct($order){
$items=array();
if($order){
$website = Mage::app ()->getStore ()->getWebsiteId ();
$showProductNum=mage::getStoreConfig("vieworder/viewordermes/show_product_count");
foreach ($order->getParentItemsRandomCollection($showProductNum) as $item){
if($item->getProduct()&& in_array($website,$item->getProduct()->getWebsiteids())){
if($this->isItemAvailableForReorder($item)){
$items[]=$item;
}
}
}
}
return $items;
}

public function getProductImgUrl($item,$size){
$product = Mage::getModel('catalog/product')->load($item->getProductId());
return $this->helper('catalog/image')->init($product, 'image')->resize($size);
}

public function isItemAvailableForReorder(Mage_Sales_Model_Order_Item $orderItem)
{
if ($orderItem->getProduct()) {
return $orderItem->getProduct()->getStockItem()->getIsInStock();
}
return false;
}

public function getLastOrder() {
foreach ( $this->getOrders () as $order ) {
return $order;
}
return false;
}

}
[/php]

config.xml

[php]
<?xml version="1.0"?>
<config>
<modules>
<Brandintheeast_ViewOrder>
<version>0.1.0</version>
</Brandintheeast_ViewOrder>
</modules>

<frontend>

<layout>
<updates>
<brandintheeast_vieworder>
<file>brandintheeast_vieworder.xml</file>
</brandintheeast_vieworder>
</updates>
</layout>
</frontend>
<global>
<models>
<vieworder>
<class>Brandintheeast_ViewOrder_Model</class>
</vieworder>
</models>
<blocks>
<vieworder>
<class>Brandintheeast_ViewOrder_Block</class>
</vieworder>
</blocks>
<helpers>
<vieworder>
<class>Brandintheeast_ViewOrder_Helper</class>
</vieworder>
</helpers>
</global>
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<vieworder>
<title>vieworder</title>
</vieworder>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<default>
<vieworder>
<viewordermes><show_order_count>4</show_order_count><show_product_count>1</show_product_count></viewordermes>
</vieworder>
</default>
</config>
[/php]

模板

[php]
<div class="block block-vieworder">
<div class="block-title">
<strong><span><?php echo $this->__('Recent Orders') ?></span></strong>
</div>
<ul class="block-content">
<?php foreach ($this->getOrders() as $order): ?>

<?php $items=$this->getOrdersOneProduct($order);
foreach ($items as $item){

$product = Mage::getModel('catalog/product')->load($item->getProductId());
//$imgUrl=$this->getProductImgUrl($item,70);
?>
<li>
<a href="<?php echo $item->getProduct()->getProductUrl() ?>"><?php echo $this->htmlEscape($item->getName()) ?></a>
<p><?php echo "ship to ".$order->getCustomerName();echo ",".$order->getShippingAddress()->getCity();?></p>
</li>
<?php }?>
<?php endforeach; ?>
</ul>
</div>
[/php]

标签:

评论已关闭!