From 4a9dc2a6b22992caa19035c5c52fb89f2473420c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 6 Feb 2024 04:43:58 -0500 Subject: [PATCH] Add routes, controller, and template for trade in pricing. #789 --- config/packages/catalyst_auth.yaml | 5 + config/packages/catalyst_menu.yaml | 4 + config/routes/trade_in_pricing.yaml | 14 ++ src/Controller/TradeInPricingController.php | 72 ++++++++++ src/Entity/TradeInPrice.php | 117 ++++++++++++++++ templates/trade-in-pricing/form.html.twig | 143 ++++++++++++++++++++ 6 files changed, 355 insertions(+) create mode 100644 config/routes/trade_in_pricing.yaml create mode 100644 src/Controller/TradeInPricingController.php create mode 100644 src/Entity/TradeInPrice.php create mode 100644 templates/trade-in-pricing/form.html.twig diff --git a/config/packages/catalyst_auth.yaml b/config/packages/catalyst_auth.yaml index 9707fc93..fe6cb91f 100644 --- a/config/packages/catalyst_auth.yaml +++ b/config/packages/catalyst_auth.yaml @@ -672,6 +672,11 @@ catalyst_auth: acls: - id: item_pricing.update label: Update + - id: trade_in_pricing + label: Trade In Pricing + acls: + - id: trade_in_pricing.update + label: Update api: user_entity: "App\\Entity\\ApiUser" diff --git a/config/packages/catalyst_menu.yaml b/config/packages/catalyst_menu.yaml index 7972a414..19af068c 100644 --- a/config/packages/catalyst_menu.yaml +++ b/config/packages/catalyst_menu.yaml @@ -306,3 +306,7 @@ catalyst_menu: acl: item_pricing.update label: Item Pricing parent: item + - id: trade_in_pricing + acl: trade_in_pricing.update + label: Trade In Pricing + parent: item diff --git a/config/routes/trade_in_pricing.yaml b/config/routes/trade_in_pricing.yaml new file mode 100644 index 00000000..dbc52fb7 --- /dev/null +++ b/config/routes/trade_in_pricing.yaml @@ -0,0 +1,14 @@ +trade_in_pricing: + path: /trade-in-pricing + controller: App\Controller\TradeInPricingController::index + methods: [GET] + +trade_in_pricing_update: + path: /trade-in-pricing + controller: App\Controller\TradeInPricingController::formSubmit + methods: [POST] + +trade_in_pricing_prices: + path: /trade-in-pricing/{pt_id}/prices + controller: App\Controller\TradeInPricingController::tradeInPrices + methods: [GET] diff --git a/src/Controller/TradeInPricingController.php b/src/Controller/TradeInPricingController.php new file mode 100644 index 00000000..f9c0dcb4 --- /dev/null +++ b/src/Controller/TradeInPricingController.php @@ -0,0 +1,72 @@ +getRepository(PriceTier::class)->findAll(); + + // get all the items/battery sizes + $items = $this->getBatterySizes($em); + + // get the trade in types + + $params = [ + 'sets' => [ + 'price_tiers' => $price_tiers, + 'trade_in_types' => TradeInType::getCollection(), + ], + 'items' => $items, + ]; + + // TODO: fix display of prices according to trade in type selected + // need to set a default trade in type to display? check TradeInType::getCollection + return $this->render('trade-in-pricing/form.html.twig', $params); + } + + protected function getBatterySizes(EntityManagerInterface $em) + { + // get all battery sizes + $b_sizes = $em->getRepository(BatterySize::class)->findBy([], ['name' => 'asc']); + foreach ($b_sizes as $b_size) + { + $b_size_set[$b_size->getID()] = [ + 'name' => $b_size->getName(), + 'motolite_tiprice' => $b_size->getTIPriceMotolite(), + 'premium_tiprice' => $b_size->getTIPricePremium(), + 'other_tiprice' => $b_size->getTIPriceOther(), + ]; + } + + return [ + 'items' => $b_size_set, + ]; + } +} diff --git a/src/Entity/TradeInPrice.php b/src/Entity/TradeInPrice.php new file mode 100644 index 00000000..de5d1216 --- /dev/null +++ b/src/Entity/TradeInPrice.php @@ -0,0 +1,117 @@ +meta_info = []; + } + + public function getID() + { + return $this->id; + } + + public function setPriceTier(PriceTier $price_tier) + { + $this->price_tier = $price_tier; + return $this; + } + + public function getPriceTier() + { + return $this->price_tier; + } + + public function setItemType(ItemType $item_type) + { + $this->item_type = $item_type; + return $this; + } + + public function getItemType() + { + return $this->item_type; + } + + public function setItemID($item_id) + { + $this->item_id = $item_id; + return $this; + } + + public function getItemID() + { + return $this->item_id; + } + + public function addMetaInfo($id, $value) + { + $this->meta_info[$id] = $value; + return $this; + } + + public function deleteMetadataInfo($id) + { + unset($this->meta_info[$id]); + return $this; + } + + public function getMetaInfo($id) + { + // return null if we don't have it + if (!isset($this->meta_info[$id])) + return null; + + return $this->meta_info[$id]; + } + + public function getAllMetaInfo() + { + return $this->meta_info; + } +} diff --git a/templates/trade-in-pricing/form.html.twig b/templates/trade-in-pricing/form.html.twig new file mode 100644 index 00000000..77198fe2 --- /dev/null +++ b/templates/trade-in-pricing/form.html.twig @@ -0,0 +1,143 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Trade-In Pricing

+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + {% for id, item in items.items %} + + + + + + {% endfor %} + +
IDNamePrice
{{ id }}{{ item.name }}
+
+ +
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %}