1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Adminhtml_Block_Customer_Edit_Tab_Cart extends Mage_Adminhtml_Block_Widget_Grid
36: {
37: public function __construct($attributes=array())
38: {
39: parent::__construct($attributes);
40: $this->setUseAjax(true);
41: $this->_parentTemplate = $this->getTemplate();
42: $this->setTemplate('customer/tab/cart.phtml');
43: }
44:
45: 46: 47: 48: 49:
50: protected function _prepareGrid()
51: {
52: $this->setId('customer_cart_grid' . $this->getWebsiteId());
53: parent::_prepareGrid();
54: }
55:
56: protected function _prepareCollection()
57: {
58: $customer = Mage::registry('current_customer');
59: $storeIds = Mage::app()->getWebsite($this->getWebsiteId())->getStoreIds();
60:
61: $quote = Mage::getModel('sales/quote')
62: ->setSharedStoreIds($storeIds)
63: ->loadByCustomer($customer);
64:
65: if ($quote) {
66: $collection = $quote->getItemsCollection(false);
67: }
68: else {
69: $collection = new Varien_Data_Collection();
70: }
71:
72: $collection->addFieldToFilter('parent_item_id', array('null' => true));
73:
74: $this->setCollection($collection);
75:
76: return parent::_prepareCollection();
77: }
78:
79: protected function _prepareColumns()
80: {
81: $this->addColumn('product_id', array(
82: 'header' => Mage::helper('catalog')->__('Product ID'),
83: 'index' => 'product_id',
84: 'width' => '100px',
85: ));
86:
87: $this->addColumn('name', array(
88: 'header' => Mage::helper('catalog')->__('Product Name'),
89: 'index' => 'name',
90: 'renderer' => 'adminhtml/customer_edit_tab_view_grid_renderer_item'
91: ));
92:
93: $this->addColumn('sku', array(
94: 'header' => Mage::helper('catalog')->__('SKU'),
95: 'index' => 'sku',
96: 'width' => '100px',
97: ));
98:
99: $this->addColumn('qty', array(
100: 'header' => Mage::helper('catalog')->__('Qty'),
101: 'index' => 'qty',
102: 'type' => 'number',
103: 'width' => '60px',
104: ));
105:
106: $this->addColumn('price', array(
107: 'header' => Mage::helper('catalog')->__('Price'),
108: 'index' => 'price',
109: 'type' => 'currency',
110: 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
111: ));
112:
113: $this->addColumn('total', array(
114: 'header' => Mage::helper('sales')->__('Total'),
115: 'index' => 'row_total',
116: 'type' => 'currency',
117: 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
118: ));
119:
120: $this->addColumn('action', array(
121: 'header' => Mage::helper('customer')->__('Action'),
122: 'index' => 'quote_item_id',
123: 'renderer' => 'adminhtml/customer_grid_renderer_multiaction',
124: 'filter' => false,
125: 'sortable' => false,
126: 'actions' => array(
127: array(
128: 'caption' => Mage::helper('customer')->__('Configure'),
129: 'url' => 'javascript:void(0)',
130: 'process' => 'configurable',
131: 'control_object' => $this->getJsObjectName() . 'cartControl'
132: ),
133: array(
134: 'caption' => Mage::helper('customer')->__('Delete'),
135: 'url' => '#',
136: 'onclick' => 'return ' . $this->getJsObjectName() . 'cartControl.removeItem($item_id);'
137: )
138: )
139: ));
140:
141: return parent::_prepareColumns();
142: }
143:
144: 145: 146: 147: 148:
149: public function getCustomer() {
150: return Mage::registry('current_customer');
151: }
152:
153: public function getGridUrl()
154: {
155: return $this->getUrl('*/*/cart', array('_current'=>true, 'website_id' => $this->getWebsiteId()));
156: }
157:
158: public function getGridParentHtml()
159: {
160: $templateName = Mage::getDesign()->getTemplateFilename($this->_parentTemplate, array('_relative'=>true));
161: return $this->fetchView($templateName);
162: }
163:
164: public function getRowUrl($row)
165: {
166: return $this->getUrl('*/catalog_product/edit', array('id' => $row->getProductId()));
167: }
168: }
169: