Jump to content

Calculate Price per Unit automatically from Price and Quantity (Product Feature)


each1teach1

Recommended Posts

Hi Everyone!

 

we  sell bottles of different size.

the bottle size is the product feature with the id# 9.

It is formattet like: "0,7" (in liters)

 

divisions ain't rocket-science ;)

 

I want the price per unit to be calculated automatically when the price is set.

 

like:

read price

read feature id=9 (liters -- replace comma by point?)

divide and save as price per unit.

 

i would highly appreciate any hints!

 

Thank You!

 

(ps 1.6.1.4)

Link to comment
Share on other sites

you can set Unit Price of each product at back office - Catalogue - Products - editing product, Prices tab

 

You will see Unit Price field and per field.

So you can enter $1.5 per liter

 

If there is discount, prestaShop will automatically calculated discounted unit price.

Link to comment
Share on other sites

Thanks a lot for your quick help.

 

entering the price per unit works fine. it is also displayed correctly.

 

when I change the price of a product, the size e.g. 1 Liter stays the same.

I was wondering if it was possible that the calculation of the price per unit could be automatic.

 

as I am new to prestashop and the programming I dont know how to access the feature id=9 of a product (my bottle size in liters)

also I dont know the command, to write the unit price.

Neither do I know where to place it.

 

or am I missing some vital point?

 

thank you!

Edited by each1teach1 (see edit history)
Link to comment
Share on other sites

when you change product price, should also change price per unit at product management page. I think this is the normal way to handle it.

unless the core does not provide the function then you can consider to modify or customize it, because custom changes will be lost when you upgrade your store.

 

anyway, if you really want to customize it, you will need to learn the Smarty and PrestaShop programming.

 

the data is loaded in product classes in controller class /controllers/front/ProductController.php and passed the data to view(theme file) via Smarty.

and the theme file is in /themes/yourthemefolder/product.tpl

Link to comment
Share on other sites

  • 3 years later...
On 4/9/2016 at 7:28 PM, each1teach1 said:

ok thank you 

 

I hope I will manage to find the command myself

 

if so, I will gladly share it, but this could take quite a while.

have you finish it? searching also for a auto method. greets

Link to comment
Share on other sites

  • 8 months later...

 Hello everyone I currently have the same problem,

which can be found on the product overview page in the miniatures: Folder tree: /PRS01/templates/catalog/_partials/miniatures/product.tpl
(purchased template)
also the base prices are not shown the product.tpl times appended because strangely enough the {hook} in line 107 is written.

 

But it is not shown and calculated in the frontend.

 

Here the link to the current test page:

www.pritumble-test.de

 

Attention, when you click on the logo or home you will get back to the actual store, I still have to fix the error, so you can screw in the testshop in peace.

{**
 * 2007-2019 PrestaShop
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License 3.0 (AFL-3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/AFL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to http://www.prestashop.com for more information.
 *
 * @author    PrestaShop SA <contact@prestashop.com>
 * @copyright 2007-2019 PrestaShop SA
 * @license   https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
 * International Registered Trademark & Property of PrestaShop SA
 *}
{block name='product_miniature_item'}
<article class="product-miniature js-product-miniature col-sm-4" data-id-product="{$product.id_product}" data-id-product-attribute="{$product.id_product_attribute}" itemscope itemtype="http://schema.org/Product">
	<div class="thumbnail-container">
		<div class="ttproduct-image">
			{block name='product_thumbnail'}
			{if $product.cover}
			  <a href="{$product.url}" class="thumbnail product-thumbnail">
				<img
			  class="ttproduct-img1"
				  src = "{$product.cover.bySize.home_default.url}"
				  alt = "{if !empty($product.cover.legend)}{$product.cover.legend}{else}{$product.name|truncate:30:'...'}{/if}"
				  data-full-size-image-url = "{$product.cover.large.url}"
				>
			   {hook h="displayTtproductImageHover" id_product=$product.id_product home='home_default' large='large_default'}
			  </a>
			{else}
			  <a href="{$product.url}" class="thumbnail product-thumbnail">
				<img
			  class="ttproduct-img1"
				  src = "{$urls.no_picture_image.bySize.home_default.url}"
				>
			  </a>
			{/if}
		  {/block}
			{block name='product_flags'}
				<ul class="product-flags">
					{foreach from=$product.flags item=flag}
						<li class="{$flag.type}">{$flag.label}</li>
					{/foreach}
				</ul>
			{/block}
			{block name='product_reviews'}
				{hook h='displayProductListReviews' product=$product}
			  {/block}
			<div class="ttproducthover">
			<div class="tt-button-container">
				{include file='catalog/_partials/customize/button-cart.tpl' product=$product}
			</div>
			{hook h='displayTtWishListButton' product=$product}
			{hook h='displayTtCompareButton' product=$product}
			{block name='quick_view'}
				<div class="quick-view-block">
					<a href="#" class="quick-view btn" data-link-action="quickview" title="{l s='Quick view'}">
						<i class="material-icons search">&#xE8B6;</i> <span>{l s='Quick view' d='Shop.Theme.Actions'}</span>
					</a>
				</div>
			{/block}
			</div>
		</div>
		
		<div class="ttproduct-desc">
			<div class="product-description">
				<h5 class="cat-name">{$product.category|escape:'html':'UTF-8'}</h5>
				
				{block name='product_name'}
				  {if $page.page_name == 'index'}
					<span class="h3 product-title" itemprop="name"><a href="{$product.url}">{$product.name|truncate:18:'...'}</a></span>
				  {else}
					<span class="h3 product-title" itemprop="name"><a href="{$product.url}">{$product.name|truncate:18:'...'}</a></span>
				  {/if}
				{/block}
		
				{block name='product_description_short'}
					<div class="product-desc-short" itemprop="description">{$product.description_short|strip_tags:'UTF-8'|truncate:60:'...' nofilter}</div>
				{/block}
		
				{block name='product_price_and_shipping'}
				{if $product.show_price}
						<div class="product-price-and-shipping">
							<span itemprop="price" class="price">{$product.price}</span>
							{if $product.has_discount}
								{hook h='displayProductPriceBlock' product=$product type="old_price"}
								<span class="sr-only">{l s='Regular price' d='Shop.Theme.Catalog'}</span>
								{if $product.discount_type === 'percentage'}
								   <span class="discount-percentage discount-product">{$product.discount_percentage}</span>
								{elseif $product.discount_type === 'amount'}
								   <span class="discount-amount discount-product">{$product.discount_amount_to_display}</span>
								{/if}
								<span class="regular-price">{$product.regular_price}</span>
							{/if}
							{hook h='displayProductPriceBlock' product=$product type="before_price"}
							<span class="sr-only">{l s='Price' d='Shop.Theme.Catalog'}</span>
							{hook h='displayProductPriceBlock' product=$product type='unit_price'}
							{hook h='displayProductPriceBlock' product=$product type='weight'}
						</div>
					{/if}
				{/block}
				<div class="highlighted-informations{if !$product.main_variants} no-variants{/if} hidden-sm-down">
				{block name='product_variants'}
					{if $product.main_variants}
						{include file='catalog/_partials/variant-links.tpl' variants=$product.main_variants}
					{/if}
				{/block}
			</div>
			</div>
		</div>
	</div>
</article>
{/block}

 

Link to comment
Share on other sites

  • 2 years later...

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
×
×
  • Create New...