/
Configuration.php
157 lines (143 loc) · 5.75 KB
/
Configuration.php
1
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Mage
* @package Mage_Bundle
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Helper for fetching properties by product configurational item
*
* @category Mage
* @package Mage_Bundle
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Bundle_Helper_Catalog_Product_Configuration extends Mage_Core_Helper_Abstract implements Mage_Catalog_Helper_Product_Configuration_Interface
{
/**
* Get selection quantity
*
* @param Mage_Catalog_Model_Product $product
* @param int $selectionId
*
* @return float
*/
public function getSelectionQty($product, $selectionId)
{
$selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
if ($selectionQty) {
return $selectionQty->getValue();
}
return 0;
}
/**
* Obtain final price of selection in a bundle product
*
* @param Mage_Catalog_Model_Product_Configuration_Item_Interface $item
* @param Mage_Catalog_Model_Product $selectionProduct
* @return float
*/
public function getSelectionFinalPrice(
Mage_Catalog_Model_Product_Configuration_Item_Interface $item,
$selectionProduct
) {
$selectionProduct->unsetData('final_price');
return $item->getProduct()->getPriceModel()->getSelectionFinalTotalPrice(
$item->getProduct(),
$selectionProduct,
$item->getQty() * 1,
$this->getSelectionQty($item->getProduct(), $selectionProduct->getSelectionId()),
false,
true
);
}
/**
* Get bundled selections (slections-products collection)
*
* Returns array of options objects.
* Each option object will contain array of selections objects
*
* @param Mage_Catalog_Model_Product_Configuration_Item_Interface $item
* @return array
*/
public function getBundleOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item)
{
$options = array();
$product = $item->getProduct();
/** @var Mage_Bundle_Model_Product_Type $typeInstance */
$typeInstance = $product->getTypeInstance(true);
// get bundle options
$optionsQuoteItemOption = $item->getOptionByCode('bundle_option_ids');
$bundleOptionsIds = $optionsQuoteItemOption ? unserialize($optionsQuoteItemOption->getValue(), ['allowed_classes' => false]) : array();
if ($bundleOptionsIds) {
/**
* @var Mage_Bundle_Model_Resource_Option_Collection
*/
$optionsCollection = $typeInstance->getOptionsByIds($bundleOptionsIds, $product);
// get and add bundle selections collection
$selectionsQuoteItemOption = $item->getOptionByCode('bundle_selection_ids');
$bundleSelectionIds = unserialize($selectionsQuoteItemOption->getValue(), ['allowed_classes' => false]);
if (!empty($bundleSelectionIds)) {
$selectionsCollection = $typeInstance->getSelectionsByIds(
unserialize($selectionsQuoteItemOption->getValue(), ['allowed_classes' => false]),
$product
);
/** @var Mage_Bundle_Model_Option[] $bundleOptions */
$bundleOptions = $optionsCollection->appendSelections($selectionsCollection, true);
foreach ($bundleOptions as $bundleOption) {
if ($bundleOption->getSelections()) {
$option = array(
'label' => $bundleOption->getTitle(),
'value' => array()
);
$bundleSelections = $bundleOption->getSelections();
foreach ($bundleSelections as $bundleSelection) {
$qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
if ($qty) {
$option['value'][] = $qty . ' x ' . $this->escapeHtml($bundleSelection->getName())
. ' ' . Mage::helper('core')->currency(
$this->getSelectionFinalPrice($item, $bundleSelection)
);
}
}
if ($option['value']) {
$options[] = $option;
}
}
}
}
}
return $options;
}
/**
* Retrieves product options list
*
* @param Mage_Catalog_Model_Product_Configuration_Item_Interface $item
* @return array
*/
public function getOptions(Mage_Catalog_Model_Product_Configuration_Item_Interface $item)
{
return array_merge(
$this->getBundleOptions($item),
Mage::helper('catalog/product_configuration')->getCustomOptions($item)
);
}
}