s02e08 - Products Cost QUESTIONS/SUPPORT

Open to all! Ask other shopowners for help.
Post Reply
admin
Contributor
Posts: 217
Joined: Wed Oct 30, 2019 1:34 pm
Phoenix Version:
Has thanked: 20 times
Been thanked: 22 times

s02e08 - Products Cost QUESTIONS/SUPPORT

Post by admin »

Questions / Comments / Concerns

Tags:


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
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

Post 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.
You do not have the required permissions to view the files attached to this post.
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: s02e08 - Products Cost

Post 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;
    }
  }

}
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
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

Post 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:


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply