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: /**
28: * Adminhtml block for fieldset of grouped product
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Catalog_Product_Composite_Fieldset_Grouped extends Mage_Catalog_Block_Product_View_Type_Grouped
35: {
36: /**
37: * Redefine default price block
38: * Set current customer to tax calculation
39: */
40: protected function _construct()
41: {
42: parent::_construct();
43:
44: $this->_block = 'adminhtml/catalog_product_price';
45: $this->_useLinkForAsLowAs = false;
46:
47: $taxCalculation = Mage::getSingleton('tax/calculation');
48: if (!$taxCalculation->getCustomer() && Mage::registry('current_customer')) {
49: $taxCalculation->setCustomer(Mage::registry('current_customer'));
50: }
51: }
52:
53: /**
54: * Retrieve product
55: *
56: * @return Mage_Catalog_Model_Product
57: */
58: public function getProduct()
59: {
60: if (!$this->hasData('product')) {
61: $this->setData('product', Mage::registry('product'));
62: }
63: $product = $this->getData('product');
64: if (is_null($product->getTypeInstance(true)->getStoreFilter($product))) {
65: $product->getTypeInstance(true)->setStoreFilter(Mage::app()->getStore($product->getStoreId()), $product);
66: }
67:
68: return $product;
69: }
70:
71: /**
72: * Retrieve array of associated products
73: *
74: * @return array
75: */
76: public function getAssociatedProducts()
77: {
78: $product = $this->getProduct();
79: $result = $product->getTypeInstance(true)
80: ->getAssociatedProducts($product);
81:
82: $storeId = $product->getStoreId();
83: foreach ($result as $item) {
84: $item->setStoreId($storeId);
85: }
86:
87: return $result;
88: }
89:
90:
91: /**
92: * Set preconfigured values to grouped associated products
93: *
94: * @return Mage_Catalog_Block_Product_View_Type_Grouped
95: */
96: public function setPreconfiguredValue() {
97: $configValues = $this->getProduct()->getPreconfiguredValues()->getSuperGroup();
98: if (is_array($configValues)) {
99: $associatedProducts = $this->getAssociatedProducts();
100: foreach ($associatedProducts as $item) {
101: if (isset($configValues[$item->getId()])) {
102: $item->setQty($configValues[$item->getId()]);
103: }
104: }
105: }
106: return $this;
107: }
108:
109: /**
110: * Check whether the price can be shown for the specified product
111: *
112: * @param Mage_Catalog_Model_Product $product
113: * @return bool
114: */
115: public function getCanShowProductPrice($product)
116: {
117: return true;
118: }
119:
120: /**
121: * Checks whether block is last fieldset in popup
122: *
123: * @return bool
124: */
125: public function getIsLastFieldset()
126: {
127: $isLast = $this->getData('is_last_fieldset');
128: if (!$isLast) {
129: $options = $this->getProduct()->getOptions();
130: return !$options || !count($options);
131: }
132: return $isLast;
133: }
134:
135: /**
136: * Returns price converted to current currency rate
137: *
138: * @param float $price
139: * @return float
140: */
141: public function getCurrencyPrice($price)
142: {
143: $store = $this->getProduct()->getStore();
144: return $this->helper('core')->currencyByStore($price, $store, false);
145: }
146: }
147: