Change price calculation

  • Posts: 18
  • Thank you received: 0
10 years 6 months ago #183280

-- url of the page with the problem -- : www.print-foto.com/NL/fotoafdrukken/foto/foto-op-voetmat
-- HikaShop version -- : 2.3.1
-- Joomla version -- : 2.5

Hi,

I'm creating a webshop for a printing company.
The current hikashop configuration allows to order products.
So, example situation:
I have two pieces: first one is 30x30cm (€ price_a), second one is 60x40cm (€ price_b).
A customer can order, sees the amount and pays.

The owner of this company wants to change it:
he has the custom fields width and height and want to define a price per cm², in stead of per product.

Does someone know how I can configure this?
So, I'll have a price per cm² for each product and the price will be calculated for the dimensions.

Please Log in or Create an account to join the conversation.

  • Posts: 84077
  • Thank you received: 13627
  • MODERATOR
10 years 6 months ago #183305

Hi,

You can follow the instructions of the section "How to sell products by Width and Length ?" of our FAQ:
www.hikashop.com/support/support/documen...on/106-faq.html#cart

Please Log in or Create an account to join the conversation.

  • Posts: 526
  • Thank you received: 9
  • Hikashop Business
10 years 6 months ago #183322

Hi, I sell with widths & lengths etc. Best way is to set up 'Characteristics' for this requirement or simply if selling only by cm² is to set up the price for cm² and put in the description that it's sold by cm² they can put amount required in the quantity box if more than 1 cm² piece is needed.

Hope this helps.

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
10 years 6 months ago #183324

Hi,

thanks for the fasts responses.
It's no solution to put the amount of cm² in the quantity field:
for some products he can do this (e.g. wallpaper), but for some products (like a canvas) he wants to have the amount of products in the quantity field. Those products have a width and length (and so a cm² defined).
Now he want to set a price per cm² and he wants the price being calculated based on the cm²...

Please Log in or Create an account to join the conversation.

  • Posts: 526
  • Thank you received: 9
  • Hikashop Business
10 years 6 months ago #183325

you put the amount you have in stock in the quantity box i.e. if you have 10 cm² then put 10 in quantity (you can leave this as the default (unlimited) if you have loads of stock, then set the price for 1 x cm², is someone wants 5 x cm² they put '5' in the box (front end) and the price will be calculated for 5 x cm² also reducing your stock by 5 x cm² (if set)

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
10 years 6 months ago #183608

Hi,

I know you can do it like that, but it's not that clean right?
It's just: 1 product (e.g. mouse mat) can have two dimensions 30x30cm (i.e. 900cm²) or 40x20cm (i.e. 800cm²).
The price needs to be calculated based on the width and height of the product (characteristics), but the quantity is the amount of products (e.g. mouse mats) that the customer wants to buy.
So the price is the amount of cm² x price_per_cm² x quantity....

Is there a clean solution to do this, without adapting the PHP code of hikashop?

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
10 years 6 months ago #183610

I found I can do this by using a template override on the hikashop_product_price_for_quantity_in_cart(&$product) or hikashop_product_price_for_quantity_in_order(&$product) method.

The issue now is that I don't find documentation (or if possible) an example on how to do template overrides for a particular product...

Please Log in or Create an account to join the conversation.

  • Posts: 84077
  • Thank you received: 13627
  • MODERATOR
10 years 6 months ago #183612

@MaartenVdp The link I gave in my message has a plugin which implements that in order to achieve what you want.

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
10 years 6 months ago #183656

So,

I searched further. It can be enough that I define a price on the product level (without length and with characteristics).
The price that needs to be created when I add width and height characteristic has to be width x height x global price product (will be defined per cm²).

Is there a way to manipulate how the prices are calculated and stored into the database?

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
10 years 6 months ago #183681

Thank you very much!!!

I didn't see that it was a link :blush:
I just saw that I had to create the plugin....
Many thanks!

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
10 years 6 months ago #183753

Hi Nicolas,

I installed the plugin, but nothing is happening....
- I installed the plugin (with these changes:
if(!function_exists('hikashop_product_price_for_quantity_in_cart') && !function_exists('hikashop_product_price_for_quantity_in_order')) {
function hikashop_product_price_for_quantity_in_cart(&$product){
$currencyClass = hikashop_get('class.currency');
$quantity = @$product->cart_product_quantity;
if(!empty($product->length) && !empty($product->width)){
$quantity = 500;//$quantity*$product->length*$product->width;
}
$currencyClass->quantityPrices($product->prices,$quantity,$product->cart_product_total_quantity);
}

function hikashop_product_price_for_quantity_in_order(&$product){
$quantity = $product->order_product_quantity;
if(!empty($product->length) && !empty($product->width)){
$quantity = $quantity*$product->length*$product->width;
}
$product->order_product_total_price_no_vat = -100;//$product->order_product_price*$quantity;
$product->order_product_total_price = -50;//($product->order_product_price+$product->order_product_tax)*$quantity;
}
}


just to see that it's working...
- I have width & length and published it on the front end.
Now I still have the old prices on the front end

Please Log in or Create an account to join the conversation.

  • Posts: 84077
  • Thank you received: 13627
  • MODERATOR
10 years 6 months ago #183800

Hi,

The prices will only change in the cart since that an override of the quantity price calculated when the cart is loaded in memory.
So make sure that the plugin is published and that you're looking at the price of the product in the cart.

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
10 years 6 months ago #183859

And what do you have to override in the following scenario:

I give as a price for the global product: €amountA (e.g. mouse mat) ==> price is per cm²
mouse mat has 2 variants: 20x20cm, and 40x40cm.
when I enter those variants, with there length and with, I want to have the price calculated based on the global price set.
Is this possible through a hikashop plugin, or should I add a database trigger?

Please Log in or Create an account to join the conversation.

  • Posts: 84077
  • Thank you received: 13627
  • MODERATOR
10 years 6 months ago #183862

If you want to have fixed variants, and not fields where the user can enter anything, you don't need any plugin or database trigger.
Just click on the "manage variants" button of the product edition page, edit each variant, and enter what you want in the field "Main product price percentage" of each one.
The price will then be calculated automatically for each variant.

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
10 years 6 months ago #183931

Aha :)
this is indeed what I'm looking for.
Is there a plugin way to put in "product price percentage" automatically "width * length"?
like the quantity plugin for the cart

Please Log in or Create an account to join the conversation.

  • Posts: 84077
  • Thank you received: 13627
  • MODERATOR
10 years 6 months ago #183938

There is no plugin for that.

Please Log in or Create an account to join the conversation.

Time to create page: 0.091 seconds
Powered by Kunena Forum