public function getPromotionsForCategories() { $promotions = $this->db->getAllEntities(self::PROMO_CATEGORIES_TABLENAME, 'promotedAt'); $categoriesPromos = []; foreach ($promotions as $promo) { $promoCategory = new PromoCategory($promo); if ($promo['isInPromotion'] == '1') { array_push($categoriesPromos, $promoCategory); } } return $categoriesPromos; }
public function removeAllProductsDiscount($id) { $condition = "id={$id}"; $promotion = $this->db->getAllEntitiesWithCondition(self::ALL_PRODUCTS_PROMO_TABLENAME, $condition, 'id'); $discount = $promotion[0]['discount']; $allProducts = $this->db->getAllEntities(self::PRODUCTS_TABLENAME, 'id'); foreach ($allProducts as $product) { $restoredPrice = $product['price'] + $product['price'] * ($discount / 100); $isUpdated = $this->db->updateEntityById(self::PRODUCTS_TABLENAME, array("price" => $restoredPrice), $product['id']); if (!$isUpdated) { throw new InvalidUserOperationException("Error during remove promo"); } } if ($isUpdated) { $isDeleted = $this->db->deleteEntityById(self::ALL_PRODUCTS_PROMO_TABLENAME, $id); } return $isDeleted; }