Reputation: 146
I need Prestashop to calculate shipping price depend on items quantity in cart. If there is more than one item in cart, i want the shipping price to be 50% of sum of all shipping costs.
I modyfied the cart module, but when i proceed to order page, the shipping cost is still full amount.
My code in blockcart:
if($nbTotalProducts>1) {
$shipping_cost_float = $shipping_cost_float/2;
$shipping_cost = $shipping_cost/2;
}
How can i store new shipping cost for all modules/controllers?
Upvotes: 0
Views: 7262
Reputation: 146
I think, i found the solution.
I have modified the cart class (classes/cart.php) - getPackageShippingCost function.
I add this code before the shipping cost is converting to float:
$product_array = $this->getProducts();
$pcount = 0; //quantity of products in cart
$moreThanOneQuantity = FALSE;
foreach($product_array as $product_item) {
$pcount++;
if($product_item['quantity']>1) $moreThanOneQuantity = TRUE;
}
if($shipping_cost>0 && ($pcount>1 || $moreThanOneQuantity )) $shipping_cost=$shipping_cost/2;
Hope it will help someone.
Upvotes: 2
Reputation: 27
I dont think you need to code here. You can try to play with the weights of the productos.
For example, you put all your items with weight 1 and you configure your shipping cost to be 50% more if the weight is up to 1. This way you will have what you want if I understood correctly
Upvotes: 0
Reputation: 407
This is not that simple to manipulate shipping cost. They depends on the carrier used for the cart. I think you should try to set fixed value in the carrier option, and define many price range.
If it's not enough, the best solution for me is to use a new cartrule. Create one that give free shipping, and override CartRule class. In the method getContextualValue, the shipping cost is setted to 0 here. i think you may change it to remove 50% instead. You may have to change some template rendering too (your cart will display a free shipping).
Hope it help.
Upvotes: 0