s02e08 - Products Cost QUESTIONS/SUPPORT
Posted: Thu Mar 11, 2021 12:51 pm
Questions / Comments / Concerns
Free Open Source Ecommerce
https://phoenixcart.org/forum/
Code: Select all
<div class="form-group row" id="zNet">
<label for="pNet" class="col-form-label col-sm-3 text-left text-sm-right"><?= TEXT_PRODUCTS_PRICE_NET ?></label>
<div class="col-sm-9">
<?= (new Input('products_price', ['id' => 'pNet', 'class' => 'form-control w-25', 'onchange' => 'updateGross()']))->require()->default_value($product->get('price') ?? '') ?>
<?php
$num = $product->get('cost');
$percentage = 20;
$num += $num*($percentage/100); // results in cost price + VAT @ 20%
echo '<b>Cost Price + VAT @ 20% :</b>' . ' ' . $num;
?>
</div>
</div>
Code: Select all
class hook_admin_catalog_netPriceText {
public function listen_injectSiteEnd() {
if (!empty($GLOBALS['product']->get('id'))) {
$num = $GLOBALS['product']->get('cost') * 1.2;
$pNetText = <<<pn
<script>
$('#pNet').after('<small class="form-text text-muted">Cost Price + VAT @ 20% : {$num}</small>');
</script>
pn;
return $pNetText;
}
}
}
@burtburt wrote: ↑Sun Dec 31, 2023 1:02 pm There is no straightforward way to add data in the middle of a form. Here's an idea that might work, I don't test these things, but if the code looks right...it should work. Maybe.
1. Undo the core code change you made.
2.
New file:
/includes/hooks/admin/catalog/netPriceText.php
Contents:Code: Select all
class hook_admin_catalog_netPriceText { public function listen_injectSiteEnd() { if (!empty($GLOBALS['product']->get('id'))) { $num = $GLOBALS['product']->get('cost') * 1.2; $pNetText = <<<pn <script> $('#pNet').after('<small class="form-text text-muted">Cost Price + VAT @ 20% : {$num}</small>'); </script> pn; return $pNetText; } } }