Get Products Data (Weight) And Calulate Shipping

Hello everyone,

I made a custom product tab that you can choose your location and calculate shipping.

Now I want to write a function-script that can read the product's weight (current product page) and make more precise calculation.

I did it through an external php-ajax script embeded in a custom tab, but I think I have access at all fn functions.

I tried to do it as an addon but despite all the reading I did ( I read whole docs.cs-cart !) I think the structure flow is a bit incomprehensive.

Please any ideas would be appreciated

no Ideas how to do it yourself efficiently but the alt team have a good addon for it.

You really should write it as an addon. You're only going to cause yourself more problems down the line.

Ok, lets me understand the flow then.

I managed to write an addon.xml for creating and inserting values into 3 custom tables, and deleting them after uninstall.

Then I made 2 php scripts that script1 is reading from table1 and after calling ajax through script2 it links the user selection with the data of table2 and table3. This is embeded in a custom product tab as an iframe.

Let's follow the straight addon idea:

I have already done addon.xml ok

I have to create an init.php file that I register the use of get_product_data function. ok

I have to create a func.php file that has all the code of my script1 ?

-Script1 also includes javascript functions

-How can this return the ajax response that script2 does ?

What I have to create in skins/my_skin/customer/addons/blocks/product_tabs/ ?

thanks for the responses

(cs-cart 3 professional)

What is the problem you are trying to solve? Very hard to follow what you're trying to do and my first thought would be that you are over complicating it because of a lack of understanding of how things work in cs-cart. So if you can state the problem you want to solve then maybe we can point you in the right direction. Not being critical, just not enough info to work from.

Generally you would store additional product info in the 'extra' field of the product data array. The system will then store this automatically for you. It will then be available to you via $product_data['extra']['my_extra_data']['value'] (where 'my_extra_data' is the key to an array of data you want to save/use per product.

Ok, let me state the problem in a simple way.

I want to make an addon that does these:

Creates a tab next to description tab in every product page and a link-block in cart page. The functionality is supposed to be :

User selects from a dropdown menu, a region.

then a second dropdown appears with the cities of this region.

then a third dropdown appears with the villages of this city.

then by the last selection of the village as data1 and product weight as data2, the addon must calculate the shipping cost. Just for customer's info at every product and not storing it anywhere(customers info tool)

The 3 custom tables are a thought of storing the regions-cities-villages of my country.Don't have to be altered.

The calculation of cost is also been made under standard rates of local post company.(At a second step I want to store shipping rates of this tool as addons settings)

That is the idea with simple words and sorry for the misunderstanding

Hi there

well it is not so simple as you put it dioskouros

You first need some functions in the Addon folder where your addon.xml leaves. maybe a products.pre with some ajax request to collect some data from the product like weitgh and quantity also shipping rates and locations.

Then after you solve this, you neet to have in the skin a hook for the view_main_info ( a post.tpl I suppose) in order to put all your forms, like country/ state and shipping options dropdown, in order for the customer to choose his location and diesired shipping method (they come from the Ajax function ealrier) and last an action button to calculate all this.

It is very complicated. I would also go with Alt-team addon.


I would utilize one of the lesser used elements of “locations” (like Address) for your “villages” and then use the standard shipping functionality to set/store the rates. Since the name 'Address' is a language variable, you can easily change it to “Village”. But you'll want to ensure that it's a unique lang variable for “address” that's used otherwise other form labels are going to see the change.

I'm all for NOT re-inventiing the wheel when you don't have to.

You really are dealing with a “Location” and a “rate” based on the Location.

Ok, managed to find way to get the product_id and then the product weight and make the calculations in my embeded php script.

I have almost finished it but unfortunalety in an unorthodox coding way that I am not satisfied. I managed not to have any security issues and walk by the security rules of cscart.

The thing is that I want to do it right and I want to read and learn the proper way through addons-controllers-hooks. But unfortunately I cannot find anywhere details about developing by the rules. I mean syntax, list of available variables, syntax of retrieving vars, hooks, other controllers, the sections that I am allowed to have access to which var and hooks etc.

I read the 2 addon examples of “Hello world” and “Advanced Addon” but what I have to write and where and how.

I just want to make a new product tab that reads only product_id or weight, reads values from my tables and make a simple calculation to display a simple text.

I know that if I pay someone who knows I can get it in 2 days, but that;s not the point.

I also had very useful help through this forum over the years, so I think here is the only source of collecting cscart info.

Any help about proper cscart coding is welcome

Please share ;)

cs-cart 4.1.2

You might do a search of the forums for me as the author and search for the string “PHP Controller”.

I did a 6 article tutorial on creating addons and using a practical example. It was done for V2, but the concepts are still the same though the path names and some of the language variable usage has changed.