Browse Source

Ajuste en filtro de productos

Hugo Quijada 10 months ago
parent
commit
8815fc8333
1 changed files with 19 additions and 5 deletions
  1. 19 5
      modules/publico/controllers/CondicionantesController.php

+ 19 - 5
modules/publico/controllers/CondicionantesController.php

@@ -24,11 +24,25 @@ class CondicionantesController extends JsonController {
 			->andWhere(["{{Condicionante}}.[[eliminado]]" => null]);
 
 		if ($producto > 0) {
-			$producto = Producto::find()
-				->andWhere(["idSagarhpa" => $producto])
-				->one();
-			$condicionante
-				->andWhere(["OR", ["{{Condicionante}}.[[idProducto]]" => $producto->id], ["{{Condicionante}}.[[idProducto]]" => $producto->idPadre]]);
+      $query = (new Query)
+        ->select("id")
+        ->from("Producto")
+        ->andWhere([
+          "eliminado" => null,
+          "idSagarhpa" => $producto
+        ]);
+			$productos = (clone $query)
+        ->union((clone $query)->select("[[idPadre]] [[id]]"))
+        ->column();
+
+      $idProductos = (new Query)
+        ->from("Producto")
+        ->select("id")
+        ->andWhere(["eliminado" => null])
+        ->andWhere(["OR", ["id" => $productos], ["idPadre" => $productos]])
+        ->column();
+
+			$condicionante->andWhere(["idProducto" => $idProductos]);
 		}
 
 		/* # En el front no se pueden elegir ciudades*/