Display a value based on a result.

FLAG

New Member
Hello,
I would like to be able to display the shipping rate according to the total weight of the orders.
See image below.
Javascript, sql, fabrik code?
I'm not sure how to go about it.
Can you orient me please?
Thank you.
 

Attachments

  • cart.jpg
    cart.jpg
    124.4 KB · Views: 87
1. Create new table shipping_rates with prices something like:
id from_weight to_weight price
1 0.00 0.50 1.50
2 0.51 1.00 2.50

2. Add new field to calculate total weight - you can use JS or calc element http://fabrikar.com/forums/index.php?wiki/calculation-element/ or total element http://fabrikar.com/forums/index.php?wiki/total-element/
3. Add new field to diaplay Shipping rate (in table pricelist find price which meet condition from total weight - use user-ajax and sql)
Those two fields are not in repeat group like items.

http://fabrikar.com/forums/index.php?wiki/form-javascript/
http://fabrikar.com/forums/index.php?wiki/form-javascript-objects/
http://fabrikar.com/forums/index.php?wiki/user-ajax/

and search the forum. Im sure you will find evrything you need.
 
Hello Deant,
I had created a shipping price table in case the original idea was the right one. I used the calc element for the total price and total weight so that is also good.
It remains to explore user-ajax and sql with a field with several conditions ...
I'm not very good at it, but I'll try.
Thank you for the direction and the links.
Greeting. :)
 
thanks for the help but i have a little problem understanding.
I have created a "shipping price" table with id - weight - price.
I have another "objects" table with id, title, description, etc. and a total-price and total-weight field.
So :
SELECT price
FROM shipping_price
... that's good but for the rest?
WHERE ?_from> = ?
AND ?_to <= ?
My tests yesterday did not give much! fault

SELECT price
FROM shipping_price
WHERE total-weight_from> = 0.5
AND total-weight_to <= 30

with a databasejoin field and data = table "objects" value = total-weight Associated label = id.


This function is very useful for me but surely for others because the e-commerce plugins apply the shipping price to the object and not to all the objects if several in the cart.
 
Last edited:
I have created a "shipping price" table with id - weight - price.

Your shipping_price table must have field weight_from and field wieght_to. For example:
from weight_from = 0.00g to weight_to = 100.00g -> price= 2.60$
from weight_from = 101.00g to weight_to = 200.00g -> price= 4.20$

When you sum all items weight in your form you will get weight_total - right? ...and then you do query to search price in table shipping_price

with a databasejoin field and data = table "objects" value = total-weight Associated label = id.

I dont have a clue what you mean. For what you are asking you dont need db join.

...and BTW what exactly you are doing and where and what plugins you are using?
 
Last edited:
My total shipping price result should be displayed in the "port" field of the "products" table.
I took a databasejoin for this but maybe this is my mistake!
Attached pictures of my tables.
Whatever I put as even simple sql query I have "error 1064".
I have been struggling with it since yesterday but I still want to figure it out with your precious help.
copie-panier-exped.png



shipping_rates.png
 
If I understand correctly the Table products is acctualy your selling items - a catalog?

How looks your order table?
 
In fact it is a catalog for my association.
We have a lot of vintage objects for sale to benefit the stray cats in our village.
I have tested a lot of e-commerce plugins but this function does not exist.
Shipping price based on the total weight of the items.
I am therefore making a site for the association that is easy to inform because it is my wife who will enter the data via login => user.
I used joomla and flexi-content a lot which I know well now. (not easy) but for my catalog I prefer Fabrik.
Here you know everything!
 
OK...you have to create another form/list for orders where you or customer will put selling items.

This is a bit too much then just a few words. Short version: you need table Products witch you have and table Orders, maybe you need also a Customers table

1. New form/table for Orders
2. Create three groups of elements:
group a: basic order data (order no,. date, cutormer data or id_customr if you have a list of customes (name, addres etc)
group b: items data (id_item is a dbjoin field, item_name, item_discription, weight, price) - this is repeatable data (go to group settings)
group c: price_total, weight_toltal, weight_price
3. Create invoice
4. Print or send invoice by mail or what ever you want

Here you can find some tutorials how to do most of it and dont forget WIKI is friend.
 
Last edited:
For the structure of the site itself, I have no problem. In the past I had created a site for artists, a real "gas factory" with flexi_content which is very good but very complicated to learn.
First of all I have to settle this problem of total shipping price because the top I row!
No equivalent on joomshopping or others.
 
Frankly, if you want to build an e-commerce application from scratch with Fabrik, you've got to be an expert with Fabrik, PHP, SQL, HTML, CSS, and eventually JS, too. And have very much time available.

Even the free "Starter" version of HikaShop does that without fuss: set weights of the products, then create a shipping method restricted to each weight group (min/max), and in the checkout the customer gets (only) the correct shipping method with its set price shown for the total weight of the order.
And it does a lot more out of the box. Oh, and their support is absolutely top there, too.
 
far from me the idea of making an e-commerce site entirely. My site is associative and only for the members of the association. So no online payment. Members must log in and can apply to purchase items. I have already tried Hikashop and Joomshopping but to enter items in the list, a lot of settings and information. I want to simplify the practice for people not accustomed to this kind of adjustment. This is why I want to go through simple fabrik forms to fill out for novices.
 
So the sql request, where do I put it?
That is the question...:(

You will put your sql in user_ajax.php file but befor you get to there you need to do a lot of things first.
Did you create table/form Orders with at least those fields and groups I wrote in previous posts?
If yes -> did you create and setup dbjoin element for your seling items teble?
I notice you dont have Quantity in table products - or you have unlimited stock?
etc...
So you have members/users who will buy items? How you will manage your members, permission? Do you use fabrik user plugin?
etc...
This is why I want to go through simple fabrik forms to fill out for novices.
It looks like a simple form but behind that is a lot of things and what is going on.
What is the workflow? Will user open a form and select items form dbjoin or user will be in catalog and put items in basket by clicing some button?

Sorry but I can't write a whole tutorial...it is to much. Also the forum it self is not intended for that.

Im sure you can find all you need in wiki and on this forum (search 'invoice') and go step by step.

You are welcome to come back and ask more specific question like: Im doing xxx and I have done this and that...how can I populate data form other table.
 
Indeed it seems more complicated than I thought with fabrik.
For the site it's simpler than that, members connect to their account and have access to a contact type form or via a multiple select, they select the objects they want to buy.
Either by the name or the id of the object.
By return email, the paypal payment information is given and the items manually removed from the catalog.
No quantity because the items are unique.
It is not a commercial site I repeat.
I thought possible to go through fabrik and apply an sql formula on a field for example to get the shipping price according to the weight.
Obviously you have to go through the nucleus of fabrik.
If this is too complicated, the price of the shipment can be given by the return email specifying the payment information.
It was my first idea but I wanted to automate the weight => shipping price calculation.
My question on the forum was only about this idea and not how to make an e-commerce site.
Nothing complicated in fact.
 
Leaving aside all the logic and workflow of your system and keeping it on calculating the shipping price with calc element, it's still necessary to know how are the products selected? Is there a databasejoin element referring to products table and rendered as multiselect. Or are the products e.g. added to some separate "shopping cart" table with list php-plugin or...
 
Hello and thank you juuser,
yes, let's stay focused on calculating the shipping price.
I had actually initially thought of a databasejoin element referring to the product table with a multi-select field.
See images above.
I would have liked an "expedition" field with automatic filling of the expedition price with a sql query on the total weight of the kind:
if total weight> = 0.5 then 4.60
if total weight <0.5 and> = 1 then 4.90
if total weight> 1 and <= 2 then 5.40
etc ..
 
Something like this should do in the calc element in the form view:
Code:
$mydb = JFactory::getDbo();

//get multiselect option ids (comma separated string)
$selected_options = '{yourtable___productelement_raw}';
//convert comma separated options to array
$selected_options_array = explode(',', $selected_options);

//loop through selected options array
$items_weight = 0;
foreach ($selected_options_array as $selected_option) {

  //get weigh of the item
  $mydb->setQuery("SELECT item_weight FROM items_table WHERE id = ".$mydb->Quote($selected_option));
  $myresult = $mydb->loadResult();
 
  //add up the weight for all selected items
  $items_weight += $myresult;

}

if ($items_weight <= 0.5) {
  return "4.60";
} elseif ($items_weight > 0.5) {
  return "4.90";
} elseif ($items_weight > 1) {
  return "5.40";
}
Of course change the element name for the product multiselect element (do not forget the _raw at the end) and table/element names in the query.

And in calc element settings set "Ajax calculation" to "Yes" and "Ajax observe fields" to your product element or just "Ajax observe all" to "Yes".

This actual code is not tested, so you may need to adjust to your needs.
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top