| Total Complexity | 103 |
| Total Lines | 668 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Attributes often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Attributes, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 54 | class Attributes extends OledrionObject |
||
| 55 | { |
||
| 56 | /** |
||
| 57 | * constructor |
||
| 58 | * |
||
| 59 | * normally, this is called from child classes only |
||
| 60 | */ |
||
| 61 | public function __construct() |
||
| 62 | { |
||
| 63 | $this->initVar('attribute_id', XOBJ_DTYPE_INT, null, false); |
||
|
|
|||
| 64 | $this->initVar('attribute_weight', XOBJ_DTYPE_INT, null, false); |
||
| 65 | $this->initVar('attribute_title', XOBJ_DTYPE_TXTBOX, null, false); |
||
| 66 | $this->initVar('attribute_name', XOBJ_DTYPE_TXTBOX, null, false); |
||
| 67 | $this->initVar('attribute_type', XOBJ_DTYPE_INT, null, false); |
||
| 68 | $this->initVar('attribute_mandatory', XOBJ_DTYPE_INT, null, false); |
||
| 69 | $this->initVar('attribute_names', XOBJ_DTYPE_OTHER, null, false); |
||
| 70 | $this->initVar('attribute_values', XOBJ_DTYPE_OTHER, null, false); |
||
| 71 | $this->initVar('attribute_prices', XOBJ_DTYPE_OTHER, null, false); |
||
| 72 | $this->initVar('attribute_stocks', XOBJ_DTYPE_OTHER, null, false); |
||
| 73 | $this->initVar('attribute_product_id', XOBJ_DTYPE_INT, null, false); |
||
| 74 | $this->initVar('attribute_default_value', XOBJ_DTYPE_TXTBOX, null, false); |
||
| 75 | $this->initVar('attribute_option1', XOBJ_DTYPE_INT, null, false); |
||
| 76 | $this->initVar('attribute_option2', XOBJ_DTYPE_INT, null, false); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Indique si l'attribut courant a une valeur par défaut |
||
| 81 | * |
||
| 82 | * @return bool |
||
| 83 | * @since 2.3.2009.03.20 |
||
| 84 | */ |
||
| 85 | public function hasDefaultValue() |
||
| 86 | { |
||
| 87 | return '' !== xoops_trim($this->getVar('attribute_default_value')); |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Retourne le nom du champs tel qu'il est construit dans le formulaire sur la fiche produit |
||
| 92 | * |
||
| 93 | * @return string |
||
| 94 | */ |
||
| 95 | public function getAttributeNameInForm() |
||
| 96 | { |
||
| 97 | return $this->getVar('attribute_name') . '_' . $this->getVar('attribute_id'); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Retourne une option de l'attribut |
||
| 102 | * |
||
| 103 | * @param string $valueToGet |
||
| 104 | * @param string $format |
||
| 105 | * @return array |
||
| 106 | * @since 2.3.2009.03.11 |
||
| 107 | */ |
||
| 108 | public function getOption($valueToGet, $format = 'e') |
||
| 109 | { |
||
| 110 | $names = []; |
||
| 111 | if ('' !== xoops_trim($this->getVar($valueToGet, $format))) { |
||
| 112 | $names = explode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $this->getVar($valueToGet, $format)); |
||
| 113 | } |
||
| 114 | |||
| 115 | return $names; |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Retourne le nombre d'options de l'attribut courant |
||
| 120 | * |
||
| 121 | * @return int |
||
| 122 | * @since 2.3.2009.03.12 |
||
| 123 | */ |
||
| 124 | public function getOptionsCount() |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Ajout d'une option à l'attribut (soit une option vide soit une option valorisée) |
||
| 131 | * |
||
| 132 | * @param string $name |
||
| 133 | * @param string $value |
||
| 134 | * @param string $price |
||
| 135 | * @param string $stock |
||
| 136 | * @return bool |
||
| 137 | * @since 2.3.2009.03.16 |
||
| 138 | */ |
||
| 139 | private function appendOption($name, $value, $price = '', $stock = '') |
||
| 140 | { |
||
| 141 | $names = $values = $prices = $stocks = []; |
||
| 142 | $format = 'e'; |
||
| 143 | $names = $this->getOption('attribute_names', $format); |
||
| 144 | $values = $this->getOption('attribute_values', $format); |
||
| 145 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 146 | $prices = $this->getOption('attribute_prices', $format); |
||
| 147 | } |
||
| 148 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 149 | $stocks = $this->getOption('attribute_stocks', $format); |
||
| 150 | } |
||
| 151 | $names[] = $name; |
||
| 152 | $values[] = $value; |
||
| 153 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 154 | $prices[] = $price; |
||
| 155 | } |
||
| 156 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 157 | $stocks[] = $stock; |
||
| 158 | } |
||
| 159 | $this->setVar('attribute_names', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $names)); |
||
| 160 | $this->setVar('attribute_values', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $values)); |
||
| 161 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 162 | $this->setVar('attribute_prices', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $prices)); |
||
| 163 | } |
||
| 164 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 165 | $this->setVar('attribute_stocks', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $stocks)); |
||
| 166 | } |
||
| 167 | |||
| 168 | return true; |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Ajoute une option vide à la fin (avec des valeurs par défaut) |
||
| 173 | * |
||
| 174 | * @return bool |
||
| 175 | * @since 2.3.2009.03.12 |
||
| 176 | */ |
||
| 177 | public function addEmptyOption() |
||
| 178 | { |
||
| 179 | return $this->appendOption(_AM_OLEDRION_ATTRIBUTE_DEF_VALUE, _AM_OLEDRION_ATTRIBUTE_DEF_VALUE, _AM_OLEDRION_ATTRIBUTE_DEF_AMOUNT, _AM_OLEDRION_ATTRIBUTE_DEF_AMOUNT); |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Ajoute une nouvelle option à l'attribut |
||
| 184 | * |
||
| 185 | * @param string $name |
||
| 186 | * @param string $value |
||
| 187 | * @param string $price |
||
| 188 | * @param string $stock |
||
| 189 | * @return bool |
||
| 190 | * @since 2.3.2009.03.16 |
||
| 191 | */ |
||
| 192 | public function addOption($name, $value, $price = '', $stock = '') |
||
| 193 | { |
||
| 194 | return $this->appendOption($name, $value, $price, $stock); |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Réinitialisation des options de l'attribut |
||
| 199 | * |
||
| 200 | * @return bool True |
||
| 201 | * @since 2.3.2009.03.10 |
||
| 202 | */ |
||
| 203 | public function resetOptions() |
||
| 204 | { |
||
| 205 | $this->setVar('attribute_names', Constants::OLEDRION_EMPTY_OPTION); |
||
| 206 | $this->setVar('attribute_values', Constants::OLEDRION_EMPTY_OPTION); |
||
| 207 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 208 | $this->setVar('attribute_prices', Constants::OLEDRION_EMPTY_OPTION); |
||
| 209 | } |
||
| 210 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 211 | $this->setVar('attribute_stocks', Constants::OLEDRION_EMPTY_OPTION); |
||
| 212 | } |
||
| 213 | |||
| 214 | return true; |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Renseigne une option |
||
| 219 | * |
||
| 220 | * @param int $optionNumber (de 0 à N) |
||
| 221 | * @param string $name Valeur pour name |
||
| 222 | * @param string $value Valeur pour value |
||
| 223 | * @param string $price Valeur pour prix |
||
| 224 | * @param string $stock Valeur pour stock |
||
| 225 | * @return bool True si la mise à jour s'est faite sinon false |
||
| 226 | * @since 2.3.2009.03.10 |
||
| 227 | */ |
||
| 228 | public function setOptionValue($optionNumber, $name, $value, $price = '', $stock = '') |
||
| 229 | { |
||
| 230 | $optionNumber = (int)$optionNumber; |
||
| 231 | if ($optionNumber < 0 || $optionNumber > $this->getOptionsCount()) { |
||
| 232 | return false; |
||
| 233 | } |
||
| 234 | $names = $values = $prices = $stocks = []; |
||
| 235 | $format = 'e'; |
||
| 236 | $names[] = $this->getOption('attribute_names', $format); |
||
| 237 | $values = $this->getOption('attribute_values', $format); |
||
| 238 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 239 | $prices = $this->getOption('attribute_prices', $format); |
||
| 240 | } |
||
| 241 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 242 | $stocks = $this->getOption('attribute_stocks', $format); |
||
| 243 | } |
||
| 244 | if (isset($names[$optionNumber])) { |
||
| 245 | $names[$optionNumber] = $name; |
||
| 246 | } |
||
| 247 | if (isset($values[$optionNumber])) { |
||
| 248 | $values[$optionNumber] = $value; |
||
| 249 | } |
||
| 250 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 251 | if (isset($prices[$optionNumber])) { |
||
| 252 | $prices[$optionNumber] = $price; |
||
| 253 | } |
||
| 254 | } |
||
| 255 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 256 | if (isset($stocks[$optionNumber])) { |
||
| 257 | $stocks[$optionNumber] = $stock; |
||
| 258 | } |
||
| 259 | } |
||
| 260 | $this->setVar('attribute_names', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $names)); |
||
| 261 | $this->setVar('attribute_values', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $values)); |
||
| 262 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 263 | $this->setVar('attribute_prices', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $prices)); |
||
| 264 | } |
||
| 265 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 266 | $this->setVar('attribute_stocks', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $stocks)); |
||
| 267 | } |
||
| 268 | |||
| 269 | return true; |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Echange deux contenus dans un tableau |
||
| 274 | * |
||
| 275 | * @param array $array |
||
| 276 | * @param int $from |
||
| 277 | * @param int $to |
||
| 278 | * @since 2.3.2009.03.10 |
||
| 279 | */ |
||
| 280 | private function swapValues(&$array, $from, $to) |
||
| 281 | { |
||
| 282 | $tempValue = $array[$to]; |
||
| 283 | $array[$to] = $array[$from]; |
||
| 284 | $array[$from] = $tempValue; |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Fonction interne chargée du déplacement d'une option soit vers le haut soit vers le bas |
||
| 289 | * |
||
| 290 | * @param int $optionNumber |
||
| 291 | * @param int $upDown 1=Up, 2=Down |
||
| 292 | * @return bool |
||
| 293 | * @since 2.3.2009.03.10 |
||
| 294 | */ |
||
| 295 | private function moveOption($optionNumber, $upDown) |
||
| 296 | { |
||
| 297 | $prices = $stocks = []; |
||
| 298 | $optionNumber = (int)$optionNumber; |
||
| 299 | if (1 === $upDown) { |
||
| 300 | // Up |
||
| 301 | $newPosition = $optionNumber - 1; |
||
| 302 | } else { |
||
| 303 | // Down |
||
| 304 | $newPosition = $optionNumber + 1; |
||
| 305 | } |
||
| 306 | if ($optionNumber < 0 || $optionNumber > $this->getOptionsCount()) { |
||
| 307 | return false; |
||
| 308 | } |
||
| 309 | $format = 'e'; |
||
| 310 | $names = $this->getOption('attribute_names', $format); |
||
| 311 | $values = $this->getOption('attribute_values', $format); |
||
| 312 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 313 | $prices = $this->getOption('attribute_prices', $format); |
||
| 314 | } |
||
| 315 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 316 | $stocks = $this->getOption('attribute_stocks', $format); |
||
| 317 | } |
||
| 318 | if (isset($names[$optionNumber])) { |
||
| 319 | $this->swapValues($names, $optionNumber, $newPosition); |
||
| 320 | } |
||
| 321 | if (isset($values[$optionNumber])) { |
||
| 322 | $this->swapValues($values, $optionNumber, $newPosition); |
||
| 323 | } |
||
| 324 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 325 | if (isset($prices[$optionNumber])) { |
||
| 326 | $this->swapValues($prices, $optionNumber, $newPosition); |
||
| 327 | } |
||
| 328 | } |
||
| 329 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 330 | if (isset($stocks[$optionNumber])) { |
||
| 331 | $this->swapValues($stocks, $optionNumber, $newPosition); |
||
| 332 | } |
||
| 333 | } |
||
| 334 | $this->setVar('attribute_names', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $names)); |
||
| 335 | $this->setVar('attribute_values', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $values)); |
||
| 336 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 337 | $this->setVar('attribute_prices', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $prices)); |
||
| 338 | } |
||
| 339 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 340 | $this->setVar('attribute_stocks', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $stocks)); |
||
| 341 | } |
||
| 342 | |||
| 343 | return true; |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Déplace une option vers le haut |
||
| 348 | * |
||
| 349 | * @param int $optionNumber |
||
| 350 | * @return bool |
||
| 351 | * @since 2.3.2009.03.10 |
||
| 352 | */ |
||
| 353 | public function moveOptionUp($optionNumber) |
||
| 354 | { |
||
| 355 | return $this->moveOption($optionNumber, 1); |
||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Déplace une option vers le bas |
||
| 360 | * |
||
| 361 | * @param int $optionNumber |
||
| 362 | * @return bool |
||
| 363 | * @since 2.3.2009.03.10 |
||
| 364 | */ |
||
| 365 | public function moveOptionDown($optionNumber) |
||
| 366 | { |
||
| 367 | return $this->moveOption($optionNumber, 2); |
||
| 368 | } |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Supprime une option de l'attribut |
||
| 372 | * |
||
| 373 | * @param int $optionNumber (de 0 à n) |
||
| 374 | * @return bool false si l'indice est hors borne sinon true |
||
| 375 | * @since 2.3.2009.03.12 |
||
| 376 | */ |
||
| 377 | public function deleteOption($optionNumber) |
||
| 378 | { |
||
| 379 | $optionNumber = (int)$optionNumber; |
||
| 380 | if ($optionNumber < 0 || $optionNumber > $this->getOptionsCount()) { |
||
| 381 | return false; |
||
| 382 | } |
||
| 383 | $format = 'e'; |
||
| 384 | $names = $this->getOption('attribute_names', $format); |
||
| 385 | $values = $this->getOption('attribute_values', $format); |
||
| 386 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 387 | $prices = $this->getOption('attribute_prices', $format); |
||
| 388 | } |
||
| 389 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 390 | $stocks = $this->getOption('attribute_stocks', $format); |
||
| 391 | } |
||
| 392 | if (isset($names[$optionNumber])) { |
||
| 393 | unset($names[$optionNumber]); |
||
| 394 | } |
||
| 395 | if (isset($values[$optionNumber])) { |
||
| 396 | unset($values[$optionNumber]); |
||
| 397 | } |
||
| 398 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 399 | if (isset($prices[$optionNumber])) { |
||
| 400 | unset($prices[$optionNumber]); |
||
| 401 | } |
||
| 402 | } |
||
| 403 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 404 | if (isset($stocks[$optionNumber])) { |
||
| 405 | unset($stocks[$optionNumber]); |
||
| 406 | } |
||
| 407 | } |
||
| 408 | $this->setVar('attribute_names', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $names)); |
||
| 409 | $this->setVar('attribute_values', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $values)); |
||
| 410 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 411 | $this->setVar('attribute_prices', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $prices)); |
||
| 412 | } |
||
| 413 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 414 | $this->setVar('attribute_stocks', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $stocks)); |
||
| 415 | } |
||
| 416 | |||
| 417 | return true; |
||
| 418 | } |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Retourne le prix de l'attribut par défaut |
||
| 422 | * |
||
| 423 | * @param string $format |
||
| 424 | * @return float |
||
| 425 | * @since 2.3.2009.03.19 |
||
| 426 | */ |
||
| 427 | public function getDefaultAttributePrice($format = 'e') |
||
| 428 | { |
||
| 429 | $defaultValue = xoops_trim($this->getVar('attribute_default_value', 'e')); |
||
| 430 | if ('' !== $defaultValue) { |
||
| 431 | // Il y a une option par défaut donc un prix |
||
| 432 | $values = $this->getOption('attribute_values', $format); |
||
| 433 | $prices = $this->getOption('attribute_prices', $format); |
||
| 434 | $counter = 0; |
||
| 435 | if (count($values) > 0) { |
||
| 436 | foreach ($values as $value) { |
||
| 437 | if (xoops_trim($value) == $defaultValue) { |
||
| 438 | if (isset($prices[$counter])) { |
||
| 439 | return (float)$prices[$counter]; |
||
| 440 | } |
||
| 441 | |||
| 442 | return 0; |
||
| 443 | } |
||
| 444 | ++$counter; |
||
| 445 | } |
||
| 446 | } |
||
| 447 | } |
||
| 448 | |||
| 449 | return 0; |
||
| 450 | } |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Retourne la valeur par défaut de l'attribut courant |
||
| 454 | * |
||
| 455 | * @param string $format |
||
| 456 | * @return string |
||
| 457 | * @since 2.3.2009.03.20 |
||
| 458 | */ |
||
| 459 | public function getAttributeDefaultValue($format = 'e') |
||
| 460 | { |
||
| 461 | return xoops_trim($this->getVar('attribute_default_value', $format)); |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Retourne une liste combinée des options de l'attribut |
||
| 466 | * |
||
| 467 | * @param string $format Format dans lequel renvoyer les données |
||
| 468 | * @param bool $withFormatedPrices Faut il retourner les prix formatés ? |
||
| 469 | * @param Products $product Le produit de travail |
||
| 470 | * @return array |
||
| 471 | * @since 2.3.2009.03.11 |
||
| 472 | */ |
||
| 473 | public function getAttributeOptions($format = 's', $withFormatedPrices = false, Products $product = null) |
||
| 474 | { |
||
| 475 | $ret = []; |
||
| 476 | $counter = 0; |
||
| 477 | $oledrionCurrency = 0; |
||
| 478 | $vat_id = $vat = 0; |
||
| 479 | if (null !== $product) { |
||
| 480 | $vat_id = $product->getVar('product_vat_id'); |
||
| 481 | } |
||
| 482 | $names = $this->getOption('attribute_names', $format); |
||
| 483 | $values = $this->getOption('attribute_values', $format); |
||
| 484 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 485 | $prices = $this->getOption('attribute_prices', $format); |
||
| 486 | } |
||
| 487 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 488 | $stocks = $this->getOption('attribute_stocks', $format); |
||
| 489 | } |
||
| 490 | |||
| 491 | if ($withFormatedPrices) { |
||
| 492 | $oledrionCurrency = Oledrion\Currency::getInstance(); |
||
| 493 | } |
||
| 494 | if (count($names) > 0) { |
||
| 495 | foreach ($names as $key => $name) { |
||
| 496 | $price = $stock = 0; |
||
| 497 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 498 | $price = $prices[$key]; |
||
| 499 | if ($withFormatedPrices) { |
||
| 500 | $priceFormated = $oledrionCurrency->amountForDisplay($price); |
||
| 501 | $priceTtc = Oledrion\Utility::getAmountWithVat($price, $vat_id); |
||
| 502 | $priceTtcFormated = $oledrionCurrency->amountForDisplay($priceTtc); |
||
| 503 | $vat = $priceTtc - $price; |
||
| 504 | $vatFormated = $oledrionCurrency->amountForDisplay($vat); |
||
| 505 | } |
||
| 506 | } |
||
| 507 | if (Oledrion\Utility::getModuleOption('attributes_stocks')) { |
||
| 508 | $stock = $stocks[$key]; |
||
| 509 | } |
||
| 510 | if (!$withFormatedPrices) { |
||
| 511 | $ret[] = ['name' => $name, 'value' => $values[$key], 'price' => $price, 'stock' => $stock]; |
||
| 512 | } else { |
||
| 513 | $ret[] = [ |
||
| 514 | 'name' => $name, |
||
| 515 | 'value' => $values[$key], |
||
| 516 | 'price' => $price, |
||
| 517 | 'priceFormated' => $priceFormated, |
||
| 518 | 'priceTTC' => $priceTtc, |
||
| 519 | 'priceTTCFormated' => $priceTtcFormated, |
||
| 520 | 'vat' => $vat, |
||
| 521 | 'vatFormated' => $vatFormated, |
||
| 522 | 'counter' => $counter, |
||
| 523 | 'stock' => $stock, |
||
| 524 | ]; |
||
| 525 | } |
||
| 526 | ++$counter; |
||
| 527 | } |
||
| 528 | } |
||
| 529 | |||
| 530 | return $ret; |
||
| 531 | } |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Retourne la liste des types d'attributs |
||
| 535 | * |
||
| 536 | * @return array |
||
| 537 | * @since 2.3.2009.03.10 |
||
| 538 | */ |
||
| 539 | public function getTypesList() |
||
| 540 | { |
||
| 541 | $attributeTypeName = [ |
||
| 542 | Constants::OLEDRION_ATTRIBUTE_RADIO => _AM_OLEDRION_TYPE_RADIO, |
||
| 543 | Constants::OLEDRION_ATTRIBUTE_CHECKBOX => _AM_OLEDRION_TYPE_CHECKBOX, |
||
| 544 | Constants::OLEDRION_ATTRIBUTE_SELECT => _AM_OLEDRION_TYPE_LIST, |
||
| 545 | ]; |
||
| 546 | |||
| 547 | return $attributeTypeName; |
||
| 548 | } |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Retourne le type de l'attribut courant (son libellé) |
||
| 552 | * |
||
| 553 | * @return mixed Soit le type de l'attribut soit null; |
||
| 554 | * @since 2.3.2009.03.10 |
||
| 555 | */ |
||
| 556 | public function getTypeName() |
||
| 564 | } |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Retourne le prix d'une option en fonction de son nom |
||
| 568 | * |
||
| 569 | * @param string $optionName |
||
| 570 | * @return float |
||
| 571 | */ |
||
| 572 | public function getOptionPriceFromValue($optionName) |
||
| 573 | { |
||
| 574 | $ret = 0; |
||
| 575 | $format = 's'; |
||
| 576 | $counter = 0; |
||
| 577 | $values = $this->getOption('attribute_values', $format); |
||
| 578 | $prices = $this->getOption('attribute_prices', $format); |
||
| 579 | foreach ($values as $value) { |
||
| 580 | if (xoops_trim($value) == $optionName) { |
||
| 581 | if (isset($prices[$counter])) { |
||
| 582 | return (float)$prices[$counter]; |
||
| 583 | } |
||
| 584 | } |
||
| 585 | ++$counter; |
||
| 586 | } |
||
| 587 | |||
| 588 | return $ret; |
||
| 589 | } |
||
| 590 | |||
| 591 | /** |
||
| 592 | * Retourne le libellé d'une option en fonction de son nom |
||
| 593 | * |
||
| 594 | * @param string $optionName |
||
| 595 | * @return string |
||
| 596 | */ |
||
| 597 | public function getOptionNameFromValue($optionName) |
||
| 598 | { |
||
| 599 | $ret = ''; |
||
| 600 | $format = 's'; |
||
| 601 | $counter = 0; |
||
| 602 | $values = $this->getOption('attribute_values', $format); |
||
| 603 | $names = $this->getOption('attribute_names', $format); |
||
| 604 | foreach ($values as $value) { |
||
| 605 | if (xoops_trim($value) == $optionName) { |
||
| 606 | if (isset($names[$counter])) { |
||
| 607 | return $names[$counter]; |
||
| 608 | } |
||
| 609 | } |
||
| 610 | ++$counter; |
||
| 611 | } |
||
| 612 | |||
| 613 | return $ret; |
||
| 614 | } |
||
| 615 | |||
| 616 | /** |
||
| 617 | * Création du code html de l'attribut |
||
| 618 | * |
||
| 619 | * On utilise le contenu de templates html (réalisés en Smarty) pour créer le contenu de l'attribut |
||
| 620 | * Templates utilisés (selon le type d'attribut) : |
||
| 621 | * oledrion_attribute_checkbox.html |
||
| 622 | * oledrion_attribute_radio.html |
||
| 623 | * oledrion_attribute_select.html |
||
| 624 | * |
||
| 625 | * @param Products $product Le produit de "travail" |
||
| 626 | * @return string Le contenu html |
||
| 627 | * @since 2.3.2009.03.16 |
||
| 628 | */ |
||
| 629 | public function render(Products $product) |
||
| 722 | } |
||
| 723 | } |
||
| 724 |