Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prestashop Custom / Calculated Product Price

I have canvas banner printing website. I want customer to enter width and height and using my own custom table I am calculating and showing price. Now I want to move calculated price to Cart and from there to Order generation. I have checked prestashop tables for cart but it is storing Product Ids and joining to Products tables to get prices. Is there anyway to achieve my requirements?

like image 217
Brindesh Avatar asked Jan 08 '14 09:01

Brindesh


1 Answers

This feature is not available by default in prestashop and i dont know any module for now which can do it without overloading core functionality. I am providing you only the theory and some files references for you. Please try it.

Lets consider the following general assumptions:

a) Measuring Unit is inch.

b) Per inch price is 5 usd

c) You will also need a price calculation formula, and for this example lets it is

finalPrice = width x height x 5  //width and height are formula variables

Now for prestashop you can perform the following steps:

1) Update cart table and add three fields, width, height and final_price. (The number of fields may vary according to your formula variables.)

2) Overload cart class and add properties for width, height and final_price. Also you will need to override the method which fetch all products from the cart and check if a cart product has custom price or width and height. Also all taxes, shipping costs can be applied there.

3) If you are using ajax add to cart feature, then you will need to modify blockcart module a little. You may need to modify ajax-cart.js to get width, height and final price values to post to the cart controller. Also blockcart-json.tpl may need some modifications as this file is used to populate the cart block contents. Also you may need to modify blockcart.tpl file where you can show width and height etc in the blockcart. This way you will be able to show the variables in blockcart.

4) Now next step is actually adding product to cart. Data is posted to CartController, so you will need to override it, and receive width, height and final price from the posted data. You will need to place appropriate checks if width, height and final price are available or not to detect the custom price product.

5) You will need to override OrderController to populate the shopping cart page products list with width, height and final price.

6) In all above theory, we have added product to cart and populated blockcart and shopping cart page with width, height and final price data. Now next step is completing the order. For this you will need to work with Order class, order controller and cart class. and order_product table. In order product table add same fields as cart_products table for width, height and final_price. Then modify order class and add these properties to order class.

7) You will need to override PaymentModule class and make changes in the validateOrder method. This method handles your final step in ordering steps, saves order, sends email to customer and, if enabled, site administrator(s). So here you will need add width, height and final price info in the order products db insertion code. Also you will need to supply these variables to the email templates so the customer can get the width, height and final price of the product in the email also.

8) You will also need to modify the order history section so customers can see all those details in his/her order history also.

9) You will need to make changes in Admin Order controller to show those data in the order view section for the admin.

10) And finally (not actually final :P ), you will need to make changes in the pdf invoice generation so that width, height and final price are shown in pdf invoice also.

Note : Above theory is from my experience with a similar feature in prestashop and may work or not work for you according to your requirements.

Try this, and i hope you will make it work :) ..

Good Luck...

like image 100
Altaf Hussain Avatar answered Nov 15 '22 16:11

Altaf Hussain