Beginner Online Quote calculator

dough

New Member
New to fabrik, but we know php and sql. Apologies if I use the wrokng terminology.

here is the first little project we want to use it for:

  • A simple online quote tool
    • Have created a pricing list (table) with 3 field. lets say size, price and colour as an example
    • Want to have a module that is a simple form with a 2 pull downs for customer to choose size and colour.
    • Will then select from pricingtable where size = 'medium' and colour='green' to return the price.
    • May also want to add another calculated value based on another pull down (eg logos) say total price = price + logos x 3
    • Make it all look nice. Have it as a module can position on the front page, or as a page on its own
Any tips of if this can be done, and how to do it apprectaied
 
Create the 'calcform' (or whatever you want to call it) From/List. You may not need to store, or even submit, the lookup form, but although technically we still support "table-less" forms, it's someting we will be deprecating. So best to create it as a List.

Ensure that the 'pricing' table has a simple integer primary key, auto incrementing.

For the 'calcform', best approach is probably to use a calc element for the price. The size and colour could be either dropdown elements, or make a couple of simple tables for their values, and use join elements in dropdown mode. Probably best to do it as tables - a little more work, but usually worth it in the long run. Fields in the table would be id (int auto-inc PK), value and label, like ...

1 blue Blue
2 green Green

On the pricing list/form, the colour and size elements would be joins to those two tables. The 'value' would be whatever you are using in the pricing table for those values, as the FK. What values you use in the pricing table depends on your application ... ike if you are importig the data from elsewhere, you may not having a choice and it may be the value like 'blue'. If starting from scratch in Fabrik, it's be easier to use the id's, so you have iteger FK/PK's.

Then in the calc element on the calc form, you'd have to do your lookup, fetching the raw values of the size and colour using Fabrik's {} placeholder mechanism:

Code:
$size = '{calcform___size_raw}';
$colour = '{calcform___colour_raw}';
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('price')->from('price_tabe')->where('size = ' . $db->quote($size) . ' AND colour = ' . $db->quote('$colour'));
$db->setQuery($query);
$price = $db->loadResult();
return $price;

Note the _raw on those {} placeholders, which tells us to give your the value, rather than the label, for things ike dropdowns, radio buttons, etc.

Set the calc to "Only calc on save" Yes, and "AJAX calculation" Yes.

-- hugh
 
Thanks. I am making some progress on this, but cant get it to quite work.

I have the calc field as

$channels = '{quotes___Channels_raw}';
$coverage = '{quotes___Coverage_raw}';

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('price')->from('pricing')->where('channels = ' . $db->quote($channels) . ' AND coverage = ' . $db->quote('$coverage'));
$db->setQuery($query);
$price = $db->loadResult();
return $price;

I know the variables are correctly named and the query works with real data. When I change the drop down, I briefly see calculating sign in the field for price, but stays blank and nothing saves in the database for price. Hust for the other 2 variables.

is there any easy way to debug this and see what is not working
 
I think it must be
. $db->quote($coverage));

For debugging you can do
Code:
$price = $db->loadResult();
var_dump($price);exit;
wich will give you a blank page with just the variable's content.
 
I found the problem and now have this all working. There was a small problem in the example with the ' ' in the query that var_dump helped me find. All is good now

Last question on this...

Once I have give the customer the price quote from the database in the form, I would like to have a button that says 'BUY NOW" and takes them to a form that will get name, address etc and will keep the quote information. Is this possible?
 
Create a new display element, with "List->link to details = yes" and enter something like this in the "custom url" field:

index.php?option=com_fabrik&view=form&formid=X&purchase___size={calcform___size_raw}&purchase___colour={calcform___colour_raw}

replace X with your purchase form.
Fabrik will replace {...} with the row's values.
For the user - it depends - I presume they are already logged in?

So either make a database join element to look up the address info and limit it to the current user's address by adding into the where statement:

Code:
where {thistable}.user_id = {$my->id}

You can make it read only as well by setting the element access level to
form add : special
form edit: special

Alternatively you could use a display element and build the query to get the address from the user's id. , so a default text of something like:

PHP:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$user = JFactory::getUser();
$query->select('address')->from('customer_info')->where('id = ' . (int) $user->get('id'));
$db->setQuery($query);
return $db->loadObjectList();

then set 'eval = yes' to treat the default text as PHP code
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top