Fix issues found during testing of update of trade in prices. #789
This commit is contained in:
parent
59c65235b7
commit
8804818828
2 changed files with 71 additions and 3 deletions
|
|
@ -55,12 +55,74 @@ class TradeInPricingController extends Controller
|
|||
public function formSubmit(Request $req, EntityManagerInterface $em)
|
||||
{
|
||||
$pt_id = $req->request->get('price_tier_id');
|
||||
|
||||
// get the trade in prices
|
||||
$motolite_tips = $req->request->get('motolite_tip');
|
||||
$premium_tips = $req->request->get('premium_tip');
|
||||
$other_tips = $req->request->get('other_tip');
|
||||
|
||||
// get the battery sizes
|
||||
$bsizes = $em->getRepository(BatterySize::class)->findBy([], ['id' => 'asc']);
|
||||
|
||||
// on default price tier
|
||||
if ($pt_id == 0)
|
||||
{
|
||||
// default price tier, update battery size trade in prices
|
||||
// NOTE: battery size trade in prices are stored as decimal
|
||||
foreach ($bsizes as $bsize)
|
||||
{
|
||||
$bsize_id = $bsize->getID();
|
||||
if (isset($motolite_tips[$bsize_id]))
|
||||
$bsize->setTIPriceMotolite($motolite_tips[$bsize_id]);
|
||||
|
||||
if (isset($premium_tips[$bsize_id]))
|
||||
$bsize->setTIPricePremium($premium_tips[$bsize_id]);
|
||||
|
||||
if (isset($other_tips[$bsize_id]))
|
||||
$bsize->setTIPriceOther($other_tips[$bsize_id]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// get the price tier
|
||||
$price_tier = $em->getRepository(PriceTier::class)->find($pt_id);
|
||||
|
||||
$pt_tips = $price_tier->getTradeInPrices();
|
||||
|
||||
// clear the tier's trade in prices
|
||||
foreach ($pt_tips as $pt_tip)
|
||||
{
|
||||
$em->remove($pt_tip);
|
||||
}
|
||||
|
||||
// update the tier's trade in prices
|
||||
foreach ($bsizes as $bsize)
|
||||
{
|
||||
$bsize_id = $bsize->getID();
|
||||
|
||||
$new_tip = new TradeInPrice();
|
||||
|
||||
$new_tip->setPriceTier($price_tier)
|
||||
->setItemID($bsize_id);
|
||||
|
||||
$new_tip->addMetaInfo(TradeInType::MOTOLITE, $motolite_tips[$bsize_id] * 100);
|
||||
$new_tip->addMetaInfo(TradeInType::PREMIUM, $premium_tips[$bsize_id] * 100);
|
||||
$new_tip->addMetaInfo(TradeInType::OTHER, $other_tips[$bsize_id] * 100);
|
||||
|
||||
// save
|
||||
$em->persist($new_tip);
|
||||
}
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute('trade_in_pricing');
|
||||
}
|
||||
|
||||
/**
|
||||
* @IsGranted("trade_in_pricing.update")
|
||||
*/
|
||||
public function tradeInPrices(EntityManagerInterface $em, $pt_id, $ti_type)
|
||||
public function tradeInPrices(EntityManagerInterface $em, $pt_id)
|
||||
{
|
||||
$pt_prices = [];
|
||||
|
||||
|
|
@ -119,7 +181,7 @@ class TradeInPricingController extends Controller
|
|||
$data_items[] = [
|
||||
'id' => $bsize_id,
|
||||
'name' => $name,
|
||||
'motolite_tip' => $actul_motolite_tip,
|
||||
'motolite_tip' => $actual_motolite_tip,
|
||||
'premium_tip' => $actual_premium_tip,
|
||||
'other_tip' => $actual_other_tip,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -127,7 +127,13 @@ function update_table(data) {
|
|||
item_html += '<td>' + item.id + '</td>';
|
||||
item_html += '<td>' + item.name + '</td>';
|
||||
item_html += '<td class="py-1">';
|
||||
item_html += '<input name="price[' + item.id + ']" class="form-control ca-filter" type="number" value="' + item.price + '" step="0.01">';
|
||||
item_html += '<input name="motolite_tip[' + item.id + ']" class="form-control ca-filter" type="number" value="' + item.motolite_tip + '" step="0.01">';
|
||||
item_html += '</td>';
|
||||
item_html += '<td class="py-1">';
|
||||
item_html += '<input name="premium_tip[' + item.id + ']" class="form-control ca-filter" type="number" value="' + item.premium_tip + '" step="0.01">';
|
||||
item_html += '</td>';
|
||||
item_html += '<td class="py-1">';
|
||||
item_html += '<input name="other_tip[' + item.id + ']" class="form-control ca-filter" type="number" value="' + item.other_tip + '" step="0.01">';
|
||||
item_html += '</td>';
|
||||
item_html += '</tr>';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue