· 8 years ago · May 30, 2018, 02:24 PM
1<?xml version="1.0"?>
2<config>
3<modules>
4 <Locker_Bundleoption>
5 <version>0.1.0</version>
6 </Locker_Bundleoption>
7</modules>
8<global>
9 <blocks>
10 <bundle>
11
12
13 <rewrite>
14 <adminhtml_catalog_product_edit_tab_bundle_option>Locker_Bundleoption_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option</adminhtml_catalog_product_edit_tab_bundle_option>
15 </rewrite>
16 </bundle>
17 </blocks>
18 <models>
19 <bundleoption>
20 <class>Locker_Bundleoption_Model</class>
21 <resourceModel>bundleoption_mysql4</resourceModel>
22 </bundleoption>
23 <bundleoption_mysql4>
24 <class>Locker_Bundleoption_Model_Mysql4</class>
25 <entities>
26 <bundleqty>
27 <table>catalog_product_bundle_option_bundleqty</table>
28 </bundleqty>
29 </entities>
30 </bundleoption_mysql4>
31 </models>
32 <resources>
33 <bundleoption_setup>
34 <setup>
35 <module>Locker_Bundleoption</module>
36 <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
37 </setup>
38 <connection>
39 <use>core_setup</use>
40 </connection>
41 </bundleoption_setup>
42 <bundleoption_write>
43 <connection>
44 <use>core_write</use>
45 </connection>
46 </bundleoption_write>
47 <bundleoption_read>
48 <connection>
49 <use>core_read</use>
50 </connection>
51 </bundleoption_read>
52 </resources>
53</global>
54<adminhtml>
55 <events>
56 <catalog_product_save_commit_after>
57 <observers>
58 <custom_field_observer>
59 <type>singleton</type>
60 <class>Locker_Bundleoption_Model_Observer</class>
61 <method>SaveDropdownAfterProductSave</method>
62 </custom_field_observer>
63 </observers>
64 </catalog_product_save_commit_after>
65 </events>
66</adminhtml>
67
68<?php
69class Locker_Bundleoption_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option extends Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Bundle_Option
70{
71public function getOptions()
72{
73 if (!$this->_options) {
74 $this->getProduct()->getTypeInstance(true)->setStoreFilter($this->getProduct()->getStoreId(),
75 $this->getProduct());
76
77 $optionCollection = $this->getProduct()->getTypeInstance(true)->getOptionsCollection($this->getProduct());
78
79 $selectionCollection = $this->getProduct()->getTypeInstance(true)->getSelectionsCollection(
80 $this->getProduct()->getTypeInstance(true)->getOptionsIds($this->getProduct()),
81 $this->getProduct()
82 );
83
84 $this->_options = $optionCollection->appendSelections($selectionCollection);
85 /*echo "<pre>";
86 print_r($this->_options); die;*/
87 $storeId = $this->getProduct()->getData('store_id');
88 foreach ($this->_options as $option) {
89 //gets each option's id
90 $option_id = $option->getData('option_id');
91 $optionFixed = Mage::getModel('bundleoption/bundleqty')->load($option_id, "option_id");
92 if ($optionFixed->getId() != "") {
93 $id = (int)$optionFixed->getId();
94 $bundleqty = $optionFixed->getBundleqty();
95 //adds our new datas to option
96 $option->addData(array('fixedbundle_id'=> $id, 'bundleqty' => $bundleqty, 'is_new'=> 'no'));
97 } else {
98 $option->addData(array('fixedbundle_id'=> '', 'bundleqty' => '', 'is_new'=> 'yes'));
99 }
100 }
101
102 if ($this->getCanReadPrice() === false) {
103 foreach ($this->_options as $option) {
104 if ($option->getSelections()) {
105 foreach ($option->getSelections() as $selection) {
106 $selection->setCanReadPrice($this->getCanReadPrice());
107 $selection->setCanEditPrice($this->getCanEditPrice());
108 }
109 }
110 }
111 }
112 }
113 return $this->_options;
114}
115
116}
117
118<?php //echo "string"; die;
119$installer=$this;
120$installer->startSetup();
121
122$installer->run("
123-- DROP TABLE IF EXISTS {$this->getTable('bundleoption/bundleqty')};
124CREATE TABLE {$this->getTable('bundleoption/bundleqty')} (
125 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
126 `store_id` int(11) NOT NULL default '0',
127 `option_id` int(11) NOT NULL,
128 `bundleqty` int(11) NOT NULL default '0',
129 PRIMARY KEY (`id`)
130) ENGINE=InnoDB DEFAULT CHARSET=utf8;
131
132");
133$installer->endSetup();
134
135<?php
136class Locker_Bundleoption_Model_Bundleqty extends Mage_Core_Model_Abstract {
137
138public function _construct()
139{
140 $this->_init('yourmodule/fixedbundle');
141}
142
143}
144
145<?php
146class Locker_Bundleoption_Model_Mysql4_Bundleqty extends Mage_Core_Model_Abstract {
147
148public function _construct()
149{
150 $this->_init('bundleoption/bundleqty', 'id');
151}
152
153}
154
155<?php
156class Locker_Bundleoption_Model_Mysql4_Bundleqty_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
157 protected function _construct(){
158 $this->_init('bundleoption/bundleqty');
159 }
160 }
161
162<?php
163
164class Locker_Bundleoption_Model_Observer extends Mage_Core_Model_Abstract
165{
166public function SaveDropdownAfterProductSave($observer)
167{
168 $product = Mage::registry('product');
169
170 if (Mage::registry('catalog_product_save_commit_after' . $product->getId())) {
171 return;
172 }
173
174 Mage::register('catalog_product_save_commit_after' . $product->getId(), true);
175 $model = Mage::getModel('bundleoption/bundleqty');
176 $optionCollection = $product->getTypeInstance(TRUE)->getOptionsCollection($product);
177 $bundleOptions = $product->getBundleOptionsData();
178 if (!empty($bundleOptions)) {
179 $storeId = (int)$product->getData('store_id');
180 foreach ($bundleOptions as $option) {
181 $optionId = (int)$option['option_id'];
182 $id = (int)$option['id'];
183 $isDeleted = (int)$option['delete'];
184 //use to set option_id for new options in our module
185 if ($optionId <= 0 || $optionId == "" || is_null($optionId)) {
186 foreach ($optionCollection as $new) {
187 if($new['type'] == $option['type'] && ( $new['title'] == $option['title'] || $new['default_title'] == $option['title'] )){
188 $optionId = $new['option_id'];
189 }
190 }
191 }
192 $data = array(
193 'option_id' => $optionId,
194 'store_id' => $storeId,
195 'bundleqty' => $option['bundleqty']
196 );
197 $optionFixed = Mage::getModel('bundleoption/bundleqty')->load($optionId, "option_id");
198 // id exist means already there is an entry in custom table
199 try {
200 if ($isDeleted == 1) {
201 $model->setId($id)->delete();
202 } else {
203 if ($optionFixed->getId() != ""){
204 $model->load($id);
205 $model->addData($data);
206 $model->setId($id)->save();
207 } else {
208 $model->setData($data);
209 $insertId = $model->save()->getId();
210 }
211 }
212 } catch (Exception $e) {
213 Mage::logException($e);
214 }
215 }
216 }
217 return $this;
218 }
219}
220
221<script type="text/javascript">
222optionTemplate = '<div id="<?php echo $this->getFieldId() ?>_{{index}}" class="option-box"> ' +
223'<input id="fixedbundle_id" type="hidden" name="<?php echo $this->getFieldName() ?>[{{index}}][id]" value="{{id}}" />'+
224'<input id="is_new" type="hidden" name="<?php echo $this->getFieldName() ?>[{{index}}][is_new]" value="{{is_new}}" />'+
225'<div class="option-title"> ' +
226'<label for="<?php echo $this->getFieldName() ?>[{{index}}][title]"><?php echo $this->jsQuoteEscape(Mage::helper('bundle')->__('Default Title')) ?> <span class="required">*</span></label>' +
227<?php if ($this->isDefaultStore()): ?>
228'<input class="input-text required-entry" type="text" name="<?php echo $this->getFieldName() ?>[{{index}}][title]" id="id_<?php echo $this->getFieldName() ?>_{{index}}_title" value="{{title}}">' +
229<?php else: ?>
230'<input class="input-text required-entry" type="text" name="<?php echo $this->getFieldName() ?>[{{index}}][default_title]" id="id_<?php echo $this->getFieldName() ?>_{{index}}_default_title" value="{{default_title}}">' +
231<?php endif; ?>
232'<?php echo $this->jsQuoteEscape($this->getOptionDeleteButtonHtml()) ?>' +
233'</div>' +
234 '<table class="option-header" cellpadding="0" cellspacing="0">' +
235 '<thead>' +
236 '<tr>' +
237 <?php if (!$this->isDefaultStore()): ?>
238 '<th class="opt-title"><?php echo $this->jsQuoteEscape(Mage::helper('bundle')->__('Store View Title')) ?> <span class="required">*</span></th>' +
239 <?php endif; ?>
240 '<th class="opt-type"><?php echo $this->jsQuoteEscape(Mage::helper('bundle')->__('Input Type')) ?></th>' +
241 '<th class="opt-req"><?php echo $this->jsQuoteEscape(Mage::helper('bundle')->__('Is Required')) ?></th>' +
242 '<th class="opt-order"><?php echo $this->jsQuoteEscape(Mage::helper('bundle')->__('Position')) ?></th>' +
243 '<th class="opt-order bundleqty-assigned"><?php echo Mage::helper('bundle')->__('Bundle Quantity') ?></th>' +
244 '<th> </th>' +
245 '</tr>' +
246 '</thead>' +
247 '<tbody>' +
248 '<tr>' +
249 '<input type="hidden" id="<?php echo $this->getFieldId() ?>_id_{{index}}" name="<?php echo $this->getFieldName() ?>[{{index}}][option_id]" value="{{option_id}}">' +
250 '<input type="hidden" name="<?php echo $this->getFieldName() ?>[{{index}}][delete]" value="" class="delete">' +
251 <?php if (!$this->isDefaultStore()): ?>
252 '<td><input class="input-text required-entry" type="text" name="<?php echo $this->getFieldName() ?>[{{index}}][title]" id="id_<?php echo $this->getFieldName() ?>_{{index}}_title_store" value="{{title}}"></td>' +
253 <?php endif; ?>
254 '<td><?php echo $this->getTypeSelectHtml() ?></td>' +
255 '<td><?php echo $this->getRequireSelectHtml() ?></td>' +
256 '<td><input class="input-text validate-zero-or-greater" type="text" name="<?php echo $this->getFieldName() ?>[{{index}}][position]" value="{{position}}"></td>' +
257 '<td class="bundleqty-assigned"><input class="input-text validate-zero-or-greater" type="text" name="<?php echo $this->getFieldName() ?>[{{index}}][bundleqty]" value="{{bundleqty}}"></td>' +
258 '<td> <?php echo $this->jsQuoteEscape($this->getAddSelectionButtonHtml()) ?></td>' +
259 '</tr>' +
260 '</tbody>' +
261'</table>' +
262'<div id="<?php echo $this->getFieldId() ?>_search_{{index}}">' +
263'</div>' +
264'</div>';
265</script>