[ Index ] |
PHP Cross Reference of osCMax 2.0.4 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 $Id: attributeManager.class.php,v 1.0 21/02/06 Sam West$ 4 5 osCommerce, Open Source E-Commerce Solutions 6 http://www.oscommerce.com 7 8 Released under the GNU General Public License 9 10 Copyright © 2006 Kangaroo Partners 11 http://kangaroopartners.com 12 [email protected] 13 */ 14 15 class attributeManagerAtomic extends attributeManager { 16 17 /** 18 * Holder for a reference to the session variable for storing temp data 19 * @access private 20 */ 21 var $arrSessionVar = array(); 22 23 /** 24 * __constrct - Assigns the session variable and calls the parent construct registers page actions 25 * @access public 26 * @author Sam West aka Nimmit - [email protected] 27 * @param $arrSessionVar array - passed by Ref 28 * @return void 29 */ 30 function attributeManagerAtomic(&$arrSessionVar) { 31 32 parent::attributeManager(); 33 $this->arrSessionVar = &$arrSessionVar; 34 35 $this->registerPageAction('addAttributeToProduct','addAttributeToProduct'); 36 $this->registerPageAction('addOptionValueToProduct','addOptionValueToProduct'); 37 $this->registerPageAction('addNewOptionValueToProduct','addNewOptionValueToProduct'); 38 $this->registerPageAction('removeOptionFromProduct','removeOptionFromProduct'); 39 $this->registerPageAction('removeOptionValueFromProduct','removeOptionValueFromProduct'); 40 // QT Pro Plugin 41 $this->registerPageAction('RemoveStockOptionValueFromProduct','RemoveStockOptionValueFromProduct'); 42 $this->registerPageAction('AddStockToProduct','AddStockToProduct'); 43 // QT Pro Plugin 44 $this->registerPageAction('update','update'); 45 $this->registerPageAction('updateProductStockQuantity','updateProductStockQuantity'); 46 if(AM_USE_SORT_ORDER) { 47 $this->registerPageAction('moveOption','moveOption'); 48 $this->registerPageAction('moveOptionDown','moveOptionDown'); 49 $this->registerPageAction('moveOptionValue','moveOptionValue'); 50 $this->registerPageAction('moveOptionValueDown','moveOptionValueDown'); 51 } 52 53 } 54 55 //----------------------------------------------- page actions 56 57 /** 58 * Adds the selected attribute to the current product 59 * @access public 60 * @author Sam West aka Nimmit - [email protected] 61 * @param $get $_GET 62 * @return void 63 */ 64 function addAttributeToProduct($get) { 65 if(isset($get['option_id']) === true) { 66 $this->getAndPrepare('option_id', $get, $getArray['option_id']); 67 } 68 69 if(isset($get['option_value_id']) === true) { 70 $this->getAndPrepare('option_value_id', $get, $getArray['option_value_id']); 71 } 72 73 if(isset($get['price']) === true) { 74 $this->getAndPrepare('price', $get, $getArray['price']); 75 } 76 77 78 if(isset($get['prefix']) === true) { 79 $this->getAndPrepare('prefix', $get, $getArray['prefix']); 80 } 81 82 if(isset($get['sortOrder']) === true ) { 83 $this->getAndPrepare('sortOrder', $get, $getArray['sortOrder']); 84 } else { 85 $getArray['sortOrder'] = -1; 86 } 87 88 // 89 90 if((empty($getArray['price']))||($getArray['price']=='0')){ 91 $getArray['price']='0.0000'; 92 }else{ 93 if((empty($getArray['prefix']))||($getArray['prefix']==' ')){ 94 $getArray['prefix']='+'; 95 } 96 } 97 98 if(empty($getArray['prefix'])){ 99 $getArray['prefix']=' '; 100 } 101 102 $getArray['price']=sprintf("%01.4f", $getArray['price']); 103 104 // echo '<br><br>Array arrSessionVar:: <br><br>'; 105 // print_r($getArray); 106 107 // changes by mytool 108 // get highest sort order value 109 110 if (AM_USE_SORT_ORDER && $getArray['sortOrder'] == -1) { 111 $insertIndex = -1; 112 113 $result = $this->getSortedProductAttributes(); 114 115 // search for the current Sort Order where the new value needs to be added 116 $i = -1; 117 while ( list($key, $val) = each($result) ) { 118 $i++; 119 if( $key == $getArray['option_id'] ){ 120 $insertIndex = $key; 121 } 122 } 123 124 // if InsertIndex is still -1 then this is a new option and will be added at the end 125 if($insertIndex > -1){ 126 127 $last = end( $result[$insertIndex]['values'] ) ; 128 $getArray['sortOrder'] = (int)$last['sortOrder'] + 1; 129 } else { 130 $lastrow = end( $result ) ; 131 $last = $lastrow['values']; 132 $lastv = end( $last ) ; 133 $getArray['sortOrder'] = (int)$lastv['sortOrder'] + 1; 134 } 135 // EO mytool 136 } 137 138 $this->arrSessionVar[] = $getArray; 139 140 } 141 142 143 /** 144 * Adds an existing option value to a product 145 * @see addAttributeToProduct() 146 * @access public 147 * @author Sam West aka Nimmit - [email protected] 148 * @param $get $_GET 149 * @return void 150 */ 151 function addOptionValueToProduct($get) { 152 $this->addAttributeToProduct($get); 153 } 154 155 /** 156 * Adds a new option value to the session then to the product 157 * @access public 158 * @author Sam West aka Nimmit - [email protected] 159 * @param $get $_GET 160 * @return void 161 */ 162 function addNewOptionValueToProduct($get) { 163 $returnInfo = $this->addOptionValue($get); 164 $get['option_value_id'] = $returnInfo['selectedOptionValue']; 165 $this->addAttributeToProduct($get); 166 return false; 167 } 168 169 /** 170 * Removes a specific option and its option values from the current product 171 * @access public 172 * @author Sam West aka Nimmit - [email protected] 173 * @param $get $_GET 174 * @return void 175 */ 176 function removeOptionFromProduct($get) { 177 $this->getAndPrepare('option_id',$get,$optionId); 178 foreach($this->arrSessionVar as $id => $res) 179 if(($res['option_id'] == $optionId)) 180 unset($this->arrSessionVar[$id]); 181 } 182 183 /** 184 * Removes a specific option value from a the current product 185 * @access public 186 * @author Sam West aka Nimmit - [email protected] 187 * @param $get $_GET 188 * @return void 189 */ 190 function removeOptionValueFromProduct($get) { 191 192 $this->getAndPrepare('option_id',$get,$optionId); 193 $this->getAndPrepare('option_value_id',$get,$optionValueId); 194 195 foreach($this->arrSessionVar as $id => $res) { 196 if(($res['option_id'] == $optionId) && ($res['option_value_id'] == $optionValueId)){ 197 unset($this->arrSessionVar[$id]); 198 } 199 } 200 } 201 // QT pro 202 /** 203 * Updates the quantity on the products stock table 204 * @access public 205 * @author Phocea 206 * @param $get $_GET 207 * @return void 208 */ 209 function AddStockToProduct($get) { 210 customprompt(); 211 $this->getAndPrepare('stockQuantity',$get,$stockQuantity); 212 //$this->getAndPrepare('option_id', $get, $optionId); 213 //$this->getAndPrepare('option_value_id', $get, $optionValueId); 214 //$this->getAndPrepare('price', $get, $price); 215 //$this->getAndPrepare('prefix', $get, $prefix); 216 //$this->getAndPrepare('sortOrder', $get, $sortOrder); 217 218 $this->arrSessionVar[] = array( 219 'product_stock_quantity' => $productStockQuantity 220 ); 221 222 } 223 224 // QT pro 225 226 /** 227 * Updates the price and prefix in the products attribute table 228 * @access public 229 * @author Sam West aka Nimmit - [email protected] 230 * @param $get $_GET 231 * @return void 232 */ 233 function update($get) { 234 if(isset($get['option_id']) === true) { 235 $this->getAndPrepare('option_id', $get, $getArray['option_id']); 236 } 237 238 if(isset($get['option_value_id']) === true) { 239 $this->getAndPrepare('option_value_id', $get, $getArray['option_value_id']); 240 } 241 242 if(isset($get['price']) === true) { 243 $this->getAndPrepare('price', $get, $getArray['price']); 244 } 245 246 if(isset($get['prefix']) === true) { 247 $this->getAndPrepare('prefix', $get, $getArray['prefix']); 248 } 249 250 if(isset($get['sortOrder']) === true) { 251 $this->getAndPrepare('sortOrder', $get, $getArray['sortOrder']); 252 } 253 254 // 255 if((empty($getArray['price']))||($getArray['price']=='0')){ 256 $getArray['price']='0.0000'; 257 }else{ 258 if((empty($getArray['prefix']))||($getArray['prefix']==' ')){ 259 $getArray['prefix']='+'; 260 } 261 } 262 263 $getArray['price']=sprintf("%01.4f", $getArray['price']); 264 265 foreach($this->arrSessionVar as $id => $res) { 266 if(($res['option_id'] == $getArray['option_id']) && ($res['option_value_id'] == $getArray['option_value_id'])) { 267 $debug.=$id."enter\r\n"; 268 $this->arrSessionVar[$id]['price'] = $getArray['price']; 269 $this->arrSessionVar[$id]['prefix'] = $getArray['prefix']; 270 if (AM_USE_SORT_ORDER) { 271 $this->arrSessionVar[$id][AM_FIELD_OPTION_VALUE_SORT_ORDER] = $getArray['sortOrder']; 272 } 273 } 274 } 275 276 } 277 278 //----------------------------------------------- page actions end 279 280 /** 281 * Returns all of the products options and values in the session 282 * @access public 283 * @author Sam West aka Nimmit - [email protected] 284 * @return array 285 */ 286 function getAllProductOptionsAndValues($reset = false) { 287 if(0 === count($this->arrAllProductOptionsAndValues) || true === $reset) { 288 $this->arrAllProductOptionsAndValues = array(); 289 $allOptionsAndValues = $this->getAllOptionsAndValues(); 290 291 // Sort Option Names ABC 292 for($z1=0;$z1<count($this->arrSessionVar);$z1++){ 293 $fch=false; 294 $last_z2=-1; 295 foreach($this->arrSessionVar as $z2 => $values){ 296 if($last_z2>-1){ 297 if(strcmp($allOptionsAndValues[$this->arrSessionVar[$last_z2]['option_id']]['name'],$allOptionsAndValues[$this->arrSessionVar[$z2]['option_id']]['name'])>0){ 298 $tempArr=$this->arrSessionVar[$last_z2]; 299 $this->arrSessionVar[$last_z2]=$this->arrSessionVar[$z2]; 300 $this->arrSessionVar[$z2]=$tempArr; 301 $fch=true; 302 } 303 } 304 $last_z2=$z2; 305 } 306 if(!$fch){ 307 break; 308 } 309 } 310 311 $optionsId = null; 312 foreach($this->arrSessionVar as $id => $res) { 313 314 if($res['option_id'] != $optionsId) { 315 $optionsId = $res['option_id']; 316 $this->arrAllProductOptionsAndValues[$optionsId]['name'] = $allOptionsAndValues[$optionsId]['name']; 317 } 318 $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['option_value_id']]['name'] = $allOptionsAndValues[$optionsId]['values'][$res['option_value_id']]; 319 $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['option_value_id']]['price'] = $res['price']; 320 $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['option_value_id']]['prefix'] = $res['prefix']; 321 if (AM_USE_SORT_ORDER) { 322 $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['option_value_id']]['sortOrder'] = $res['sortOrder']; 323 } 324 } 325 326 if (AM_USE_SORT_ORDER) { 327 $this->sortProductAttributes(); 328 } 329 } 330 return $this->arrAllProductOptionsAndValues; 331 } 332 333 function getSortedProductAttributes(){ 334 return $this->getAllProductOptionsAndValues(true); 335 } 336 337 338 function sortArrSessionVar(){ 339 340 if( count($this->arrSessionVar)){ 341 342 $sortArray = $this->arrSessionVar; 343 344 foreach ( $sortArray as $id => $res) { 345 $newSortArray[$res['sortOrder']] = $res; 346 } 347 348 ksort($newSortArray, SORT_NUMERIC); 349 350 $sortArray=$newSortArray; 351 352 $this->arrSessionVar = $newSortArray; 353 354 return $sortArray; 355 } else{ 356 return $this->arrSessionVar; 357 } 358 } 359 360 361 362 function sortProductAttributes(){ 363 364 $arrAllProductOptionsAndValues = $this->arrAllProductOptionsAndValues; 365 366 $sortedArray = array(); 367 368 $sorter = -1; 369 // reformat the $arrAllProductOptionsAndValues 370 while( list($key, $currentOption) = each($arrAllProductOptionsAndValues) ){ 371 while( list($currentOptionValuekey, $currentOptionValues) = each($currentOption['values']) ){ 372 $sorter++; 373 374 $sortorder = $currentOptionValues['sortOrder']; 375 // just to make shure there is a value in there 376 if(! ($sortorder > -1) )$sortorder=$sorter; 377 $sortedArray[$sortorder] = array( 'optionValue-id' => $currentOptionValuekey, 378 'optionValue-name' => $currentOptionValues['name'], 379 'optionValue-price' => $currentOptionValues['price'], 380 'optionValue-prefix' => $currentOptionValues['prefix'], 381 'optionValue-sortorder' => $sortorder, 382 'option-key' => $key, 383 'option-name' => $currentOption['name'] 384 ); 385 } 386 } 387 388 // now sort by key, because that contains the sortorder 389 ksort($sortedArray, SORT_NUMERIC); 390 391 reset($sortedArray); 392 393 $lastOption = current($sortedArray); 394 395 $optionValues = array(); 396 $finalSortedArray = array(); 397 398 // now rebuild the $arrAllProductOptionsAndValues 399 while( list($key, $currentOption) = each($sortedArray) ){ 400 if( $lastOption['option-key'] != $currentOption['option-key']){ 401 $lastOption = $currentOption; 402 $optionValues = array(); 403 } 404 $optionValues[$currentOption['optionValue-id']] = array( 405 'name' => $currentOption['optionValue-name'], 406 'price' => $currentOption['optionValue-price'], 407 'prefix' => $currentOption['optionValue-prefix'], 408 'sortOrder' => $currentOption['optionValue-sortorder'] 409 ); 410 $finalSortedArray[ $currentOption['option-key'] ] = array( 'name' => $currentOption['option-name'], 411 'values' => $optionValues ) ; 412 } 413 414 $this->arrAllProductOptionsAndValues = $finalSortedArray; 415 //return $finalSortedArray; 416 } 417 } 418 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 1 13:43:16 2010 | Cross-referenced by PHPXref 0.7 |