XoopsModules25x /
oledrion
| 1 | <?php |
||
| 2 | |||
| 3 | namespace XoopsModules\Oledrion; |
||
| 4 | |||
| 5 | /* |
||
| 6 | You may not change or alter any portion of this comment or credits |
||
| 7 | of supporting developers from this source code or any supporting source code |
||
| 8 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, |
||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 13 | */ |
||
| 14 | |||
| 15 | /** |
||
| 16 | * oledrion |
||
| 17 | * |
||
| 18 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 19 | * @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
||
| 20 | * @author Hervé Thouzard (http://www.herve-thouzard.com/) |
||
| 21 | */ |
||
| 22 | |||
| 23 | use XoopsModules\Oledrion; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Gestion des options (attributs) produits dans les commandes |
||
| 27 | */ |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Class Caddy_attributes |
||
| 31 | */ |
||
| 32 | class CaddyAttributes extends OledrionObject |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * constructor |
||
| 36 | * |
||
| 37 | * normally, this is called from child classes only |
||
| 38 | */ |
||
| 39 | public function __construct() |
||
| 40 | { |
||
| 41 | $this->initVar('ca_id', XOBJ_DTYPE_INT, null, false); |
||
| 42 | $this->initVar('ca_cmd_id', XOBJ_DTYPE_INT, null, false); |
||
| 43 | $this->initVar('ca_caddy_id', XOBJ_DTYPE_INT, null, false); |
||
| 44 | $this->initVar('ca_attribute_id', XOBJ_DTYPE_INT, null, false); |
||
| 45 | $this->initVar('ca_attribute_values', XOBJ_DTYPE_OTHER, null, false); |
||
| 46 | $this->initVar('ca_attribute_names', XOBJ_DTYPE_OTHER, null, false); |
||
| 47 | $this->initVar('ca_attribute_prices', XOBJ_DTYPE_OTHER, null, false); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Retourne une option de l'attribut |
||
| 52 | * |
||
| 53 | * @param string $valueToGet |
||
| 54 | * @param string $format |
||
| 55 | * @return array |
||
| 56 | * @since 2.3.2009.03.11 |
||
| 57 | */ |
||
| 58 | public function getOption($valueToGet, $format = 'e') |
||
| 59 | { |
||
| 60 | $names = []; |
||
| 61 | if ('' !== xoops_trim($this->getVar($valueToGet, $format))) { |
||
| 62 | $names = explode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $this->getVar($valueToGet, $format)); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 63 | } |
||
| 64 | |||
| 65 | return $names; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Ajout d'une option à l'attribut (soit une option vide soit une option valorisée) |
||
| 70 | * |
||
| 71 | * @param string $name |
||
| 72 | * @param string $value |
||
| 73 | * @param string $price |
||
| 74 | * @return bool |
||
| 75 | * @since 2.3.2009.03.16 |
||
| 76 | */ |
||
| 77 | private function appendOption($name, $value, $price = '') |
||
| 78 | { |
||
| 79 | $names = $values = $prices = []; |
||
| 80 | $format = 'e'; |
||
| 81 | $names = $this->getOption('ca_attribute_names', $format); |
||
| 82 | $values = $this->getOption('ca_attribute_values', $format); |
||
| 83 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 84 | $prices = $this->getOption('ca_attribute_prices', $format); |
||
| 85 | } |
||
| 86 | $names[] = $name; |
||
| 87 | $values[] = $value; |
||
| 88 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 89 | $prices[] = $price; |
||
| 90 | } |
||
| 91 | $this->setVar('ca_attribute_names', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $names)); |
||
| 92 | $this->setVar('ca_attribute_values', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $values)); |
||
| 93 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 94 | $this->setVar('ca_attribute_prices', implode(Constants::OLEDRION_ATTRIBUTE_SEPARATOR, $prices)); |
||
| 95 | } |
||
| 96 | |||
| 97 | return true; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Ajoute une nouvelle option à l'attribut |
||
| 102 | * |
||
| 103 | * @param string $name |
||
| 104 | * @param string $value |
||
| 105 | * @param string $price |
||
| 106 | * @return bool |
||
| 107 | * @since 2.3.2009.03.16 |
||
| 108 | */ |
||
| 109 | public function addOption($name, $value, $price = '') |
||
| 110 | { |
||
| 111 | return $this->appendOption($name, $value, $price); |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Retourne les informations formatées de l'attribut pour affichage dans la facture |
||
| 116 | * |
||
| 117 | * @param Products $product Le produit concerné par l'attribut |
||
| 118 | * @param string $format |
||
| 119 | * @return array |
||
| 120 | * @since 2.3.2009.03.23 |
||
| 121 | */ |
||
| 122 | public function renderForInvoice(Products $product, $format = 's') |
||
| 123 | { |
||
| 124 | $names = $prices = $ret = []; |
||
| 125 | $names = $this->getOption('ca_attribute_names', $format); |
||
| 126 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 127 | $prices = $this->getOption('ca_attribute_prices', $format); |
||
| 128 | } |
||
| 129 | |||
| 130 | $oledrionCurrency = Oledrion\Currency::getInstance(); |
||
| 131 | $counter = 0; |
||
| 132 | foreach ($names as $name) { |
||
| 133 | $price = 0; |
||
| 134 | if (Oledrion\Utility::getModuleOption('use_price')) { |
||
| 135 | if (isset($prices[$counter])) { |
||
| 136 | $price = Oledrion\Utility::getAmountWithVat((float)$prices[$counter], $product->getVar('product_vat_id')); |
||
| 137 | $price = $oledrionCurrency->amountForDisplay($price); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | $ret[] = ['ca_attribute_name' => $name, 'ca_attribute_price_formated' => $price]; |
||
| 141 | ++$counter; |
||
| 142 | } |
||
| 143 | |||
| 144 | return $ret; |
||
| 145 | } |
||
| 146 | } |
||
| 147 |