Prestashop Custom / Calculated Product Price - prestashop

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?

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...

Related

Prestashop add custom radio button on shipping carriers on front end checkout

I have created one custom module in Prestashop 1.7.8.7 which will add multiple shipping methods (Carrier) and will show shipping cost based on product dimensions and delivery address. So shipping carrier will look something like this on front-end checkout page. https://prnt.sc/E1avDASyJYYW
Now if someone select SameDay Courier Shipping then i need to show two radio button to select which service they want.
It will have two radio options like
Delivery pickup (by default this option will be selected)
Locker pickup
So if someone select Delivery pickup then it will have different shipping cost and if someone select Locker pickup then it will have different shipping cost.
Can anybody help me how can i achieve this functionality.
While digging, i found that we have file called DeliveryOptionsFinder.php and in that file we have one public function called getDeliveryOptions() where we have this line of code
if ($moduleId = Module::getModuleIdByName($carrier['external_module_name'])) {
$carrier['extraContent'] = Hook::exec('displayCarrierExtraContent', ['carrier' => $carrier], $moduleId);
}
}
So if i set is_module to 1 to all my carriers directly from DB then on frontend checkout page, no carriers is being displayed.
Thanks in advance.
I've already done something like this in the last 2 year as prestashop developer.
The truth is that you can't achieve what you want by "respecting" prestashop processes.
Maybe you can hook using a module the hookDisplayCarrierExtraContent($data) and then return the 2 radios if carrier is certain one (use $data).
But you can't handle a form submit or something else, or include it to prestashop checkout data.
But what you can do as workaround, for example, is the following.
In your module, as I said, hook the extra content, render a template with the 2 radios. Hook displayHeader too and use $this->context->controller->addJS() to add your own js if the current controller is the checkout one.
Then in this JS code you can handle the "change" event of the radios and send an ajax request to your module.
You can create inside {your_module}/controllers/front/ a controller called, for example, radio-choose and handle the js ajax request by saving inside your own table the choosen one.
Obviously you can disable the "next" button in checkout untill one of the two radios are selected, or maybe you can just set a radio button as default one to simplify.
For example your table "ps_cart_choosen_radio" could look like this |id_cart|choosen_radio|.
Then you have all the data you needed. When a cart is converted into an order you will have inside Order object (and ps_orders table as well) the id_cart.
Just select / join choosen radio from your own table by using order's id_cart.
"SELECT choosen_radio FROM ps_cart_choosen_radio WHERE id_cart = {$order.id_cart}"
If you need to show data depending on choosen_radio in frontend you can hook everywhere an order is present and select these data. Or maybe you can edit carrier name in ps_orders table by adding a piece of string. Let' say carrier is "express" and customer choosed "24h". You can update that column with carrier name by changing it to "express-24h" so around the whole prestashop ecosystem everybody will see that's a 24h choice.
Remember that the carrier name related to an order is not the carrier name inside the carriers table. So you can edit it without having trouble.
All these problems comes from the "need" to show some nested choices instead of listing all these in the main selections. In that case it would be easy (just create carrier in the prestashop backoffice)

Showing different price on category page and single product page in variable product in bigcommerce

Showing different price on category page and single product page in variable product in bigcommerce. I just want to show the lowest price on category page.
This is the category page: https://hilineelectronics.com/portable-audio/. In the first product price is showing $112.99 and after checking it quick view and single product page it is showing $83.99. I want $83.99 (varibale amount) amount there.
How can we do this? Any variable or code for this?
Thanks in advance.
Go to your CategoryProductsItem.html check the code
<em class="p-price">%%GLOBAL_ProductPrice%%</em>
Is there %%GLOBAL_ProductPrice%% call same or different with product details page.
ProductDetails.html
<span class="ProductPrice VariationProductPrice">%%GLOBAL_ProductPrice%%</span>
Compare both files global varriable.
The second way makes the backup and of the files and then revert it to the original.

Bigcommerce - add category name to product page layout

I'm changing a theme in Bigcommerce, and I should put the product Category name in Product page layout, but there isn't any panel that could do that, and I don't really know is it possible?
I can get the list of all categories, but that's not what I want, and I would like to do it without unecessary JavaScript.
So, for example..
I have few categories, and when I'm in each of that categories product, this product category should be writen.
Category - Product - Headline ( should be writen in this page )
Car - Honda - Car
Cloth - Shirt - Cloth
etc..
If anyone knows how it can be made, it would be very appreciated.
Thanks!
I believe the only place the category is pulled onto the product page is through the product breadcrumbs. You could use a simple Javascript to get the category set in the product breadcrumbs and then display it somewhere else.
Something like
Get breadcrumbs
Find the item before the ones that matches the product name
Set it's text as a variable
Set the element where you actually want the cat name to appear to contain the text of the var

Openerp add fields in invoice

![openerp invoice][1]
[1]: http://i.stack.imgur.com/h6zY0.pngemphasized text
I would like to add discount ammount to my invoice template not in percents but in real ammount
Example: item value 100$, discout 10%, discount is 10$
i need to put it in a template like in the picture above
The account_invoice_line class in OpenERP is designed in such way to consider the discount field as percent. If you need discounts in absolute value you need to customize the account module and modify the account.invoice.line object. Maybe the easiest is to add another filed - let say abs_discount, and to take it with priority, if present.
You should look at least at the methods _ammount_line(), _price_unit_default(), move_line_get() and compute() of the account_invoice_line class.
You should also modify the Invoice view to allow the editing of the new field.

Prestashop 1.5 sort product in catgory page by price lowest to heighest by default

this question can be silly to you, but i am having trouble to find a solution. I want to sort product in category page by price lowest to highest, i know there is drop by which i can see products by price but i want to set it by default so that page loads with sorted. can you tell which file i should modify? and how can i achieve this?
here is the url so you can check which things i am talking about:
http://pinstripecreative.com/nationalcapp2/5-decaffeinated
For people who are meeting such issue in Prestashop 1.6, the default sort type can be set in backend via preferences> Products > Set default sorting.
Note that some default modules, like blocksearch, can force the sorting of page by sending the orderby and orderway via a hidden input. Then you need in this case to change the view by either deleting the inputs or sending your own orderby and orderway.
Products default sort not working on search.tpl - Prestashop 1.6.0.6 - Resolved