Jump to content

Price per unit & Price per box in Featured [Solution]


olivierleduc101
 Share

Recommended Posts

I want to store the second price in the database.
Change the value of the second price in the item editor tool
Display the second price in featured and in the more info page.

Here is the solution:

In your DB:

ALTER TABLE ps_product ADD price_unit decimal(20,6) NOT NULL




In classes/product.php
Right After:

   /** @var float Price in euros */
   public         $price = 0;



Put:

   /** @var float Price Unit in euros */
   public         $price_unit = 0;




Right After:

'price' => 'isPrice',



Put:

'price_unit' => 'isPrice',







Right After:

$fields['price'] = floatval($this->price);



Put:

$fields['price_unit'] = floatval($this->price_unit);




Save product.php and open admin/tabs/AdminProduct.php

Right After:

                    echo '

'.$this->l('Pre-tax retail price:').'

                           '.($currency->format == 1 ? $currency->sign.' ' : '').'<input size="11" maxlength="14" id="priceTE" name="price" type="text" value="'.$this->getFieldValue($obj, 'price').'" onchange="this.value = this.value.replace(/,/g, \'.\');" onkeyup="calcPriceTI();" />'.($currency->format == 2 ? ' '.$currency->sign : '').' *
'.$this->l('The pre-tax retail price to sell this product').'

';



Put:

                   echo '

'.$this->l('Pre-tax unit price:').'

                           '.($currency->format == 1 ? $currency->sign.' ' : '').'<input size="11" maxlength="14" id="priceTE" name="price_unit" type="text" value="'.$this->getFieldValue($obj, 'price_unit').'" onchange="this.value = this.value.replace(/,/g, \'.\');" onkeyup="calcPriceTI();" />'.($currency->format == 2 ? ' '.$currency->sign : '').' *
'.$this->l('The pre-tax unit price to sell this product').'

';



All you have to do now is add {convertPrice price=$product.price_unit} in your .tpl files to print the unit price.

Note that this is a dirty solution. DB backup module will not work properly after this mod. I didn't try to provide a fix yet.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More