public function actionView($categoryslug, $productslug) { $categoryData = ProductCategories::find()->where(["slug" => $categoryslug])->asArray()->one(); $productData = Products::find()->where(["slug" => $productslug])->with(["productToppings", "productImages"])->asArray()->one(); $tagData = ProductTagProducts::find()->where(["product_id" => $productData["id"]])->with(["tag"])->asArray()->all(); $orderProducts = new OrderProducts(); return $this->render("view", ["categoryData" => $categoryData, "productData" => $productData, "tagData" => $tagData, "topSelling" => $orderProducts->getTopSellingProducts(9)]); }
public function actionIndex() { $destination = $this->getDestinationAccount(); // pending orders $query = OrderProducts::find()->where('quantity>consumed'); $query->leftJoin('order_shipping', "order_products.order_id = order_shipping.order_id"); $query->andFilterWhere(['order_shipping.shipping_email' => $destination->email]); $query->orderBy(['order_products.order_id' => SORT_DESC, 'order_products.id' => SORT_DESC]); return $this->render('index', ['pending' => $query->all()]); }
public function actionIndex() { $provider = $this->getProvider(); $query = OrderProducts::find(); $query->leftJoin('product', 'product.id=order_products.product_id'); $query->leftJoin('order', 'order.id=order_products.order_id'); $query->andFilterWhere(['order.status' => Order::STATUS_APPROVED]); $query->andFilterWhere(['product.provider_id' => $provider->id]); $query->andWhere('order_products.quantity>order_products.consumed'); $query->orderBy(['order.id' => SORT_DESC, 'order_products.id' => SORT_ASC]); $query->limit(10); // top sellers $sql = "select product_id, sum(quantity) as cant from order_products left join simplestore.order on order.id=order_products.order_id left join product on product.id=order_products.product_id where order.status=:approved and product.provider_id=:prov group by product_id order by cant desc limit :limit"; $products = Yii::$app->db->createCommand($sql, [':approved' => Order::STATUS_APPROVED, ':prov' => $provider->id, ':limit' => 10])->queryAll(); return $this->render('index', ['pending' => $query->all(), 'products' => $products]); }
/** * Updates an existing Order model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdateConsumed($id) { $model = $this->findModel($id); if (Yii::$app->request->isPost && isset($_REQUEST['order_products']) && is_array($_REQUEST['order_products'])) { foreach ($_REQUEST['order_products'] as $op_id => $consumed) { /** @var OrderProducts $op */ $op = OrderProducts::findOne($op_id); if (!is_null($op) && $op->order_id == $model->id) { if ($op->consumed < min($op->quantity, $consumed)) { $op->consumed_date = date('Y-m-d H:i:s'); } if (isset($_REQUEST['order_consumed']) && is_array($_REQUEST['order_consumed']) && isset($_REQUEST['order_consumed'][$op_id]) && !empty($_REQUEST['order_consumed'][$op_id])) { $op->consumed_date = $_REQUEST['order_consumed'][$op_id]; } $op->consumed = min($op->quantity, $consumed); $op->save(); } } } return $this->redirect(['index']); }
public function actionIndex() { $orderProducts = new OrderProducts(); $productCategories = new ProductCategories(); return $this->render('index', ["slider" => Slider::find()->orderBy('ordering ASC')->asArray()->all(), "topSelling" => $orderProducts->getTopSellingProducts(9), "categoryProducts" => $productCategories->getCatLowCostProducts()]); }
/** * @return \yii\db\ActiveQuery */ public function getOrderProducts() { return $this->hasMany(OrderProducts::className(), ['product_id' => 'id']); }
public function calcPrice($orderId) { $orderProds = OrderProducts::find()->where(["order_id" => $orderId])->asArray()->all(); $products = []; if ($orderProds) { foreach ($orderProds as $row) { $products[] = ["product" => Products::find()->with('productToppings')->where(["id" => $row["product_id"]])->asArray()->one(), "toppings" => $row["toppings"], "count" => $row["count"]]; } } return $products; }
/** * @return \yii\db\ActiveQuery */ public function getOrderProduct() { return $this->hasOne(OrderProducts::className(), ['id' => 'order_product_id']); }
/** * Deletes an existing Orders model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { return $this->redirect("/admin/orders/index"); exit; OrderProducts::deleteAll(["order_id" => $id]); $this->findModel($id)->delete(); return $this->redirect(['index']); }