00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Adminhtml_Block_Customer_Edit_Tab_Cart extends Mage_Adminhtml_Block_Widget_Grid
00036 {
00037
00038 public function __construct($attributes=array())
00039 {
00040 parent::__construct($attributes);
00041 $this->setId('customer_cart_grid'.$this->getWebsiteId());
00042 $this->setUseAjax(true);
00043 $this->_parentTemplate = $this->getTemplate();
00044 $this->setTemplate('customer/tab/cart.phtml');
00045 }
00046
00047 protected function _prepareCollection()
00048 {
00049 $customer = Mage::registry('current_customer');
00050 $storeIds = Mage::app()->getWebsite($this->getWebsiteId())->getStoreIds();
00051
00052 $quote = Mage::getModel('sales/quote')
00053 ->setSharedStoreIds($storeIds)
00054 ->loadByCustomer($customer);
00055
00056 if ($quote) {
00057 $collection = $quote->getItemsCollection(false);
00058 }
00059 else {
00060 $collection = new Varien_Data_Collection();
00061 }
00062
00063 $collection->addFieldToFilter('parent_item_id', array('null' => true));
00064
00065 $this->setCollection($collection);
00066
00067 return parent::_prepareCollection();
00068 }
00069
00070 protected function _prepareColumns()
00071 {
00072 $this->addColumn('product_id', array(
00073 'header' => Mage::helper('customer')->__('Product ID'),
00074 'index' => 'product_id',
00075 'width' => '100px',
00076 ));
00077
00078 $this->addColumn('name', array(
00079 'header' => Mage::helper('customer')->__('Product Name'),
00080 'index' => 'name',
00081 ));
00082
00083 $this->addColumn('sku', array(
00084 'header' => Mage::helper('customer')->__('SKU'),
00085 'index' => 'sku',
00086 'width' => '100px',
00087 ));
00088
00089 $this->addColumn('qty', array(
00090 'header' => Mage::helper('customer')->__('Qty'),
00091 'index' => 'qty',
00092 'type' => 'number',
00093 'width' => '60px',
00094 ));
00095
00096 $this->addColumn('price', array(
00097 'header' => Mage::helper('customer')->__('Price'),
00098 'index' => 'price',
00099 'type' => 'currency',
00100 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
00101 ));
00102
00103 $this->addColumn('total', array(
00104 'header' => Mage::helper('customer')->__('Total'),
00105 'index' => 'row_total',
00106 'type' => 'currency',
00107 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
00108 ));
00109
00110 $this->addColumn('action', array(
00111 'header' => Mage::helper('customer')->__('Action'),
00112 'index' => 'quote_item_id',
00113 'type' => 'action',
00114 'filter' => false,
00115 'sortable' => false,
00116 'actions' => array(
00117 array(
00118 'caption' => Mage::helper('customer')->__('Delete'),
00119 'url' => '#',
00120 'onclick' => 'return ' . $this->getJsObjectName() . 'cartControl.removeItem($item_id);'
00121 )
00122 )
00123 ));
00124
00125 return parent::_prepareColumns();
00126 }
00127
00128 public function getGridUrl()
00129 {
00130 return $this->getUrl('*/*/cart', array('_current'=>true, 'website_id' => $this->getWebsiteId()));
00131 }
00132
00133 public function getGridParentHtml()
00134 {
00135 $templateName = Mage::getDesign()->getTemplateFilename($this->_parentTemplate, array('_relative'=>true));
00136 return $this->fetchView($templateName);
00137 }
00138
00139 public function getRowUrl($row)
00140 {
00141 return $this->getUrl('*/catalog_product/edit', array('id' => $row->getProductId()));
00142 }
00143 }