Browse Source

products authorizing decimals in quantity : add checks and info display TG-52

SiM 5 years ago
parent
commit
56be1fcda6

+ 11 - 3
apps/admin/modules/kataoOrder/templates/adjustProductSuccess.php

@@ -6,12 +6,20 @@
 <?php echo form_tag('@katao_order_product_adjust?id=' . $katao_order_product->getId()) ?>
 
 <?php $katao_product = $katao_order_product->getKataoProduct() ?>
+<?php $authorize_quantity_decimal = $katao_product->getAuthorizeDecimal() ?>
+<?php $input_options = array('step' => ($authorize_quantity_decimal ?'any' : '1'), 'min' => '0', 'style' => 'width: 60px; height: 20px; text-align: center;') ?>
 <h3><?php echo $katao_order_product->getProductName() ?></h3>
 
 <table class="admin-sub-list">
 <tr>
 	<td style="border:none!important">Commande : <?php echo $katao_product->getOrderDetails($katao_order_product->getKataoOrder()->getKataoPeriodId(), $katao_order_product->getKataoOrder()->getKataoNodeId(), true) ?></td>
-	<th colspan="2" style="text-align:center!important">Quantités</th>
+	<th colspan="2" style="text-align:center!important">Quantités 
+		<?php if ($authorize_quantity_decimal): ?> 
+			<?php echo image_tag('decimals_icon.png', array('alt' => 'Décimales autorisées', 'title' => 'Décimales autorisées', 'align' => 'middle' )); ?>
+		<?php else: ?>
+			<?php echo image_tag('decimals_not_icon.png', array('alt' => 'Décimales non autorisées', 'title' => 'Décimales non autorisées', 'align' => 'middle' )); ?>
+		<?php endif ?>
+	</th>
 </tr>
 <tr>
 	<th>Adhérent</th>
@@ -28,7 +36,7 @@
  	<td><?php echo $katao_cart_product->getQuantity() ?></td>
  	<td nowrap="nowrap">
  	<?php if (!$view_mode_only): ?>
-		<?php echo input_number_tag('quantity[' . $katao_cart_product->getId() . ']', $katao_cart_product->getQuantityAdjusted(), array('style' => 'width: 60px; height: 20px; text-align: center;')) ?>
+		<?php echo input_number_tag('quantity[' . $katao_cart_product->getId() . ']', $katao_cart_product->getQuantityAdjusted(), $input_options) ?>
 	<?php else: ?>
 		<?php echo $katao_cart_product->getQuantityAdjusted() ?>
 	<?php endif ?>
@@ -40,7 +48,7 @@
  	<td><?php echo select_tag('new_user_id', options_for_select($katao_order_product->getMembersWithoutProduct(), false, array('include_custom' => '&mdash;&nbsp;Ajouter une commande à un adhérent&nbsp;&mdash;'))) ?></td>
  	<td>-</td>
  	<td nowrap="nowrap">
-		<?php echo input_number_tag('quantity[0]', '0', array('style' => 'width: 60px; height: 20px; text-align: center;')) ?>
+		<?php echo input_number_tag('quantity[0]', '0', $input_options) ?>
 	</td>
 </tr>
 <?php endif ?>

+ 8 - 2
apps/frontend/modules/katao/actions/actions.class.php

@@ -128,8 +128,14 @@ class kataoActions extends sfActions {
         $this->forward404Unless($katao_product);
         $this->forward404If(!$katao_product->isCartable());
 
-        if (0 < (float)$request->getParameter('quantity')) {
-            $this->getUser()->getInstance()->addProductToCart($katao_product->getId(), $request->getParameter('quantity', 1));
+        $quantity = $request->getParameter('quantity', 1);
+        if (0 < (float)$quantity) {
+            if ($katao_product->getAuthorizeDecimal()) {
+                $quantity = number_format($quantity, 3);
+            } else {
+                $quantity = round($quantity);
+            }
+            $this->getUser()->getInstance()->addProductToCart($katao_product->getId(), $quantity);
         } else {
             $this->getUser()->getInstance()->removeProductFromCart($katao_product->getId());
         }

+ 5 - 1
apps/frontend/modules/katao/templates/_products.php

@@ -2,6 +2,7 @@
 	<ul class="plus">
 	<?php $products_displayed = 0 ?>
 	<?php foreach($pager->getResults() as/*(KataoProduct)*/ $katao_product): ?>
+		<?php $authorize_quantity_decimal = $katao_product->getAuthorizeDecimal() ?>
 		<?php $is_cartable = $katao_product->isCartable() && $sf_user->isAuthenticated() && $sf_user->hasCredential('member') ?>
 		<?php $order_details = $is_cartable?$katao_product->getOrderDetails($sf_user->getActivePeriod()->getId(), $sf_user->getActiveNode()->getId()):'' ?>
 		<?php
@@ -40,9 +41,12 @@ if ($display) {
 			<?php if ($is_cartable): ?>
 				<div style="clear: both; padding-top: 15px">
 					<div style="float: left; padding-right: 10px">
-						<input type="number" name="quantity[<?php echo $katao_product->getId() ?>]" id="quantity_<?php echo $katao_product->getId() ?>" value="1" style="width: 60px; height: 20px; text-align: center;" />	
+						<input type="number" min="0" name="quantity[<?php echo $katao_product->getId() ?>]" id="quantity_<?php echo $katao_product->getId() ?>" <?php if ($authorize_quantity_decimal): ?>step="any" value="1.000"<?php else: ?>step="1" value="1"<?php endif ?> style="width: 60px; height: 20px; text-align: center;" />	
 					</div>
 					<div style="float: left">
+						<?php if ($authorize_quantity_decimal): ?>
+							<p>Décimales autorisées pour ce produit</p>
+						<?php endif ?>
 						<a class="btn-commander" href="javascript://" onclick="window.location = '<?php echo url_for('@katao_cart_add_js') ?>?product=<?php echo $katao_product->getUrlIdentifier() ?>&quantity='+document.getElementById('quantity_<?php echo $katao_product->getId() ?>').value;">Commander</a>
 					</div>
 				</div>

+ 6 - 0
apps/frontend/modules/katao/templates/cartSuccess.php

@@ -42,6 +42,7 @@ unset($allLanguages[$default]);
 	<?php foreach($cart->getKataoCartProductsJoinKataoProduct() as/*(KataoCartProduct)*/ $katao_cart_product): ?>
 		<?php $quantity = $katao_cart_product->getQuantity() ?>
 		<?php $katao_product = $katao_cart_product->getKataoProduct() ?>
+		<?php $authorize_quantity_decimal = $katao_product->getAuthorizeDecimal() ?>
 		<li>
 			<div class="image01">
 				<div class="top"></div>
@@ -61,6 +62,11 @@ unset($allLanguages[$default]);
 				<div style="clear: both">
 					<div style="float: left; padding-right: 10px">
 						<input type="number" name="quantity_<?php echo $katao_product->getId() ?>" id="quantity_<?php echo $katao_product->getId() ?>" value="<?php echo $quantity ?>" style="width: 60px; height: 20px; text-align: center;" />
+						<?php if ($authorize_quantity_decimal): ?>
+							<?php echo image_tag('decimals_icon.png', array('alt' => 'Décimales autorisées', 'title' => 'Décimales autorisées', 'align' => 'top' )); ?>
+						<?php else: ?>
+							<?php echo image_tag('decimals_not_icon.png', array('alt' => 'Décimales non autorisées', 'title' => 'Décimales non autorisées', 'align' => 'top' )); ?>
+						<?php endif ?>
 					</div>
 					<div style="float: left; padding-right: 10px; padding-top: 4px">
 						<a class="btn-plus" href="javascript://" onclick="window.location = '<?php echo url_for('@katao_cart_add_js') ?>?product=<?php echo $katao_product->getUrlIdentifier() ?>&quantity='+document.getElementById('quantity_<?php echo $katao_product->getId() ?>').value;">Mettre à jour</a>

+ 4 - 0
apps/frontend/modules/katao/templates/storeSuccess.php

@@ -42,6 +42,7 @@ unset($allLanguages[$default]);
 <?php elseif ($katao_product_category && $katao_product_family && $katao_product): ?>
 	<?php $katao_product = KataoProductPeer::retrieveByUrlIdentifier($katao_product) ?>
 	<?php $katao_product_cartable = $katao_product->isCartable() ?>
+	<?php $authorize_quantity_decimal = $katao_product->getAuthorizeDecimal() ?>
 	<ul class="plus01">
 		<li>
 			<div class="image02">
@@ -76,6 +77,9 @@ unset($allLanguages[$default]);
 					<div style="float: left; padding-right: 10px">
 						<input type="number" name="quantity" id="quantity" value="1" style="width: 60px; height: 20px; text-align: center;" />
 					</div>
+					<?php if ($authorize_quantity_decimal): ?>
+						<p>Décimales autorisées pour ce produit</p>
+					<?php endif ?>
 					<div style="float: left">
 						<a class="btn-commander" href="javascript://" onclick="window.location = '<?php echo url_for('@katao_cart_add_js') ?>?product=<?php echo $katao_product->getUrlIdentifier() ?>&quantity='+document.getElementById('quantity').value;">Commander</a>
 					</div>

+ 1 - 1
lib/symfony/lib/widget/sfWidgetFormInputNumber.class.php

@@ -5,7 +5,7 @@
  */
 
 /**
- * sfWidgetFormInput represents an HTML input number tag.
+ * sfWidgetFormInputNumber represents an HTML input number tag.
  *
  * @package    symfony
  * @subpackage widget

BIN
web/images/decimals_icon.png


BIN
web/images/decimals_not_icon.png