s02e08 - Products Cost QUESTIONS/SUPPORT
-
admin
- Contributor
- Posts: 217
- Joined: Wed Oct 30, 2019 1:34 pm
- Phoenix Version:
- Has thanked: 20 times
- Been thanked: 22 times
- tessthepup
- Certified Developer
- Posts: 382
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Products Cost Price
Hi Guys,
As my store has several thousand products that edit on a semi regular basis (mainly product price) I am trying to cut down on the amount of off keyboard work I do eg. using a calculator
I use s02e08 Products Cost but again having to click back and forth between tabs and then use the calculator to work out my final buy in price eg. adding VAT
I have added this little hack to admin/includes/actions/catalog/views/new_product.php to display the cost price + VAT below the Products Price (Net)
I know this is a dirty hack and was wondering if there is a more elegant way of doing it.
As my store has several thousand products that edit on a semi regular basis (mainly product price) I am trying to cut down on the amount of off keyboard work I do eg. using a calculator
I use s02e08 Products Cost but again having to click back and forth between tabs and then use the calculator to work out my final buy in price eg. adding VAT
I have added this little hack to admin/includes/actions/catalog/views/new_product.php to display the cost price + VAT below the Products Price (Net)
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>
You do not have the required permissions to view the files attached to this post.
- burt
- Core Team
- Posts: 4551
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: s02e08 - Products Cost
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:
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;
}
}
}
I am not here to build for you.
I am here to build with you. Let's help each other.
I am here to build with you. Let's help each other.
- tessthepup
- Certified Developer
- Posts: 382
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: s02e08 - Products Cost
@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; } } }
Absolutely awesome and works perfectly
Gary your the man