public function getSoldProducts() { $condition = "quantity < 0"; $data = $this->db->getAllEntitiesWithCondition(self::PRODUCTS_TABLENAME, $condition, 'id'); $soldProducts = []; foreach ($data as $p) { $product = new SoldProduct($p); array_push($soldProducts, $product); } return $soldProducts; }
public function removeDiscountOnCategory($categoryId) { $condition = 'category_id = ' . $categoryId; $categoryPromotion = $this->db->getAllEntitiesWithCondition(self::PROMO_CATEGORIES_TABLENAME, $condition, 'promotedAt'); $discount = $categoryPromotion[0]['discount']; $productsInCategory = $this->db->getAllEntitiesWithCondition(self::PRODUCTS_TABLENAME, "category_id={$categoryId}", 'id'); foreach ($productsInCategory as $product) { $restoredPrice = $product['price'] + $product['price'] * ($discount / 100); $isUpdated = $this->db->updateEntityById(self::PRODUCTS_TABLENAME, array("price" => $restoredPrice), $product['id']); } if ($isUpdated) { $remove = $this->db->deleteEntityById(self::PROMO_CATEGORIES_TABLENAME, $categoryPromotion[0]['id']); } return $remove; }