Dynamic Pricing Based On Selection

  • Posts: 25
  • Thank you received: 0
12 years 1 month ago #68293

Hi, I would like a price to appear on the checkout page based on a selection from a previous page. I therefore DO NOT want to create a product and assign a fixed price to it.
Let me explain a bit more-:
I have built a prototype site which allows persons to pay insurance. Insurance amounts will vary from person to person and are subject to change each year. Currently I have a page in joomla! which has a dropdown menu where persons can select the portion of insurance they want to pay. I want that when a user selects their insurance portion and selects 'OK', the selected amount will appear on the checkout page.

Does hikashop offer this functionality or is there a way to modify the code so as to facilitate this action. If there is a way, please tell me how.

Thank you

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 1 month ago #68486

Hi,

You can do that by creating one or several custom fields of the table "item" (business edition only) via the menu Display->Views so that the users can enter the information on a product page.
Then, you need to create a quantity price calculation override plugin as explained here:
www.hikashop.com/en/support/documentatio...tation.html#override

We have an example of that here:
demo.hikashop.com/index.php?option=com_h...show&cid=214&lang=en

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

  • Posts: 25
  • Thank you received: 0
12 years 1 month ago #68779

Hi again,

I tried to follow your instructions but I was not successful. I am not an expert so that may be part of the problem. To further clarify what I wish to happen:-

Currently I am able to pass the amount that a user selects in a session variable. I just want that session variable to appear under the 'Unit Price' field on the checkout page.

Is there a simple way to do this?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 1 month ago #68943

Hi,

It's quite simple. Everywhere in the code of the donation plugin available in the link I gave you, just replace:
$product->amount
by:
$_SESSION

and that should do the trick.

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

  • Posts: 25
  • Thank you received: 0
12 years 1 month ago #70468

Hi again,

You have been helpful so far but now I need some additional functionality.


I tried your suggestion of replacing $product->amount with $_SESSION which pulls from a drop-down menu as shown in code below:-

<?php
jimport('joomla.plugin.plugin');
class plgSystemCustom_price extends JPlugin{
}

function hikashop_product_price_for_quantity_in_cart(&$product){
$currencyClass = hikashop_get('class.currency');
$quantity = @$product->cart_product_quantity;
if(empty($product->prices)){
$price= null;
$price->price_currency_id = hikashop_getCurrency();
$price->price_min_quantity = 1;
$product->prices = array($price);
}
if(!empty($_SESSION)){
foreach($product->prices as $k => $price){
$product->prices[$k]->price_value = $_SESSION;
$product->prices[$k]->price_value_with_tax = $_SESSION;
}
}
$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->ordered_length)){
$product->order_product_price = $_SESSION;
$product->order_product_tax = 0;
}
$product->order_product_total_price_no_vat = $product->order_product_price*$quantity;
$product->order_product_total_price = ($product->order_product_price+$product->order_product_tax)*$quantity;
}


I would now like to update this code so that if the session variable is not selected from the drop-down list, the $product->amount which I created on the HikaShop-->Products page will be used instead.

Thank You again

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 1 month ago #70603

Then, instead of :
$_SESSION

you should have:
(isset($_SESSION) ? $_SESSION : $product->amount)

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

  • Posts: 25
  • Thank you received: 0
12 years 1 month ago #70678

Hi again,

I tried your suggestion but my page loads blank.

Below is the code I tried:-
(I am a novice somewhat so maybe I have something incorrect)

Please advise. Thank You again.

<?php
jimport('joomla.plugin.plugin');
class plgSystemCustom_price extends JPlugin{
}

function hikashop_product_price_for_quantity_in_cart(&$product){
$currencyClass = hikashop_get('class.currency');
$quantity = @$product->cart_product_quantity;
if(empty($product->prices)){
$price= null;
$price->price_currency_id = hikashop_getCurrency();
$price->price_min_quantity = 1;
$product->prices = array($price);
}
/* if(!empty($_SESSION)){
foreach($product->prices as $k => $price){
$product->prices[$k]->price_value = $_SESSION;
$product->prices[$k]->price_value_with_tax = $_SESSION;
*/
if(isset($_SESSION) ? $_SESSION : $product->amount){
foreach($product->prices as $k => $price){
$product->prices[$k]->price_value = isset($_SESSION) ? $_SESSION : $product->amount;
$product->prices[$k]->price_value_with_tax = isset($_SESSION) ? $_SESSION : $product->amount;


}
}
$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->ordered_length)){
$product->order_product_price = isset($_SESSION) ? $_SESSION : $product->amount;
$product->order_product_tax = 0;
}
$product->order_product_total_price_no_vat = $product->order_product_price*$quantity;
$product->order_product_total_price = ($product->order_product_price+$product->order_product_tax)*$quantity;
}

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 1 month ago #70684

Set the "error reporting" to "maximum" in the joomla configuration. That will display an error message with the line on which you have the problem.

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

  • Posts: 25
  • Thank you received: 0
12 years 1 month ago #70743

Hi again,

I will not be able to check for at least another 7 hours.
Could you tell me in the meantime if my modified code looks correct with the "(isset($_SESSION) ? $_SESSION : $product->amount)" line which you suggested?

Also how do I set error reporting to maximum?

Please direct me step by step.

Thank You again

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 1 month ago #70947

Hi,

In the joomla configuration, there is such "error reporting", just change it:
learnonline.vrsminfotech.com/wp-content/uploads/2011/09/1.gif

Your code looks ok yes.

The following user(s) said Thank You: jonblk

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

Time to create page: 0.070 seconds
Powered by Kunena Forum