Page 1 of 1

s02e08 - Products Cost QUESTIONS/SUPPORT

Posted: Thu Mar 11, 2021 12:51 pm
by admin
Questions / Comments / Concerns

Products Cost Price

Posted: Sun Dec 31, 2023 12:15 pm
by tessthepup
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)

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>' . '&nbsp;' . $num;            
            ?>           
          </div>
        </div>
I know this is a dirty hack and was wondering if there is a more elegant way of doing it.

Re: s02e08 - Products Cost

Posted: Sun Dec 31, 2023 1:02 pm
by burt
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;
    }
  }

}

Re: s02e08 - Products Cost

Posted: Sun Dec 31, 2023 1:18 pm
by tessthepup
burt 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;
    }
  }

}
@burt
Absolutely awesome and works perfectly :D

Gary your the man :+1: