1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: class Mage_Adminhtml_Helper_Sales extends Mage_Core_Helper_Abstract
28: {
29: /**
30: * Display price attribute value in base order currency and in place order currency
31: *
32: * @param Varien_Object $dataObject
33: * @param string $code
34: * @param bool $strong
35: * @param string $separator
36: * @return string
37: */
38: public function displayPriceAttribute($dataObject, $code, $strong = false, $separator = '<br/>')
39: {
40: return $this->displayPrices(
41: $dataObject,
42: $dataObject->getData('base_'.$code),
43: $dataObject->getData($code),
44: $strong,
45: $separator
46: );
47: }
48:
49: /**
50: * Get "double" prices html (block with base and place currency)
51: *
52: * @param Varien_Object $dataObject
53: * @param float $basePrice
54: * @param float $price
55: * @param bool $strong
56: * @param string $separator
57: * @return string
58: */
59: public function displayPrices($dataObject, $basePrice, $price, $strong = false, $separator = '<br/>')
60: {
61: $order = false;
62: if ($dataObject instanceof Mage_Sales_Model_Order) {
63: $order = $dataObject;
64: } else {
65: $order = $dataObject->getOrder();
66: }
67:
68: if ($order && $order->isCurrencyDifferent()) {
69: $res = '<strong>';
70: $res.= $order->formatBasePrice($basePrice);
71: $res.= '</strong>'.$separator;
72: $res.= '['.$order->formatPrice($price).']';
73: } elseif ($order) {
74: $res = $order->formatPrice($price);
75: if ($strong) {
76: $res = '<strong>'.$res.'</strong>';
77: }
78: } else {
79: $res = Mage::app()->getStore()->formatPrice($price);
80: if ($strong) {
81: $res = '<strong>'.$res.'</strong>';
82: }
83: }
84: return $res;
85: }
86:
87: /**
88: * Filter collection by removing not available product types
89: *
90: * @param Mage_Core_Model_Mysql4_Collection_Abstract $collection
91: * @return Mage_Core_Model_Mysql4_Collection_Abstract
92: */
93: public function applySalableProductTypesFilter($collection)
94: {
95: $productTypes = Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray();
96: $productTypes = array_keys($productTypes);
97: foreach($collection->getItems() as $key => $item) {
98: if ($item instanceof Mage_Catalog_Model_Product) {
99: $type = $item->getTypeId();
100: } else if ($item instanceof Mage_Sales_Model_Order_Item) {
101: $type = $item->getProductType();
102: } else if ($item instanceof Mage_Sales_Model_Quote_Item) {
103: $type = $item->getProductType();
104: } else {
105: $type = '';
106: }
107: if (!in_array($type, $productTypes)) {
108: $collection->removeItemByKey($key);
109: }
110: }
111: return $collection;
112: }
113: }
114: