Community Forums

Add a different recycling fee per product in shopping cart

Coding & concept discussion for OpenCart v1.x development

Add a different recycling fee per product in shopping cart

Postby dither » Thu Jun 14, 2012 3:00 am

Hi
I would like to add an extra field (or use an existing unused field such as SKU) in the “product” table, for storing a recycling fee.
This fee would be calculated at the chopping cart and added to the products price after any discounts or specials but before taxes.

For example a product costs 10€ the recycle fee is 0.05€ so after a 50% discount it would cost 5.05€ without Tax.

So I need to:
a) Add an extra field or use the sku field in “product” table for recycling fee.
b) Find the query that gets the products prices from database and add the recycling fee field retrieval.
c) Find the logic that calculates shopping card prices.
d) Add the product's recycling fee value to the product's price after any discounts or specials but before the taxes.

Can anyone help how to achieve this or give some guidelines ?

(I cant use the combination of fixed amount tax and percentage tax to achieve the same effect, cause every product has different recycle fee so I would end up with more than 300 different Tax Classes.)
dither
 
Posts: 20
Joined: Sun Apr 29, 2012 4:40 am

Re: Add a different recycling fee per product in shopping ca

Postby Johnathan » Thu Jun 14, 2012 4:59 am

You could do this with Product-Based Fee/Discount, but the fees would show up as their own line items, not as part of the product price. If you need a customization like that, you should probably post a request in the "Commercial Support" forum, as I'm not aware of any extensions that function that way.
Image
ImageImageImageImageImageImageImageImageImage
User avatar
Johnathan
Global Moderator
 
Posts: 2861
Joined: Thu Dec 17, 2009 7:08 pm

Re: Add a different recycling fee per product in shopping ca

Postby dither » Thu Jun 14, 2012 5:53 am

Thank you Johnathan for your answer
I would happily purchase the extension if it performed as I need.
The method you proposed with the extension, is similar to using a unique Tax Class for each product with fixed tax for the recycle fee plus percentage VAT. Since each product has different recycle fee I would have to apply a fee for each product either way.

I wanted a recycle fee field in the “product” table so I can use import/export tool to update fees and prices easily.

I posted here for some programming guidelines cause I'm familiar with procedural programming in php though I don't have enough experience with OOP. I could do it myself if someone pointed to the right places in the script since I'm new to Opencart and I'm not familiar with the framework.

If anyone has enough time to spare for some guidelines I would appreciate. Otherwise thank you anyway, I'll try on my own. Opencart is such a great application, and its worth the time and effort to explore and understand whats under the hood.
dither
 
Posts: 20
Joined: Sun Apr 29, 2012 4:40 am

Re: Add a different recycling fee per product in shopping ca

Postby Johnathan » Thu Jun 14, 2012 11:23 pm

To do what you're proposing, you would need to:

1. Add a column to the "product" table for the value.
2. Add the HTML for the field in the /admin/view/template/catalog/product_form.tpl
3. Add the database query code to pull the value from the database in /admin/model/catalog/product.php
4. Add the code to pass the data from the model file to the view file in the controller /admin/controller/catalog/product.php

You'd then need to add code somewhere on the front-end so it uses the value to calculate the price correctly, probably when the price is pulled from the database in /catalog/model/catalog/product.php

That's the best I can do in terms of programming guidelines without detailing everything out. Good luck with it
Image
ImageImageImageImageImageImageImageImageImage
User avatar
Johnathan
Global Moderator
 
Posts: 2861
Joined: Thu Dec 17, 2009 7:08 pm

Re: Add a different recycling fee per product in shopping ca

Postby dither » Fri Jun 15, 2012 5:09 am

Thank you Johnathan for your help.

Before I give it a try I have another question though …
I'm interested in using the extension category-based-fee-discount to easily add complex discounts per user groups for B2B sales.

My question is were does the calculation of the discount occur in the extension ? At the product level, at the cart level or somewere else ? Cause I would have to add the recycle fee after the discount wherever it occurs.
dither
 
Posts: 20
Joined: Sun Apr 29, 2012 4:40 am

Re: Add a different recycling fee per product in shopping ca

Postby Johnathan » Fri Jun 15, 2012 5:13 am

Order Total extensions are calculated in the background, based on the customer's cart. So there would be no message on the category or product page, but once the right combination of products was in the cart, the fee or discount would apply.

If the recycle fee needs to be after the Category-Based Fee/Discount and is an Order Total extension, then you would set its Sort Order to come after the Category-Based one. If it was a custom modification, then that modification would need to take into account Order Totals to calculate the tax correctly.
Image
ImageImageImageImageImageImageImageImageImage
User avatar
Johnathan
Global Moderator
 
Posts: 2861
Joined: Thu Dec 17, 2009 7:08 pm

Re: Add a different recycling fee per product in shopping ca

Postby dither » Fri Jun 15, 2012 8:50 am

Thanks again Johnathan for the support.

Ok, thanks. I'll probably have to get the extension, examine how it works and try to do it ... :choke:
dither
 
Posts: 20
Joined: Sun Apr 29, 2012 4:40 am

Re: Add a different recycling fee per product in shopping ca

Postby dither » Sat Jun 16, 2012 11:24 am

1. Add a column to the "product" table for the value.
2. Add the HTML for the field in the /admin/view/template/catalog/product_form.tpl
3. Add the database query code to pull the value from the database in /admin/model/catalog/product.php
4. Add the code to pass the data from the model file to the view file in the controller /admin/controller/catalog/product.php

You'd then need to add code somewhere on the front-end so it uses the value to calculate the price correctly, probably when the price is pulled from the database in /catalog/model/catalog/product.php


I have an update

I've searched a lot through the “product.xxx” files you mentioned and all the code I found, was for displaying purposes.
I couldn't find any way to pass the recycle fee from product files to cart … (did I missed something ?)

The only place I could find to do the job was through “system/library/cart.php” file
I temporarily used “upc” field to store the recycle fee, and in line 217 I added the following and it did the trick:

Code: Select all
$recycle_fee = $product_query->row['upc'];
$price += $recycle_fee;
dither
 
Posts: 20
Joined: Sun Apr 29, 2012 4:40 am


Return to Concepts

Who is online

Users browsing this forum: No registered users and 16 guests

Hosted by Arvixe Web Hosting